git-touch-android-ios-app/lib/main.dart

191 lines
5.3 KiB
Dart
Raw Normal View History

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-05-12 09:47:36 +02:00
import 'package:git_touch/screens/repo.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';
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/me.dart';
2019-02-07 07:35:19 +01:00
import 'screens/login.dart';
import 'screens/issue.dart';
2019-02-09 06:36:15 +01:00
import 'screens/repos.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';
import 'utils/utils.dart';
2018-04-18 14:38:28 +02:00
class Home extends StatefulWidget {
@override
2019-02-07 07:35:19 +01:00
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
int active = 0;
2019-02-08 16:20:28 +01:00
// String login;
2019-01-31 15:07:52 +01:00
Widget _buildNotificationIcon(BuildContext context) {
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) {
return Icon(Icons.notifications_none);
2019-01-31 15:07:52 +01:00
}
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_none),
2019-02-06 14:35:52 +01:00
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
)
]);
}
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),
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'),
),
BottomNavigationBarItem(
icon: Icon(Icons.person_outline),
title: Text('Me'),
),
];
}
_buildScreen(int index) {
// 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);
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();
case 3:
2019-03-02 11:17:46 +01:00
return SearchScreen();
case 4:
return MeScreen();
}
}
@override
Widget build(BuildContext context) {
2019-02-07 07:35:19 +01:00
var settings = SettingsProvider.of(context);
var themData = ThemeData(
// primaryColor: HSLColor.fromColor(Palette.primary)
// .withLightness(0.3)
// .toColor(),
// primaryColor: Color(0xff333333),
2019-05-12 09:14:28 +02:00
primaryColor: PrimerColors.gray900,
accentColor: PrimerColors.gray900,
);
2019-02-07 07:35:19 +01:00
// TODO:
2019-02-07 07:35:19 +01:00
if (!settings.ready) {
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-02-07 07:35:19 +01:00
if (settings.activeLogin == null) {
return MaterialApp(theme: themData, home: LoginScreen());
2019-02-07 07:35:19 +01:00
}
switch (settings.theme) {
case ThemeMap.cupertino:
return CupertinoApp(
home: CupertinoTheme(
2019-03-10 16:34:34 +01:00
data: CupertinoThemeData(
textTheme: CupertinoTextThemeData(
// primaryColor: Palette.primary,
2019-05-12 09:14:28 +02:00
textStyle: TextStyle(color: PrimerColors.gray900),
2019-03-10 16:34:34 +01:00
),
2019-07-28 15:59:18 +02:00
primaryColor: PrimerColors.gray900,
2019-03-10 16:34:34 +01:00
),
child: CupertinoTabScaffold(
tabBar: CupertinoTabBar(items: _buildNavigationItems()),
tabBuilder: (context, index) {
return CupertinoTabView(builder: (context) {
return _buildScreen(index);
});
},
),
),
);
default:
return MaterialApp(
theme: themData,
home: Scaffold(
body: _buildScreen(active),
bottomNavigationBar: BottomNavigationBar(
items: _buildNavigationItems(),
currentIndex: active,
type: BottomNavigationBarType.fixed,
onTap: (int index) {
setState(() {
active = index;
});
},
),
),
);
}
}
}
class App extends StatelessWidget {
@override
2019-09-02 14:40:20 +02:00
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(builder: (context) => NotificationModel()),
],
child: SettingsProvider(child: Home()),
);
}
}
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');
// }
// 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());
}