Skip to content

Commit 96bc43d

Browse files
committed
Refactor login and reply buttons, add icons, and comment out picture bed setting
This commit introduces the following changes: - **Login Page (`LoginPage.dart`):** - Replaced `ProgressButton` with `PlatformElevatedButton` for both login and "Sign in via Browser" actions. - Introduced `LoginResultStatus` enum (`idle`, `loading`) to manage button state. - Login button now displays an icon (`loginUserSolid`) and text, or a `PlatformCircularProgressIndicator` when loading. - "Sign in via Browser" button now displays an icon (`loginUserInWebSolid`) and text, or a `PlatformCircularProgressIndicator` when loading. - Buttons are disabled during the loading state. - **View Thread Page (`ViewThreadSliverPage.dart`):** - Replaced `ProgressButton` for sending replies with `IconButton`. - Introduced `SendReplyStatus` enum (`idle`, `loading`, `success`, `fail`) to manage the reply button's icon. - The reply button now shows different icons based on the `SendReplyStatus`: - `idle`: `postThreadSolid` - `loading`: `PlatformCircularProgressIndicator` - `success`: `checkCircleSolid` - `fail`: `errorOutline` - **App Platform Icons (`AppPlatformIcons.dart`):** - Added new icons: - `loginUserInWebSolid`: `Icons.web` (Material) / `CupertinoIcons.arrow_right_circle` (Cupertino) - `errorOutline`: `Icons.error_outline` (Material) / `CupertinoIcons.exclamationmark_circle` (Cupertino) - **Settings Page (`SettingPage.dart`):** - Commented out the "Picture Bed" settings tile.
1 parent aa24c19 commit 96bc43d

File tree

4 files changed

+108
-113
lines changed

4 files changed

+108
-113
lines changed

lib/page/LoginPage.dart

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,18 @@ class LoginForumFieldStatefulWidget extends StatefulWidget {
6767
}
6868
}
6969

70+
enum LoginResultStatus {
71+
idle,
72+
loading
73+
}
74+
7075
class _LoginFormFieldState extends State<LoginForumFieldStatefulWidget> {
7176
late final Discuz discuz;
7277
String? accountName;
73-
78+
LoginResultStatus _loginState = LoginResultStatus.idle;
7479
final _formKey = GlobalKey<FormState>();
7580
DiscuzError? error = null;
76-
ButtonState _loginState = ButtonState.idle;
81+
7782
final TextEditingController _accountController = new TextEditingController();
7883
final TextEditingController _passwdController = new TextEditingController();
7984
final CaptchaController _captchaController =
@@ -209,7 +214,7 @@ class _LoginFormFieldState extends State<LoginForumFieldStatefulWidget> {
209214
await _initDio();
210215
final client = MobileApiClient(_dio, baseUrl: discuz.baseURL);
211216
setState(() {
212-
_loginState = ButtonState.loading;
217+
_loginState = LoginResultStatus.loading;
213218
});
214219

215220
CaptchaFields? captchaFields = _captchaController.value;
@@ -239,7 +244,7 @@ class _LoginFormFieldState extends State<LoginForumFieldStatefulWidget> {
239244
if (value.errorResult!.key == "login_succeed") {
240245
// save it in database
241246
setState(() {
242-
_loginState = ButtonState.success;
247+
_loginState = LoginResultStatus.idle;
243248
});
244249
try {
245250
final dao = await AppDatabase.getUserDao();
@@ -281,14 +286,14 @@ class _LoginFormFieldState extends State<LoginForumFieldStatefulWidget> {
281286
setState(() {
282287
error =
283288
DiscuzError(value.errorResult!.key, value.errorResult!.content);
284-
_loginState = ButtonState.fail;
289+
_loginState = LoginResultStatus.idle;
285290
});
286291
}
287292
}).catchError((onError) {
288293
VibrationUtils.vibrateErrorIfPossible();
289294
_captchaController.reloadCaptcha();
290295
setState(() {
291-
_loginState = ButtonState.fail;
296+
_loginState = LoginResultStatus.idle;
292297
});
293298

294299
switch (onError.runtimeType) {
@@ -474,40 +479,28 @@ class _LoginFormFieldState extends State<LoginForumFieldStatefulWidget> {
474479
children: [
475480
SizedBox(
476481
width: double.infinity,
477-
child: ProgressButton.icon(
478-
maxWidth: 230.0,
479-
iconedButtons: {
480-
ButtonState.idle: IconedButton(
481-
text: S.of(context).loginTitle,
482-
icon: Icon(AppPlatformIcons(context).loginUserSolid,
483-
color: Theme.of(context).colorScheme.onPrimary
484-
),
485-
color:
486-
Theme.of(context).colorScheme.primary),
487-
ButtonState.loading: IconedButton(
488-
text: S.of(context).progressButtonLogining,
489-
color: Colors.blue.shade300),
490-
ButtonState.fail: IconedButton(
491-
text:
492-
S.of(context).progressButtonLoginFailed,
493-
icon:
494-
Icon(AppPlatformIcons(context).loginUserFailedSolid, color: Colors.white),
495-
color: Colors.red.shade300),
496-
ButtonState.success: IconedButton(
497-
text: S
498-
.of(context)
499-
.progressButtonLoginSuccess,
500-
icon: Icon(
501-
AppPlatformIcons(context).loginUserSuccessSolid,
502-
color: Colors.white,
503-
),
504-
color: Colors.green.shade400)
505-
},
506-
onPressed: () {
507-
VibrationUtils.vibrateWithClickIfPossible();
508-
_verifyAccountAndPassword();
509-
},
510-
state: _loginState),
482+
child: PlatformElevatedButton(
483+
color: Theme.of(context).colorScheme.primary,
484+
child: Row(
485+
mainAxisAlignment: MainAxisAlignment.center,
486+
mainAxisSize: MainAxisSize.min,
487+
children: [
488+
_loginState == LoginResultStatus.idle?
489+
Icon(AppPlatformIcons(context).loginUserSolid, color: Theme.of(context).colorScheme.onPrimary,):
490+
PlatformCircularProgressIndicator(
491+
material: (context, platform) => MaterialProgressIndicatorData(color: Theme.of(context).colorScheme.onPrimary),
492+
cupertino: (context, platform) => CupertinoProgressIndicatorData(color: Theme.of(context).colorScheme.onPrimary),
493+
),
494+
SizedBox(width: 8,),
495+
Text(S.of(context).loginTitle, style: TextStyle(color: Theme.of(context).colorScheme.onPrimary))
496+
497+
],
498+
),
499+
onPressed: _loginState == LoginResultStatus.idle? (){
500+
VibrationUtils.vibrateWithClickIfPossible();
501+
_verifyAccountAndPassword();
502+
}: null,
503+
),
511504
),
512505
SizedBox(
513506
height: 24,
@@ -516,17 +509,25 @@ class _LoginFormFieldState extends State<LoginForumFieldStatefulWidget> {
516509
SizedBox(
517510
width: double.infinity,
518511
child: PlatformElevatedButton(
519-
padding: EdgeInsets.symmetric(
520-
vertical: 16.0, horizontal: 4.0),
521512
color: Theme.of(context)
522513
.colorScheme
523-
.secondaryContainer,
524-
child: Text(S.of(context).signInViaBrowser,
525-
style: TextStyle(
526-
color: Theme.of(context)
527-
.colorScheme
528-
.onSecondaryContainer)),
529-
onPressed: () {
514+
.primaryContainer,
515+
child: Row(
516+
mainAxisAlignment: MainAxisAlignment.center,
517+
mainAxisSize: MainAxisSize.min,
518+
children: [
519+
_loginState == LoginResultStatus.idle?
520+
Icon(AppPlatformIcons(context).loginUserInWebSolid, color: Theme.of(context).colorScheme.onPrimaryContainer,):
521+
PlatformCircularProgressIndicator(
522+
material: (context, platform) => MaterialProgressIndicatorData(color: Theme.of(context).colorScheme.onPrimaryContainer),
523+
cupertino: (context, platform) => CupertinoProgressIndicatorData(color: Theme.of(context).colorScheme.onPrimaryContainer),
524+
),
525+
SizedBox(width: 8,),
526+
Text(S.of(context).signInViaBrowser, style: TextStyle(color: _loginState == LoginResultStatus.idle? Theme.of(context).colorScheme.onPrimaryContainer: Theme.of(context).colorScheme.primary))
527+
528+
],
529+
),
530+
onPressed: _loginState == LoginResultStatus.idle? () {
530531
VibrationUtils.vibrateWithClickIfPossible();
531532
Navigator.push(
532533
context,
@@ -535,7 +536,7 @@ class _LoginFormFieldState extends State<LoginForumFieldStatefulWidget> {
535536
context: context,
536537
builder: (context) =>
537538
LoginByWebviewPage(discuz)));
538-
},
539+
}: null,
539540
),
540541
),
541542
],

lib/page/SettingPage.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ class _SettingPageState extends State<SettingPage> {
123123
});
124124
}, initialValue: recordHistory,
125125
),
126-
SettingsTile.navigation(
127-
title: Text(S.of(context).pictureBedTitle),
128-
leading: Icon(AppPlatformIcons(context).pictureBedOutlined),
129-
onPressed: (_) {
130-
VibrationUtils.vibrateWithClickIfPossible();
131-
Navigator.of(context).push(platformPageRoute(
132-
builder: (_) => ConfigurePictureBedPage(),
133-
context: context,
134-
));
135-
},
136-
),
126+
// SettingsTile.navigation(
127+
// title: Text(S.of(context).pictureBedTitle),
128+
// leading: Icon(AppPlatformIcons(context).pictureBedOutlined),
129+
// onPressed: (_) {
130+
// VibrationUtils.vibrateWithClickIfPossible();
131+
// Navigator.of(context).push(platformPageRoute(
132+
// builder: (_) => ConfigurePictureBedPage(),
133+
// context: context,
134+
// ));
135+
// },
136+
// ),
137137
SettingsTile.navigation(
138138
title: Text(S.of(context).pushNotification),
139139
leading: Icon(AppPlatformIcons(context).pushServiceOutlined),

lib/page/ViewThreadSliverPage.dart

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import 'package:discuz_flutter/provider/ReplyPostNotifierProvider.dart';
2727
import 'package:discuz_flutter/screen/EmptyListScreen.dart';
2828
import 'package:discuz_flutter/screen/ExtraFuncInThreadScreen.dart';
2929
import 'package:discuz_flutter/screen/SmileyListScreen.dart';
30+
import 'package:discuz_flutter/utility/AppPlatformIcons.dart';
3031
import 'package:discuz_flutter/utility/CustomizeColor.dart';
3132
import 'package:discuz_flutter/utility/NetworkUtils.dart';
3233
import 'package:discuz_flutter/utility/PostTextFieldUtils.dart';
@@ -103,6 +104,13 @@ class ViewThreadStatefulSliverWidget extends StatefulWidget {
103104
}
104105
}
105106

107+
enum SendReplyStatus{
108+
idle,
109+
loading,
110+
success,
111+
fail
112+
}
113+
106114
class _ViewThreadSliverState extends State<ViewThreadStatefulSliverWidget> {
107115
ViewThreadResult _viewThreadResult = ViewThreadResult();
108116
bool _isFirstLoading = true;
@@ -127,7 +135,7 @@ class _ViewThreadSliverState extends State<ViewThreadStatefulSliverWidget> {
127135
EasyRefreshController _controller = EasyRefreshController(
128136
controlFinishLoad: true, controlFinishRefresh: true);
129137
ScrollController _scrollController = ScrollController();
130-
ButtonState _sendReplyStatus = ButtonState.idle;
138+
SendReplyStatus _sendReplyStatus = SendReplyStatus.idle;
131139
ViewThreadQuery viewThreadQuery = ViewThreadQuery();
132140
Map<String, List<Comment>> postCommentList = {};
133141
final FocusNode _focusNode = FocusNode(debugLabel: "view_thread_textfield");
@@ -369,7 +377,7 @@ class _ViewThreadSliverState extends State<ViewThreadStatefulSliverWidget> {
369377
return;
370378
}
371379
setState(() {
372-
_sendReplyStatus = ButtonState.loading;
380+
_sendReplyStatus = SendReplyStatus.loading;
373381
});
374382
final dio = await NetworkUtils.getDioWithPersistCookieJar(user);
375383
final client = MobileApiClient(dio, baseUrl: discuz.baseURL);
@@ -456,24 +464,24 @@ class _ViewThreadSliverState extends State<ViewThreadStatefulSliverWidget> {
456464
EasyLoading.showSuccess(
457465
'${value.errorResult!.content}(${value.errorResult!.key})');
458466
setState(() {
459-
_sendReplyStatus = ButtonState.success;
467+
_sendReplyStatus = SendReplyStatus.success;
460468
// just to clear the pic
461469
insertedAidList.clear();
462470
});
463471
// delay
464472
Future.delayed(Duration(seconds: 1), () {
465473
setState(() {
466-
_sendReplyStatus = ButtonState.idle;
474+
_sendReplyStatus = SendReplyStatus.idle;
467475
_replyController.clear();
468476
});
469477
});
470478
} else {
471479
setState(() {
472-
_sendReplyStatus = ButtonState.fail;
480+
_sendReplyStatus = SendReplyStatus.fail;
473481
});
474482
Future.delayed(Duration(seconds: 1), () {
475483
setState(() {
476-
_sendReplyStatus = ButtonState.idle;
484+
_sendReplyStatus = SendReplyStatus.idle;
477485
//_replyController.clear();
478486
});
479487
});
@@ -484,7 +492,7 @@ class _ViewThreadSliverState extends State<ViewThreadStatefulSliverWidget> {
484492
VibrationUtils.vibrateErrorIfPossible();
485493

486494
setState(() {
487-
_sendReplyStatus = ButtonState.fail;
495+
_sendReplyStatus = SendReplyStatus.fail;
488496
});
489497
if (onError is DioException) {
490498
DioException dioError = onError;
@@ -1194,56 +1202,38 @@ class _ViewThreadSliverState extends State<ViewThreadStatefulSliverWidget> {
11941202
valueListenable: showExtraButton,
11951203
builder: (context, value, _) {
11961204
if (value == false) {
1197-
return ProgressButton.icon(
1198-
maxWidth: 60.0,
1199-
iconedButtons: {
1200-
ButtonState.idle: IconedButton(
1201-
//text: S.of(context).sendReply,
1202-
icon: Icon(
1203-
Icons.send,
1204-
color: Theme.of(context)
1205-
.colorScheme
1206-
.onPrimaryContainer,
1207-
semanticLabel: S
1208-
.of(context)
1209-
.sendReply,
1210-
),
1211-
color: Theme.of(context)
1212-
.colorScheme
1213-
.primaryContainer),
1214-
ButtonState.loading:
1215-
IconedButton(
1216-
//text: S.of(context).progressButtonReplySending,
1217-
color: Theme.of(context)
1218-
.colorScheme
1219-
.secondary),
1220-
ButtonState.fail: IconedButton(
1221-
//text: S.of(context).progressButtonReplyFailed,
1222-
icon: Icon(
1223-
Icons.cancel,
1224-
color: Colors.white,
1225-
semanticLabel: S
1226-
.of(context)
1227-
.progressButtonReplyFailed,
1228-
),
1229-
color: Colors.red.shade300),
1230-
ButtonState.success: IconedButton(
1231-
//text: S.of(context).progressButtonReplySuccess,
1232-
icon: Icon(
1233-
Icons.check_circle,
1234-
color: Colors.white,
1235-
semanticLabel: S
1236-
.of(context)
1237-
.progressButtonReplySuccess,
1238-
),
1239-
color: Colors.green.shade400)
1240-
},
1205+
if(_sendReplyStatus == SendReplyStatus.idle){
1206+
return IconButton(
1207+
icon: Icon(AppPlatformIcons(context).postThreadSolid),
12411208
onPressed: () {
12421209
VibrationUtils
12431210
.vibrateWithClickIfPossible();
12441211
_sendReply(context);
12451212
},
1246-
state: _sendReplyStatus);
1213+
);
1214+
}
1215+
else if(_sendReplyStatus == SendReplyStatus.loading){
1216+
return IconButton(
1217+
icon: PlatformCircularProgressIndicator(
1218+
cupertino: (context, platform) => CupertinoProgressIndicatorData(
1219+
color: Theme.of(context).colorScheme.primary
1220+
),
1221+
material: (context, platform) => MaterialProgressIndicatorData(
1222+
color: Theme.of(context).colorScheme.primary
1223+
),
1224+
),
1225+
onPressed: (){
1226+
1227+
},
1228+
);
1229+
}
1230+
else if(_sendReplyStatus == SendReplyStatus.success){
1231+
return IconButton(icon: Icon(AppPlatformIcons(context).checkCircleSolid, color: Theme.of(context).colorScheme.primary), onPressed: (){},);
1232+
}
1233+
else if(_sendReplyStatus == SendReplyStatus.fail){
1234+
return IconButton(icon: Icon(AppPlatformIcons(context).errorOutline, color: Theme.of(context).colorScheme.error), onPressed: (){},);
1235+
}
1236+
return Container();
12471237
} else {
12481238
//return Container();
12491239
return IconButton(

0 commit comments

Comments
 (0)