-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathappbar.dart
164 lines (152 loc) · 4.46 KB
/
appbar.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/// provides a context-specific app bar and drawer
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'gameflow.dart';
import 'io.dart';
import 'store.dart';
import 'utils.dart';
class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
final String? title;
MyAppBar([this.title]);
@override
Size get preferredSize => new Size.fromHeight(kToolbarHeight);
@override
Widget build(BuildContext context) {
final String routeName = GLOBAL.currentRouteName(context);
final List<Widget> actions = [];
// don't show help button on help pages or welcome page;
if (![ROUTES.help, ROUTES.helpSettings, ROUTES.welcome]
.contains(routeName)) {
actions.add(IconButton(
icon: new Icon(Icons.help),
onPressed: () {
String nextRoute = ROUTES.help;
switch (routeName) {
case ROUTES.settings:
nextRoute = ROUTES.helpSettings;
break;
}
Navigator.pushNamed(context, nextRoute);
},
));
}
return AppBar(
primary: true,
title: AutoSizeText(title ?? 'Riichi scorer', maxLines: 2),
actions: actions,
);
}
}
Drawer myDrawer(BuildContext context) {
bool gameInProgress = store.state.inProgress;
TextStyle deactivatedText = TextStyle(color: Colors.grey[500]);
dynamic inProgressStyle = gameInProgress ? null : deactivatedText;
List<Widget> listTiles = <Widget>[
/*DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
margin: EdgeInsets.all(1),
padding:EdgeInsets.all(1),
child: Text(''),
),*/
ListTile(
title: Text('Chombo', style: inProgressStyle),
onTap: gameInProgress
? (() {
Navigator.popAndPushNamed(context, ROUTES.chombo);
})
: null,
),
ListTile(
title: Text('Undo last hand', style: inProgressStyle),
onTap: gameInProgress
? (() {
Navigator.pop(context);
Scoring.maybeUndoLastHand(context);
})
: null,
),
ListTile(
title: Text('Finish this game', style: inProgressStyle),
onTap: gameInProgress
? (() {
Navigator.pop(context);
Scoring.askToFinishGame(context);
})
: null,
),
ListTile(
title: Text('Resume an ongoing saved game'),
onTap: () {
Navigator.popAndPushNamed(context, ROUTES.liveGames);
},
),
ListTile(
title: Text('View scoresheet of a finished game'),
onTap: () {
Navigator.popAndPushNamed(context, ROUTES.deadGames);
}),
ListTile(
title: Text('New game'),
onTap: (() async {
Navigator.pop(context);
if (gameInProgress) {
bool? reallyFinish = await GLOBAL.yesNoDialog(context,
prompt:
'Really shelve this game now (it can be continued later) and start a new one?',
trueText: 'Yes, shelve it and start a new game',
falseText: 'No, carry on playing this game');
if (reallyFinish == true) {
Scoring.deleteIfEmpty(context);
Navigator.pushNamedAndRemoveUntil(context, ROUTES.selectPlayers,
ModalRoute.withName(ROUTES.hands));
}
return;
}
Navigator.pushNamed(context, ROUTES.selectPlayers);
}),
),
ListTile(
title: Text('Settings'),
trailing: Icon(Icons.settings),
onTap: () {
Navigator.popAndPushNamed(context, ROUTES.settings);
},
),
ListTile(
title: Text('Privacy policy'),
trailing: Icon(Icons.lock_outline),
onTap: () =>
Navigator.popAndPushNamed(context, ROUTES.privacyPolicy),
),
ListTile(
title: Text('Exit app'),
onTap: () async {
Navigator.pop(context);
bool? reallyQuit = await GLOBAL.yesNoDialog(
context,
prompt: 'Really quit?',
trueText: 'Yes, really quit',
falseText: "No, don't quit",
);
if (reallyQuit == true) {
SystemNavigator.pop();
}
},
),
];
if (USING_IO) {
listTiles.add(ListTile(
title: Text('show network log'),
trailing: Icon(Icons.network_wifi),
onTap: () => IO.httpLogger.showInspector(),
));
}
return Drawer(
child: ListView(
children: listTiles,
),
);
}