1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-13 17:08:49 +01:00

feat: notification screen filter

This commit is contained in:
Rongjian Zhang 2019-02-07 20:28:48 +08:00
parent 5c0870a80b
commit 7c35bb7ffb
5 changed files with 86 additions and 51 deletions

View File

@ -103,6 +103,9 @@ class _HomeState extends State<Home> {
);
default:
return MaterialApp(
theme: ThemeData(
// primaryColor: Colors.black87,
),
home: Scaffold(
// appBar: AppBar(title: Text('Home')),
body: _buildScreen(active),

View File

@ -148,7 +148,7 @@ class _SettingsProviderState extends State<SettingsProvider> {
} else if (Platform.isIOS) {
theme = ThemeMap.cupertino;
}
// layout = LayoutMap.material;
theme = ThemeMap.material;
setState(() {
ready = true;
@ -213,8 +213,10 @@ class _SettingsProviderState extends State<SettingsProvider> {
var headers = {HttpHeaders.authorizationHeader: 'token $token'};
final res =
await http.put(prefix + url, headers: headers, body: body ?? {});
final data = json.decode(res.body);
return data;
print(res.body);
// final data = json.decode(res.body);
// return data;
return true;
}
String randomString;

View File

@ -111,7 +111,9 @@ $key: pullRequest(number: ${item.number}) {
}
Widget _buildGroupItem(
BuildContext context, MapEntry<String, NotificationGroup> entry) {
BuildContext context,
MapEntry<String, NotificationGroup> entry,
) {
var group = entry.value;
var repo = group.repo;
return ListGroup(
@ -149,7 +151,11 @@ $key: pullRequest(number: ${item.number}) {
});
}
Future<void> _onSwitchTab(int index) async {
Future<void> _onSwitchTab([int index]) async {
if (index == null) {
index = active;
}
setState(() {
active = index;
loading = true;
@ -166,7 +172,6 @@ $key: pullRequest(number: ${item.number}) {
}
Future<void> _refresh() async {
// setState(() {});
await _onSwitchTab(active);
}
@ -176,48 +181,67 @@ $key: pullRequest(number: ${item.number}) {
2: 'All',
};
// var iconMap = {
// 0: Icon(Icons.inbox),
// 1: Icon(Icons.group),
// 2: Icon(Icons.mail),
// };
Widget _buildTitle() {
switch (SettingsProvider.of(context).theme) {
case ThemeMap.cupertino:
// var textStyle = DefaultTextStyle.of(context).style;
return DefaultTextStyle(
style: TextStyle(fontSize: 16),
child: SizedBox.expand(
child: CupertinoSegmentedControl(
groupValue: active,
onValueChanged: _onSwitchTab,
children: textMap.map((key, text) => MapEntry(key, Text(text))),
),
),
);
default:
return Text('Notifications');
}
}
void _confirm() async {
var value = await showConfirm(context, 'Mark all as read?');
if (value) {
await SettingsProvider.of(context).putWithCredentials('/notifications');
await _refresh();
}
}
@override
Widget build(context) {
return RefreshScaffold(
title: Text(textMap[active]),
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);
},
title: _buildTitle(),
bottom: TabBar(
onTap: _onSwitchTab,
tabs: textMap.entries.map((entry) => Tab(text: entry.value)).toList(),
),
// 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);
// },
// ),
actions: <Widget>[
PopupMenuButton(
onSelected: (value) {
_onSwitchTab(value);
},
itemBuilder: (context) {
return textMap.entries.map((entry) {
return PopupMenuItem(value: entry.key, child: Text(entry.value));
}).toList();
},
IconButton(
icon: Icon(Octicons.check),
onPressed: _confirm,
)
],
onRefresh: _refresh,

View File

@ -24,7 +24,7 @@ class Option<T> {
Option({this.value, this.widget});
}
Future<bool> showConfim(BuildContext context, String text) {
Future<bool> showConfirm(BuildContext context, String text) {
switch (SettingsProvider.of(context).theme) {
case ThemeMap.cupertino:
return showCupertinoDialog(

View File

@ -14,6 +14,7 @@ class RefreshScaffold extends StatelessWidget {
final bool loading;
final Widget trailing;
final List<Widget> actions;
final PreferredSizeWidget bottom;
RefreshScaffold({
@required this.title,
@ -22,6 +23,7 @@ class RefreshScaffold extends StatelessWidget {
@required this.loading,
this.trailing,
this.actions,
this.bottom,
});
Widget _buildBody() {
@ -49,14 +51,18 @@ class RefreshScaffold extends StatelessWidget {
),
);
default:
return Scaffold(
appBar: AppBar(
title: title,
actions: actions,
),
body: RefreshIndicator(
onRefresh: onRefresh,
child: SingleChildScrollView(child: _buildBody()),
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: title,
actions: actions,
bottom: bottom,
),
body: RefreshIndicator(
onRefresh: onRefresh,
child: SingleChildScrollView(child: _buildBody()),
),
),
);
}