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-02-07 07:35:19 +01:00
|
|
|
import 'providers/notification.dart';
|
2019-01-31 07:20:48 +01:00
|
|
|
import 'providers/settings.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import 'screens/news.dart';
|
|
|
|
import 'screens/notifications.dart';
|
|
|
|
import 'screens/search.dart';
|
|
|
|
import 'screens/profile.dart';
|
|
|
|
import 'screens/login.dart';
|
2019-02-08 07:01:25 +01:00
|
|
|
import 'screens/pull_request.dart';
|
|
|
|
import 'screens/issue.dart';
|
2018-04-18 14:38:28 +02:00
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
class Home extends StatefulWidget {
|
|
|
|
@override
|
2019-02-07 07:35:19 +01:00
|
|
|
_HomeState createState() => _HomeState();
|
2019-01-31 07:20:48 +01:00
|
|
|
}
|
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 15:07:52 +01:00
|
|
|
Widget _buildNotificationIcon(BuildContext context) {
|
|
|
|
int count = NotificationProvider.of(context).count;
|
|
|
|
if (count == 0) {
|
|
|
|
return Icon(Icons.notifications);
|
|
|
|
}
|
|
|
|
|
2019-02-06 14:35:52 +01:00
|
|
|
// String text = count > 99 ? '99+' : count.toString();
|
2019-01-31 15:07:52 +01:00
|
|
|
|
2019-02-06 14:35:52 +01:00
|
|
|
// https://stackoverflow.com/a/45434404
|
|
|
|
return new Stack(children: <Widget>[
|
|
|
|
new Icon(Icons.notifications),
|
|
|
|
new Positioned(
|
|
|
|
// draw a red marble
|
|
|
|
top: 0.0,
|
|
|
|
right: 0.0,
|
|
|
|
child: new Icon(Icons.brightness_1, size: 8.0, color: Colors.redAccent),
|
2019-01-31 15:07:52 +01:00
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
List<BottomNavigationBarItem> _buildNavigationItems() {
|
|
|
|
return [
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.rss_feed),
|
|
|
|
title: Text('News'),
|
|
|
|
),
|
|
|
|
BottomNavigationBarItem(
|
2019-01-31 15:07:52 +01:00
|
|
|
icon: _buildNotificationIcon(context),
|
2019-01-31 07:20:48 +01:00
|
|
|
title: Text('Notification'),
|
|
|
|
),
|
2019-02-06 06:06:11 +01:00
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.search),
|
|
|
|
title: Text('Search'),
|
|
|
|
),
|
2019-01-31 07:20:48 +01:00
|
|
|
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) {
|
2019-02-08 07:01:25 +01:00
|
|
|
// return IssueScreen(number: 29, owner: 'reactjs', name: 'rfcs');
|
2019-01-31 07:20:48 +01:00
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2019-02-05 13:57:05 +01:00
|
|
|
return NewsScreen();
|
2019-02-06 06:06:11 +01:00
|
|
|
case 1:
|
|
|
|
return NotificationScreen();
|
2019-01-31 08:23:52 +01:00
|
|
|
case 2:
|
2019-02-05 13:57:05 +01:00
|
|
|
return SearchScreen();
|
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) {
|
2019-02-07 07:35:19 +01:00
|
|
|
var settings = SettingsProvider.of(context);
|
|
|
|
|
|
|
|
if (!settings.ready) {
|
|
|
|
return MaterialApp(home: Scaffold(body: Text('a')));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settings.activeLogin == null) {
|
|
|
|
return LoginScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (settings.theme) {
|
|
|
|
case ThemeMap.cupertino:
|
2019-01-31 07:20:48 +01:00
|
|
|
return CupertinoApp(
|
|
|
|
home: CupertinoTheme(
|
2019-02-08 03:48:25 +01:00
|
|
|
data: CupertinoThemeData(),
|
2019-01-31 07:20:48 +01:00
|
|
|
child: CupertinoTabScaffold(
|
|
|
|
tabBar: CupertinoTabBar(items: _buildNavigationItems()),
|
|
|
|
tabBuilder: (context, index) {
|
|
|
|
return CupertinoTabView(builder: (context) {
|
|
|
|
return _buildScreen(index);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return MaterialApp(
|
2019-02-08 03:48:25 +01:00
|
|
|
theme: ThemeData(),
|
2019-01-31 07:20:48 +01:00
|
|
|
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 {
|
2018-04-25 15:07:44 +02:00
|
|
|
@override
|
|
|
|
build(context) {
|
2019-02-07 07:35:19 +01:00
|
|
|
return NotificationProvider(
|
|
|
|
child: SettingsProvider(
|
|
|
|
child: DefaultTextStyle(
|
|
|
|
style: TextStyle(color: Colors.black),
|
|
|
|
child: Home(),
|
|
|
|
// 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-02-07 07:35:19 +01:00
|
|
|
// Platform messages may fail, so we use a try/catch PlatformException.
|
|
|
|
|
|
|
|
// try {
|
|
|
|
// String initialLink = await getInitialLink();
|
|
|
|
// print(initialLink);
|
|
|
|
// } on PlatformException {
|
|
|
|
// print('test');
|
|
|
|
// }
|
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-02-07 07:35:19 +01:00
|
|
|
runApp(App());
|
2019-01-23 09:50:51 +01:00
|
|
|
}
|