2019-01-29 12:41:24 +01:00
|
|
|
import 'dart:io';
|
2018-04-18 14:38:28 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2019-01-22 16:39:44 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-01-31 07:20:48 +01:00
|
|
|
import 'providers/providers.dart';
|
|
|
|
import 'providers/settings.dart';
|
|
|
|
import 'screens/screens.dart';
|
2018-04-18 14:38:28 +02:00
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
class Home extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
createState() => _HomeState();
|
|
|
|
}
|
2019-01-23 09:50:51 +01:00
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
class _HomeState extends State<Home> {
|
|
|
|
int active = 0;
|
2018-04-25 15:07:44 +02:00
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
List<BottomNavigationBarItem> _buildNavigationItems() {
|
|
|
|
return [
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.rss_feed),
|
|
|
|
title: Text('News'),
|
|
|
|
),
|
2019-01-31 08:23:52 +01:00
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.search),
|
|
|
|
title: Text('Search'),
|
|
|
|
),
|
2019-01-31 07:20:48 +01:00
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: StreamBuilder<int>(builder: (context, snapshot) {
|
|
|
|
int count = snapshot.data;
|
|
|
|
// print(count);
|
2019-01-29 12:41:24 +01:00
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
// https://stackoverflow.com/a/45434404
|
|
|
|
if (count != null && count > 0) {
|
|
|
|
return Stack(children: <Widget>[
|
|
|
|
Icon(Icons.notifications),
|
|
|
|
Positioned(
|
|
|
|
// draw a red marble
|
|
|
|
top: 0,
|
|
|
|
right: 0,
|
|
|
|
child: Icon(Icons.brightness_1,
|
|
|
|
size: 8.0, color: Colors.redAccent),
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return Icon(Icons.notifications);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
title: Text('Notification'),
|
|
|
|
),
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.person),
|
|
|
|
title: Text('Me'),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2019-01-29 12:41:24 +01:00
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
_buildScreen(int index) {
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
return NewsScreen();
|
|
|
|
case 1:
|
|
|
|
return SearchScreen();
|
2019-01-31 08:23:52 +01:00
|
|
|
case 2:
|
|
|
|
return NotificationScreen();
|
2019-01-31 07:20:48 +01:00
|
|
|
case 3:
|
|
|
|
return ProfileScreen();
|
2019-01-29 12:41:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
switch (SettingsProvider.of(context).layout) {
|
|
|
|
case LayoutMap.cupertino:
|
|
|
|
return CupertinoApp(
|
|
|
|
home: CupertinoTheme(
|
|
|
|
data: CupertinoThemeData(
|
|
|
|
// brightness: Brightness.dark,
|
|
|
|
// barBackgroundColor: Color.fromRGBO(0x24, 0x29, 0x2e, 1),
|
|
|
|
),
|
|
|
|
child: CupertinoTabScaffold(
|
|
|
|
tabBar: CupertinoTabBar(items: _buildNavigationItems()),
|
|
|
|
tabBuilder: (context, index) {
|
|
|
|
return CupertinoTabView(builder: (context) {
|
|
|
|
return _buildScreen(index);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
// appBar: AppBar(title: Text('Home')),
|
|
|
|
body: _buildScreen(active),
|
|
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
|
|
items: _buildNavigationItems(),
|
|
|
|
currentIndex: active,
|
|
|
|
type: BottomNavigationBarType.fixed,
|
|
|
|
onTap: (int index) {
|
|
|
|
setState(() {
|
|
|
|
active = index;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class App extends StatelessWidget {
|
|
|
|
final isIos = Platform.isIOS;
|
|
|
|
final NotificationBloc notificationBloc;
|
|
|
|
final SearchBloc searchBloc;
|
|
|
|
|
|
|
|
App(this.notificationBloc, this.searchBloc);
|
|
|
|
|
2018-04-25 15:07:44 +02:00
|
|
|
@override
|
|
|
|
build(context) {
|
2019-01-23 12:52:51 +01:00
|
|
|
return SearchProvider(
|
|
|
|
bloc: searchBloc,
|
|
|
|
child: NotificationProvider(
|
|
|
|
bloc: notificationBloc,
|
2019-01-31 07:20:48 +01:00
|
|
|
child: SettingsProvider(
|
|
|
|
child: DefaultTextStyle(
|
|
|
|
style: TextStyle(color: Color(0xff24292e)),
|
|
|
|
child: Home(),
|
2019-01-25 13:35:20 +01:00
|
|
|
// theme: ThemeData(
|
|
|
|
// textTheme: TextTheme(
|
|
|
|
// title: TextStyle(color: Colors.red),
|
|
|
|
// ),
|
|
|
|
// ),
|
2019-01-23 09:50:51 +01:00
|
|
|
),
|
|
|
|
),
|
2019-01-22 16:39:44 +01:00
|
|
|
),
|
2018-04-25 15:07:44 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 12:41:24 +01:00
|
|
|
void main() async {
|
2019-01-23 09:50:51 +01:00
|
|
|
NotificationBloc notificationBloc = NotificationBloc();
|
2019-01-23 12:52:51 +01:00
|
|
|
SearchBloc searchBloc = SearchBloc();
|
2019-01-23 09:50:51 +01:00
|
|
|
|
2019-01-29 12:41:24 +01:00
|
|
|
// DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
|
|
|
// AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
|
|
|
// print('Running on ${androidInfo.model}'); // e.g. "Moto G (4)"
|
|
|
|
|
|
|
|
// IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
|
|
|
|
// print('Running on ${iosInfo.utsname.machine}'); // e.g. "iPod7,1"
|
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
runApp(App(notificationBloc, searchBloc));
|
2019-01-23 09:50:51 +01:00
|
|
|
}
|