-
Notifications
You must be signed in to change notification settings - Fork 495
Expand file tree
/
Copy pathuser_page.dart
More file actions
308 lines (298 loc) · 10.7 KB
/
user_page.dart
File metadata and controls
308 lines (298 loc) · 10.7 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:fun_android/generated/i18n.dart';
import 'package:fun_android/ui/page/change_log_page.dart';
import 'package:fun_android/ui/widget/app_bar.dart';
import 'package:fun_android/view_model/coin_model.dart';
import 'package:oktoast/oktoast.dart';
import 'package:provider/provider.dart';
import 'package:fun_android/config/resource_mananger.dart';
import 'package:fun_android/config/router_manger.dart';
import 'package:fun_android/provider/provider_widget.dart';
import 'package:fun_android/ui/widget/bottom_clipper.dart';
import 'package:fun_android/view_model/login_model.dart';
import 'package:fun_android/view_model/theme_model.dart';
import 'package:fun_android/view_model/user_model.dart';
class UserPage extends StatefulWidget {
@override
_UserPageState createState() => _UserPageState();
}
class _UserPageState extends State<UserPage>
with AutomaticKeepAliveClientMixin {
@override
bool get wantKeepAlive => true;
@override
Widget build(BuildContext context) {
super.build(context);
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
actions: <Widget>[
ProviderWidget<LoginModel>(
model: LoginModel(Provider.of(context)),
builder: (context, model, child) {
if (model.busy) {
return Padding(
padding: const EdgeInsets.only(right: 15.0),
child: AppBarIndicator(),
);
}
if (model.userModel.hasUser) {
return IconButton(
tooltip: S.of(context).logout,
icon: Icon(Icons.exit_to_app),
onPressed: () {
model.logout();
},
);
}
return SizedBox.shrink();
})
],
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
expandedHeight: 200 + MediaQuery.of(context).padding.top,
flexibleSpace: UserHeaderWidget(),
pinned: false,
),
UserListWidget(),
],
));
}
}
class UserHeaderWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ClipPath(
clipper: BottomClipper(),
child: Container(
color: Theme.of(context).primaryColor.withAlpha(200),
padding: EdgeInsets.only(top: 10),
child: Consumer<UserModel>(
builder: (context, model, child) => InkWell(
onTap: model.hasUser
? null
: () {
Navigator.of(context).pushNamed(RouteName.login);
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
InkWell(
child: Hero(
tag: 'loginLogo',
child: ClipOval(
child: Image.asset(
ImageHelper.wrapAssets('user_avatar.png'),
fit: BoxFit.cover,
width: 80,
height: 80,
color: model.hasUser
? Theme.of(context)
.accentColor
.withAlpha(200)
: Theme.of(context)
.accentColor
.withAlpha(10),
// https://api.flutter.dev/flutter/dart-ui/BlendMode-class.html
colorBlendMode: BlendMode.colorDodge),
),
),
),
SizedBox(
height: 20,
),
Column(children: <Widget>[
Text(
model.hasUser
? model.user.nickname
: S.of(context).toSignIn,
style: Theme.of(context)
.textTheme
.title
.apply(color: Colors.white.withAlpha(200))),
SizedBox(
height: 10,
),
if (model.hasUser) UserCoin()
])
])))));
}
}
class UserCoin extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ProviderWidget<CoinModel>(
model: CoinModel(),
onModelReady: (model) => model.initData(),
builder: (context, model, child) {
if (model.busy) {
return AppBarIndicator(radius: 8);
}
var textStyle = Theme.of(context).textTheme.body1.copyWith(
color: Colors.white.withAlpha(200),
decoration: TextDecoration.underline);
return InkWell(
onTap: () {
if (model.error) {
model.initData();
} else if (model.idle) {
Navigator.pushNamed(context, RouteName.coinRecordList);
}
},
child: model.error
? Text(S.of(context).retry, style: textStyle)
: Text('${S.of(context).coin}:${model.coin}',
style: textStyle));
});
}
}
class UserListWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
var iconColor = Theme.of(context).accentColor;
return ListTileTheme(
contentPadding: const EdgeInsets.symmetric(horizontal: 30),
child: SliverList(
delegate: SliverChildListDelegate([
ListTile(
title: Text(S.of(context).favourites),
onTap: () {
Navigator.of(context).pushNamed(RouteName.favouriteList);
},
leading: Icon(
Icons.favorite_border,
color: iconColor,
),
trailing: Icon(Icons.chevron_right),
),
ListTile(
title: Text(S.of(context).darkMode),
onTap: () {
switchDarkMode(context);
},
leading: Transform.rotate(
angle: -pi,
child: Icon(
Theme.of(context).brightness == Brightness.light
? Icons.brightness_5
: Icons.brightness_2,
color: iconColor,
),
),
trailing: CupertinoSwitch(
activeColor: Theme.of(context).accentColor,
value: Theme.of(context).brightness == Brightness.dark,
onChanged: (value) {
switchDarkMode(context);
}),
),
SettingThemeWidget(),
ListTile(
title: Text(S.of(context).setting),
onTap: () {
Navigator.pushNamed(context, RouteName.setting);
},
leading: Icon(
Icons.settings,
color: iconColor,
),
trailing: Icon(Icons.chevron_right),
),
ListTile(
title: Text(S.of(context).appUpdateCheckUpdate),
onTap: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => ChangeLogPage(),
fullscreenDialog: true,
),
);
},
leading: Icon(
Icons.system_update,
color: iconColor,
),
trailing: Icon(Icons.chevron_right),
),
SizedBox(
height: 30,
)
]),
),
);
}
void switchDarkMode(BuildContext context) {
if (MediaQuery.of(context).platformBrightness == Brightness.dark) {
showToast("检测到系统为暗黑模式,已为你自动切换", position: ToastPosition.bottom);
} else {
Provider.of<ThemeModel>(context).switchTheme(
userDarkMode: Theme.of(context).brightness == Brightness.light);
}
}
}
class SettingThemeWidget extends StatelessWidget {
SettingThemeWidget();
@override
Widget build(BuildContext context) {
return ExpansionTile(
title: Text(S.of(context).theme),
leading: Icon(
Icons.color_lens,
color: Theme.of(context).accentColor,
),
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Wrap(
spacing: 5,
runSpacing: 5,
children: <Widget>[
...Colors.primaries.map((color) {
return Material(
color: color,
child: InkWell(
onTap: () {
var model = Provider.of<ThemeModel>(context);
// var brightness = Theme.of(context).brightness;
model.switchTheme(color: color);
},
child: Container(
width: 40,
height: 40,
),
),
);
}).toList(),
Material(
child: InkWell(
onTap: () {
var model = Provider.of<ThemeModel>(context);
var brightness = Theme.of(context).brightness;
model.switchRandomTheme(brightness: brightness);
},
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
border:
Border.all(color: Theme.of(context).accentColor)),
width: 40,
height: 40,
child: Text(
"?",
style: TextStyle(
fontSize: 20, color: Theme.of(context).accentColor),
),
),
),
)
],
),
),
],
);
}
}