diff --git a/lib/main.dart b/lib/main.dart index 80e3163..25e982b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:git_touch/models/code.dart'; import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/theme.dart'; import 'package:git_touch/screens/issues.dart'; +import 'package:git_touch/screens/notification.dart'; import 'package:git_touch/screens/repository.dart'; import 'package:git_touch/screens/repositories.dart'; import 'package:git_touch/screens/user.dart'; @@ -11,7 +12,6 @@ import 'package:primer/primer.dart'; import 'package:provider/provider.dart'; import 'package:git_touch/models/notification.dart'; import 'screens/news.dart'; -import 'screens/notifications.dart'; import 'screens/search.dart'; import 'screens/login.dart'; import 'screens/issue.dart'; @@ -154,8 +154,8 @@ class _HomeState extends State { home: Scaffold( body: _buildScreen(active), bottomNavigationBar: BottomNavigationBar( + backgroundColor: Colors.white, selectedItemColor: PrimerColors.blue500, - // unselectedItemColor: PrimerColors.gray500, items: _buildNavigationItems(), currentIndex: active, type: BottomNavigationBarType.fixed, diff --git a/lib/scaffolds/tab_stateful.dart b/lib/scaffolds/tab_stateful.dart index 591e296..006112d 100644 --- a/lib/scaffolds/tab_stateful.dart +++ b/lib/scaffolds/tab_stateful.dart @@ -6,16 +6,16 @@ import 'package:git_touch/scaffolds/utils.dart'; class TabStatefulScaffold extends StatefulWidget { final Widget title; final Widget Function(T payload, int activeTab) bodyBuilder; - final Future Function(int activeTab) onRefresh; + final Future Function(int activeTab) fetchData; final List tabs; - final Widget Function(T payload) trailingBuilder; + final Widget Function(T payload, void Function() refresh) actionBuilder; TabStatefulScaffold({ @required this.title, @required this.bodyBuilder, - @required this.onRefresh, + @required this.fetchData, @required this.tabs, - this.trailingBuilder, + this.actionBuilder, }); @override @@ -71,7 +71,7 @@ class _TabStatefulScaffoldState extends State> { _error = ''; _loading = true; }); - _payload = await widget.onRefresh(_activeTab); + _payload = await widget.fetchData(_activeTab); } catch (err) { _error = err.toString(); throw err; @@ -95,16 +95,13 @@ class _TabStatefulScaffoldState extends State> { } } - Widget _buildTrailing() { - if (_payload == null || widget.trailingBuilder == null) return null; - return widget.trailingBuilder(_payload); - } - @override Widget build(BuildContext context) { return TabScaffold( title: widget.title, - trailing: _buildTrailing(), + trailing: widget.actionBuilder == null + ? null + : widget.actionBuilder(_payload, _refresh), tabs: widget.tabs, activeTab: _activeTab, onTabSwitch: _switch, diff --git a/lib/screens/notifications.dart b/lib/screens/notification.dart similarity index 77% rename from lib/screens/notifications.dart rename to lib/screens/notification.dart index dccf9d4..564e537 100644 --- a/lib/screens/notifications.dart +++ b/lib/screens/notification.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; +import 'package:git_touch/models/theme.dart'; import 'package:git_touch/scaffolds/tab_stateful.dart'; +import 'package:git_touch/widgets/action_entry.dart'; import 'package:git_touch/widgets/app_bar_title.dart'; import 'package:provider/provider.dart'; import 'package:git_touch/models/notification.dart'; @@ -143,42 +145,7 @@ $key: pullRequest(number: ${item.number}) { return TabStatefulScaffold( title: AppBarTitle('Notifications'), tabs: ['Unread', 'Paticipating', 'All'], - // trailing: GestureDetector( - // child: Icon(Icons.more_vert, size: 20), - // onTap: () async { - // int value = await showCupertinoDialog( - // context: context, - // builder: (context) { - // return CupertinoAlertDialog( - // title: Text('Select filter'), - // actions: textMap.entries.map((entry) { - // return CupertinoDialogAction( - // child: Text(entry.value), - // onPressed: () { - // Navigator.pop(context, entry.key); - // }, - // ); - // }).toList(), - // ); - // }, - // ); - // _onSwitchTab(value); - // }, - // ), - // trailingBuilder: (_) => IconButton( - // icon: Icon(Icons.done_all), - // onPressed: () async { - // // TODO: - // // var value = await Provider.of(context) - // // .showConfirm(context, 'Mark all as read?'); - // // if (value) { - // // await Provider.of(context) - // // .putWithCredentials('/notifications'); - // // await fetchNotifications(0); - // // } - // }, - // ), - onRefresh: fetchNotifications, + fetchData: fetchNotifications, bodyBuilder: (groupMap, activeTab) { if (groupMap.isEmpty) return EmptyWidget(); @@ -191,6 +158,18 @@ $key: pullRequest(number: ${item.number}) { ], ); }, + actionBuilder: (_, refresh) => ActionEntry( + iconData: Icons.done_all, + onTap: () async { + var value = await Provider.of(context) + .showConfirm(context, 'Mark all as read?'); + if (value) { + await Provider.of(context) + .putWithCredentials('/notifications'); + refresh(); + } + }, + ), ); } } diff --git a/lib/screens/trending.dart b/lib/screens/trending.dart index 706774a..3fa128b 100644 --- a/lib/screens/trending.dart +++ b/lib/screens/trending.dart @@ -12,7 +12,7 @@ class TrendingScreen extends StatelessWidget { return TabStatefulScaffold( title: AppBarTitle('Trending'), tabs: ['Repositories', 'Users'], - onRefresh: (tabIndex) async { + fetchData: (tabIndex) async { var uri = Uri.parse('https://github-trending-api.now.sh') .resolve(tabIndex == 1 ? '/developers' : '/'); var res = await http.get(uri);