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-09-15 11:36:09 +02:00
|
|
|
import 'package:git_touch/models/code.dart';
|
2019-09-27 14:52:38 +02:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-09-13 11:45:09 +02:00
|
|
|
import 'package:git_touch/screens/issues.dart';
|
2019-09-30 11:37:51 +02:00
|
|
|
import 'package:git_touch/screens/notification.dart';
|
2019-09-23 12:28:33 +02:00
|
|
|
import 'package:git_touch/screens/repository.dart';
|
|
|
|
import 'package:git_touch/screens/repositories.dart';
|
2019-09-13 11:00:45 +02:00
|
|
|
import 'package:git_touch/screens/user.dart';
|
2019-05-12 09:14:28 +02:00
|
|
|
import 'package:primer/primer.dart';
|
2019-09-02 14:40:20 +02:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:git_touch/models/notification.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import 'screens/news.dart';
|
|
|
|
import 'screens/search.dart';
|
|
|
|
import 'screens/login.dart';
|
2019-02-08 07:01:25 +01:00
|
|
|
import 'screens/issue.dart';
|
2019-03-10 16:34:34 +01:00
|
|
|
import 'screens/organization.dart';
|
2019-03-02 11:17:46 +01:00
|
|
|
import 'screens/trending.dart';
|
2019-03-10 06:24:40 +01:00
|
|
|
import 'utils/utils.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;
|
2019-02-08 16:20:28 +01:00
|
|
|
// String login;
|
2018-04-25 15:07:44 +02:00
|
|
|
|
2019-09-02 15:52:32 +02:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
nextTick(() {
|
|
|
|
// FIXME:
|
|
|
|
Provider.of<ThemeModel>(context).init();
|
2019-09-27 14:52:38 +02:00
|
|
|
Provider.of<AuthModel>(context).init();
|
2019-09-15 11:36:09 +02:00
|
|
|
Provider.of<CodeModel>(context).init();
|
2019-09-02 15:52:32 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-14 19:43:41 +02:00
|
|
|
Widget _buildNotificationIcon(BuildContext context, bool isActive) {
|
|
|
|
final iconData = isActive ? Icons.notifications : Icons.notifications_none;
|
2019-09-02 14:40:20 +02:00
|
|
|
int count = Provider.of<NotificationModel>(context).count;
|
2019-01-31 15:07:52 +01:00
|
|
|
if (count == 0) {
|
2019-09-14 19:43:41 +02:00
|
|
|
return Icon(iconData);
|
2019-01-31 15:07:52 +01:00
|
|
|
}
|
|
|
|
|
2019-02-06 14:35:52 +01:00
|
|
|
// String text = count > 99 ? '99+' : count.toString();
|
2019-09-03 11:20:19 +02:00
|
|
|
return Stack(
|
|
|
|
children: <Widget>[
|
2019-09-14 19:43:41 +02:00
|
|
|
Icon(iconData),
|
2019-09-03 11:20:19 +02:00
|
|
|
Positioned(
|
2019-09-14 19:43:41 +02:00
|
|
|
right: -2,
|
|
|
|
top: -2,
|
2019-09-14 11:19:33 +02:00
|
|
|
child: Icon(Octicons.primitive_dot,
|
2019-09-14 19:43:41 +02:00
|
|
|
color: PrimerColors.red500, size: 14))
|
2019-09-03 11:20:19 +02:00
|
|
|
],
|
|
|
|
);
|
2019-01-31 15:07:52 +01:00
|
|
|
}
|
|
|
|
|
2019-10-02 08:58:11 +02:00
|
|
|
List<BottomNavigationBarItem> get _navigationItems {
|
2019-01-31 07:20:48 +01:00
|
|
|
return [
|
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.rss_feed),
|
|
|
|
title: Text('News'),
|
|
|
|
),
|
|
|
|
BottomNavigationBarItem(
|
2019-09-14 19:43:41 +02:00
|
|
|
icon: _buildNotificationIcon(context, false),
|
|
|
|
activeIcon: _buildNotificationIcon(context, true),
|
2019-01-31 07:20:48 +01:00
|
|
|
title: Text('Notification'),
|
|
|
|
),
|
2019-03-02 11:17:46 +01:00
|
|
|
BottomNavigationBarItem(
|
|
|
|
icon: Icon(Icons.trending_up),
|
|
|
|
title: Text('Trending'),
|
|
|
|
),
|
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(
|
2019-02-08 12:34:07 +01:00
|
|
|
icon: Icon(Icons.person_outline),
|
2019-09-14 19:00:31 +02:00
|
|
|
activeIcon: Icon(Icons.person),
|
2019-01-31 07:20:48 +01:00
|
|
|
title: Text('Me'),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2019-01-29 12:41:24 +01:00
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
_buildScreen(int index) {
|
2019-09-13 11:45:09 +02:00
|
|
|
// return IssuesScreen(owner: 'flutter', name: 'flutter', isPullRequest: true);
|
2019-02-08 07:01:25 +01:00
|
|
|
// return IssueScreen(number: 29, owner: 'reactjs', name: 'rfcs');
|
2019-05-12 09:14:28 +02:00
|
|
|
// return IssueScreen(
|
|
|
|
// number: 68, owner: 'reactjs', name: 'rfcs', isPullRequest: true);
|
2019-02-09 06:36:15 +01:00
|
|
|
// return ReposScreen('pd4d10');
|
2019-03-10 16:34:34 +01:00
|
|
|
// return OrganizationScreen('flutter');
|
2019-03-02 11:17:46 +01:00
|
|
|
// return TrendingScreen();
|
2019-05-12 09:47:36 +02:00
|
|
|
// return RepoScreen('flutter', 'flutter');
|
2019-05-12 09:14:28 +02:00
|
|
|
// return Image.asset('images/spinner.webp', width: 32, height: 32);
|
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-03-02 11:17:46 +01:00
|
|
|
return TrendingScreen();
|
2019-01-31 07:20:48 +01:00
|
|
|
case 3:
|
2019-03-02 11:17:46 +01:00
|
|
|
return SearchScreen();
|
|
|
|
case 4:
|
2019-09-13 11:00:45 +02:00
|
|
|
return UserScreen(
|
2019-09-27 14:52:38 +02:00
|
|
|
Provider.of<AuthModel>(context).activeAccount.login,
|
2019-09-13 11:00:45 +02:00
|
|
|
isMe: true,
|
|
|
|
);
|
2019-01-29 12:41:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-31 07:20:48 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-09-27 14:52:38 +02:00
|
|
|
var settings = Provider.of<AuthModel>(context);
|
2019-03-10 06:24:40 +01:00
|
|
|
var themData = ThemeData(
|
2019-09-29 16:10:15 +02:00
|
|
|
primaryColor: PrimerColors.white,
|
|
|
|
accentColor: PrimerColors.blue500,
|
2019-03-10 06:24:40 +01:00
|
|
|
);
|
2019-02-07 07:35:19 +01:00
|
|
|
|
2019-03-10 06:24:40 +01:00
|
|
|
// TODO:
|
2019-09-02 15:52:32 +02:00
|
|
|
if (!settings.ready || !Provider.of<ThemeModel>(context).ready) {
|
2019-03-10 06:24:40 +01:00
|
|
|
return MaterialApp(theme: themData, home: Scaffold(body: Text('a')));
|
2019-02-07 07:35:19 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 16:20:28 +01:00
|
|
|
// print(settings.activeLogin);
|
2019-09-26 16:14:14 +02:00
|
|
|
if (settings.activeAccount == null) {
|
2019-03-10 06:24:40 +01:00
|
|
|
return MaterialApp(theme: themData, home: LoginScreen());
|
2019-02-07 07:35:19 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 15:52:32 +02:00
|
|
|
switch (Provider.of<ThemeModel>(context).theme) {
|
2019-09-19 15:10:50 +02:00
|
|
|
case AppThemeType.cupertino:
|
2019-01-31 07:20:48 +01:00
|
|
|
return CupertinoApp(
|
|
|
|
home: CupertinoTheme(
|
2019-03-10 16:34:34 +01:00
|
|
|
data: CupertinoThemeData(
|
2019-09-05 11:58:14 +02:00
|
|
|
primaryColor: PrimerColors.blue500,
|
2019-03-10 16:34:34 +01:00
|
|
|
),
|
2019-01-31 07:20:48 +01:00
|
|
|
child: CupertinoTabScaffold(
|
2019-10-02 08:58:11 +02:00
|
|
|
tabBar: CupertinoTabBar(
|
|
|
|
items: _navigationItems,
|
|
|
|
// backgroundColor: PrimerColors.gray000, // TODO:
|
|
|
|
),
|
2019-01-31 07:20:48 +01:00
|
|
|
tabBuilder: (context, index) {
|
|
|
|
return CupertinoTabView(builder: (context) {
|
|
|
|
return _buildScreen(index);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return MaterialApp(
|
2019-03-10 06:24:40 +01:00
|
|
|
theme: themData,
|
2019-01-31 07:20:48 +01:00
|
|
|
home: Scaffold(
|
|
|
|
body: _buildScreen(active),
|
|
|
|
bottomNavigationBar: BottomNavigationBar(
|
2019-09-30 11:37:51 +02:00
|
|
|
backgroundColor: Colors.white,
|
2019-09-14 19:00:31 +02:00
|
|
|
selectedItemColor: PrimerColors.blue500,
|
2019-10-02 08:58:11 +02:00
|
|
|
items: _navigationItems,
|
2019-01-31 07:20:48 +01:00
|
|
|
currentIndex: active,
|
|
|
|
type: BottomNavigationBarType.fixed,
|
|
|
|
onTap: (int index) {
|
|
|
|
setState(() {
|
|
|
|
active = index;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class App extends StatelessWidget {
|
2018-04-25 15:07:44 +02:00
|
|
|
@override
|
2019-09-02 14:40:20 +02:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MultiProvider(
|
|
|
|
providers: [
|
|
|
|
ChangeNotifierProvider(builder: (context) => NotificationModel()),
|
2019-09-02 15:52:32 +02:00
|
|
|
ChangeNotifierProvider(builder: (context) => ThemeModel()),
|
2019-09-27 14:52:38 +02:00
|
|
|
ChangeNotifierProvider(builder: (context) => AuthModel()),
|
2019-09-15 11:36:09 +02:00
|
|
|
ChangeNotifierProvider(builder: (context) => CodeModel()),
|
2019-09-02 14:40:20 +02:00
|
|
|
],
|
2019-09-08 14:07:35 +02:00
|
|
|
child: Home(),
|
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
|
|
|
}
|