From 5d4ccc6961c83c9dc6839682743197e3564e3ceb Mon Sep 17 00:00:00 2001 From: kidozh <11661760+kidozh@users.noreply.github.com> Date: Sun, 27 Oct 2024 00:40:54 +0100 Subject: [PATCH] halt network condition if no user is provided --- lib/page/DisplayForumSliverPage.dart | 40 ++++++++----- lib/page/PostThreadPage.dart | 80 +++++++++++-------------- lib/page/ViewThreadSliverPage.dart | 6 ++ lib/screen/ExtraFuncInThreadScreen.dart | 22 +++---- lib/utility/AppPlatformIcons.dart | 2 +- 5 files changed, 78 insertions(+), 72 deletions(-) diff --git a/lib/page/DisplayForumSliverPage.dart b/lib/page/DisplayForumSliverPage.dart index 305d43d..570a87a 100644 --- a/lib/page/DisplayForumSliverPage.dart +++ b/lib/page/DisplayForumSliverPage.dart @@ -160,6 +160,9 @@ class _DisplayForumSliverState extends State { DateTime.now(), discuz) ); + if(Provider.of(context, listen: false).user == null) { + return; + } client.favoriteForumActionResult(_displayForumResult.discuzIndexVariables.formHash, fid).then((value){ if(value.errorResult!= null && value.errorResult!.key == "do_success"){ EasyLoading.showSuccess(S.of(context).discuzOperationMessage(value.errorResult!.key, value.errorResult!.content)); @@ -176,6 +179,9 @@ class _DisplayForumSliverState extends State { FavoriteForumInDatabase? favoriteForumInDatabase = favoriteForumDao.getFavoriteForumByFid(fid, discuz); if(favoriteForumInDatabase!= null){ favoriteForumDao.removeFavoriteForum(favoriteForumInDatabase); + if(Provider.of(context, listen: false).user == null) { + return; + } client.unfavoriteThreadActionResult(_displayForumResult.discuzIndexVariables.formHash, favoriteForumInDatabase.favid).then((value){ if(value.errorResult!= null && value.errorResult!.key == "do_success"){ EasyLoading.showSuccess(S.of(context).discuzOperationMessage(value.errorResult!.key, value.errorResult!.content)); @@ -401,23 +407,25 @@ class _DisplayForumSliverState extends State { } }, ), - if(user != null) - IconButton( - icon: Icon(AppPlatformIcons(context).publishPostOutlined,size: 24), - onPressed: () { - if(_displayForumResult.discuzIndexVariables.forum.fid != 0){ - VibrationUtils.vibrateWithClickIfPossible(); - Navigator.push( - context, - platformPageRoute( - context: context, - builder: (context) => PostThreadPage(discuz,_displayForumResult.discuzIndexVariables.forum.fid, 0))); - } - else{ - EasyLoading.showInfo(S.of(context).loading); - } + Consumer( + builder: (context, discuzAndUser, child) => discuzAndUser.user!= null? IconButton( + icon: Icon(AppPlatformIcons(context).publishPostOutlined,size: 24), + onPressed: () { + if(_displayForumResult.discuzIndexVariables.forum.fid != 0){ + VibrationUtils.vibrateWithClickIfPossible(); + Navigator.push( + context, + platformPageRoute( + context: context, + builder: (context) => PostThreadPage(discuz,_displayForumResult.discuzIndexVariables.forum.fid, 0))); + } + else{ + EasyLoading.showInfo(S.of(context).loading); + } + + }): Container(), + ), - }), PlatformPopupMenu( icon: Icon(PlatformIcons(context).ellipsis, size: 24,), options: [ diff --git a/lib/page/PostThreadPage.dart b/lib/page/PostThreadPage.dart index 86d41d4..d1cdf15 100644 --- a/lib/page/PostThreadPage.dart +++ b/lib/page/PostThreadPage.dart @@ -95,7 +95,7 @@ class PostThreadState extends State { title: Text(S.of(context).pushThreadTitle), trailingActions: [ PlatformIconButton( - icon: Icon(AppPlatformIcons(context).postThreadSolid), + icon: Icon(AppPlatformIcons(context).postThreadSolid, size: 24,), onPressed: () async { VibrationUtils.vibrateWithClickIfPossible(); await _launchCaptchaDialog(context); @@ -229,9 +229,9 @@ class PostThreadState extends State { )); }, ), - PlatformIconButton( - icon: Icon(Icons.settings_backup_restore), - ), + // PlatformIconButton( + // icon: Icon(Icons.settings_backup_restore), + // ), ], ), ], @@ -389,50 +389,42 @@ class PostThreadState extends State { Dio dio = await NetworkUtils.getDioWithPersistCookieJar(user); // MobileApiClient client = MobileApiClient(dio, baseUrl: discuz.baseURL); - showDialog( + showPlatformDialog( context: context, builder: (context) { - return SimpleDialog( + return PlatformAlertDialog( title: Text(S.of(context).pushThreadTitle), - children: [ - Padding(padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0), - child: Column( - children: [ - CaptchaWidget( - dio, - discuz, - user, - "post", - captchaController: captchaController, - showProgress: true, - ), - SizedBox( - height: 16.0, - ), - Row( - mainAxisSize: MainAxisSize.max, - children: [ - Expanded( - child: PlatformElevatedButton( - color: Theme.of(context).primaryColor, - child: Text( - S.of(context).send, - style: TextStyle( - color: - Theme.of(context).primaryTextTheme.labelLarge?.color), - ), - onPressed: () { - VibrationUtils.vibrateWithClickIfPossible(); - postThread(); - Navigator.of(context).pop(); - }, - )), - ], - ) - ], - ), + content: Padding(padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + CaptchaWidget( + dio, + discuz, + user, + "post", + captchaController: captchaController, + showProgress: true, + ), + ], + ), + ), + actions: [ + PlatformDialogAction( + child: Text(S.of(context).send), + onPressed: () { + VibrationUtils.vibrateWithClickIfPossible(); + postThread(); + Navigator.of(context).pop(); + }, + ), + PlatformDialogAction( + child: Text(S.of(context).cancel), + onPressed: () { + VibrationUtils.vibrateWithClickIfPossible(); + Navigator.of(context).pop(); + }, ) - ], ); }); diff --git a/lib/page/ViewThreadSliverPage.dart b/lib/page/ViewThreadSliverPage.dart index 92e27d6..0698e2b 100644 --- a/lib/page/ViewThreadSliverPage.dart +++ b/lib/page/ViewThreadSliverPage.dart @@ -522,6 +522,9 @@ class _ViewThreadSliverState extends State { _viewThreadResult.threadVariables.threadInfo.replies, DateTime.now(), discuz)); + if(Provider.of(context, listen: false).user == null) { + return; + } client .favoriteThreadActionResult( _viewThreadResult.threadVariables.formHash, tid) @@ -543,6 +546,9 @@ class _ViewThreadSliverState extends State { favoriteThreadDao.getFavoriteThreadByTid(tid, discuz); if (favoriteThreadInDatabase != null) { favoriteThreadDao.removeFavoriteThread(favoriteThreadInDatabase); + if(Provider.of(context, listen: false).user == null) { + return; + } client .unfavoriteThreadActionResult( _viewThreadResult.threadVariables.formHash, diff --git a/lib/screen/ExtraFuncInThreadScreen.dart b/lib/screen/ExtraFuncInThreadScreen.dart index f87b7c7..bcd798a 100644 --- a/lib/screen/ExtraFuncInThreadScreen.dart +++ b/lib/screen/ExtraFuncInThreadScreen.dart @@ -16,6 +16,7 @@ import 'package:discuz_flutter/utility/NetworkUtils.dart'; import 'package:discuz_flutter/utility/VibrationUtils.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:flutter_html/flutter_html.dart'; import 'package:flutter_image_compress/flutter_image_compress.dart'; import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; import 'package:image_picker/image_picker.dart'; @@ -141,17 +142,16 @@ class ExtraFuncInThreadState extends State{ ), if(!file_not_exceeding_size) Container( - child: PlatformListTile( - // title: Text(S.of(context).attachmentUploadExceedingSizeTitle, - // style: TextStyle( - // color: Theme.of(context).colorScheme.onPrimary, - // fontSize: FontSize.small.value - // ), - // - // ), - title: Text(S.of(context).attachmentUploadExceedingSizeDescription, - style: TextStyle( - color: Theme.of(context).colorScheme.onPrimary, + child: Container( + + color: Theme.of(context).colorScheme.primary, + child: SizedBox( + width: double.infinity, + child: Text(S.of(context).attachmentUploadExceedingSizeDescription, + style: TextStyle( + color: Theme.of(context).colorScheme.onPrimary, + fontSize: FontSize.medium.value + ), ), ), ), diff --git a/lib/utility/AppPlatformIcons.dart b/lib/utility/AppPlatformIcons.dart index 6afcd1a..eb8fd72 100644 --- a/lib/utility/AppPlatformIcons.dart +++ b/lib/utility/AppPlatformIcons.dart @@ -75,7 +75,7 @@ class AppPlatformIcons{ IconData get goToSolid => isMaterial(context)? Icons.arrow_forward : CupertinoIcons.arrow_right; - IconData get postThreadSolid => isMaterial(context)? Icons.send : CupertinoIcons.arrowshape_turn_up_right_fill; + IconData get postThreadSolid => isMaterial(context)? Icons.send : CupertinoIcons.arrow_up_right_diamond_fill; IconData get checkCircleSolid => isMaterial(context)? Icons.check_circle : CupertinoIcons.check_mark_circled_solid;