mirror of
https://github.com/git-touch/git-touch
synced 2024-12-17 02:38:39 +01:00
fix: mark all as read
This commit is contained in:
parent
e7b01a0c23
commit
0d164904f1
@ -4,6 +4,7 @@ import 'package:git_touch/models/code.dart';
|
|||||||
import 'package:git_touch/models/auth.dart';
|
import 'package:git_touch/models/auth.dart';
|
||||||
import 'package:git_touch/models/theme.dart';
|
import 'package:git_touch/models/theme.dart';
|
||||||
import 'package:git_touch/screens/issues.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/repository.dart';
|
||||||
import 'package:git_touch/screens/repositories.dart';
|
import 'package:git_touch/screens/repositories.dart';
|
||||||
import 'package:git_touch/screens/user.dart';
|
import 'package:git_touch/screens/user.dart';
|
||||||
@ -11,7 +12,6 @@ import 'package:primer/primer.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:git_touch/models/notification.dart';
|
import 'package:git_touch/models/notification.dart';
|
||||||
import 'screens/news.dart';
|
import 'screens/news.dart';
|
||||||
import 'screens/notifications.dart';
|
|
||||||
import 'screens/search.dart';
|
import 'screens/search.dart';
|
||||||
import 'screens/login.dart';
|
import 'screens/login.dart';
|
||||||
import 'screens/issue.dart';
|
import 'screens/issue.dart';
|
||||||
@ -154,8 +154,8 @@ class _HomeState extends State<Home> {
|
|||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
body: _buildScreen(active),
|
body: _buildScreen(active),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
selectedItemColor: PrimerColors.blue500,
|
selectedItemColor: PrimerColors.blue500,
|
||||||
// unselectedItemColor: PrimerColors.gray500,
|
|
||||||
items: _buildNavigationItems(),
|
items: _buildNavigationItems(),
|
||||||
currentIndex: active,
|
currentIndex: active,
|
||||||
type: BottomNavigationBarType.fixed,
|
type: BottomNavigationBarType.fixed,
|
||||||
|
@ -6,16 +6,16 @@ import 'package:git_touch/scaffolds/utils.dart';
|
|||||||
class TabStatefulScaffold<T> extends StatefulWidget {
|
class TabStatefulScaffold<T> extends StatefulWidget {
|
||||||
final Widget title;
|
final Widget title;
|
||||||
final Widget Function(T payload, int activeTab) bodyBuilder;
|
final Widget Function(T payload, int activeTab) bodyBuilder;
|
||||||
final Future<T> Function(int activeTab) onRefresh;
|
final Future<T> Function(int activeTab) fetchData;
|
||||||
final List<String> tabs;
|
final List<String> tabs;
|
||||||
final Widget Function(T payload) trailingBuilder;
|
final Widget Function(T payload, void Function() refresh) actionBuilder;
|
||||||
|
|
||||||
TabStatefulScaffold({
|
TabStatefulScaffold({
|
||||||
@required this.title,
|
@required this.title,
|
||||||
@required this.bodyBuilder,
|
@required this.bodyBuilder,
|
||||||
@required this.onRefresh,
|
@required this.fetchData,
|
||||||
@required this.tabs,
|
@required this.tabs,
|
||||||
this.trailingBuilder,
|
this.actionBuilder,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -71,7 +71,7 @@ class _TabStatefulScaffoldState<T> extends State<TabStatefulScaffold<T>> {
|
|||||||
_error = '';
|
_error = '';
|
||||||
_loading = true;
|
_loading = true;
|
||||||
});
|
});
|
||||||
_payload = await widget.onRefresh(_activeTab);
|
_payload = await widget.fetchData(_activeTab);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_error = err.toString();
|
_error = err.toString();
|
||||||
throw err;
|
throw err;
|
||||||
@ -95,16 +95,13 @@ class _TabStatefulScaffoldState<T> extends State<TabStatefulScaffold<T>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildTrailing() {
|
|
||||||
if (_payload == null || widget.trailingBuilder == null) return null;
|
|
||||||
return widget.trailingBuilder(_payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return TabScaffold(
|
return TabScaffold(
|
||||||
title: widget.title,
|
title: widget.title,
|
||||||
trailing: _buildTrailing(),
|
trailing: widget.actionBuilder == null
|
||||||
|
? null
|
||||||
|
: widget.actionBuilder(_payload, _refresh),
|
||||||
tabs: widget.tabs,
|
tabs: widget.tabs,
|
||||||
activeTab: _activeTab,
|
activeTab: _activeTab,
|
||||||
onTabSwitch: _switch,
|
onTabSwitch: _switch,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/cupertino.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/scaffolds/tab_stateful.dart';
|
||||||
|
import 'package:git_touch/widgets/action_entry.dart';
|
||||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:git_touch/models/notification.dart';
|
import 'package:git_touch/models/notification.dart';
|
||||||
@ -143,42 +145,7 @@ $key: pullRequest(number: ${item.number}) {
|
|||||||
return TabStatefulScaffold(
|
return TabStatefulScaffold(
|
||||||
title: AppBarTitle('Notifications'),
|
title: AppBarTitle('Notifications'),
|
||||||
tabs: ['Unread', 'Paticipating', 'All'],
|
tabs: ['Unread', 'Paticipating', 'All'],
|
||||||
// trailing: GestureDetector(
|
fetchData: fetchNotifications,
|
||||||
// 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<ThemeModel>(context)
|
|
||||||
// // .showConfirm(context, 'Mark all as read?');
|
|
||||||
// // if (value) {
|
|
||||||
// // await Provider.of<SettingsModel>(context)
|
|
||||||
// // .putWithCredentials('/notifications');
|
|
||||||
// // await fetchNotifications(0);
|
|
||||||
// // }
|
|
||||||
// },
|
|
||||||
// ),
|
|
||||||
onRefresh: fetchNotifications,
|
|
||||||
bodyBuilder: (groupMap, activeTab) {
|
bodyBuilder: (groupMap, activeTab) {
|
||||||
if (groupMap.isEmpty) return EmptyWidget();
|
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<ThemeModel>(context)
|
||||||
|
.showConfirm(context, 'Mark all as read?');
|
||||||
|
if (value) {
|
||||||
|
await Provider.of<AuthModel>(context)
|
||||||
|
.putWithCredentials('/notifications');
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,7 +12,7 @@ class TrendingScreen extends StatelessWidget {
|
|||||||
return TabStatefulScaffold(
|
return TabStatefulScaffold(
|
||||||
title: AppBarTitle('Trending'),
|
title: AppBarTitle('Trending'),
|
||||||
tabs: ['Repositories', 'Users'],
|
tabs: ['Repositories', 'Users'],
|
||||||
onRefresh: (tabIndex) async {
|
fetchData: (tabIndex) async {
|
||||||
var uri = Uri.parse('https://github-trending-api.now.sh')
|
var uri = Uri.parse('https://github-trending-api.now.sh')
|
||||||
.resolve(tabIndex == 1 ? '/developers' : '/');
|
.resolve(tabIndex == 1 ? '/developers' : '/');
|
||||||
var res = await http.get(uri);
|
var res = await http.get(uri);
|
||||||
|
Loading…
Reference in New Issue
Block a user