diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 00000000..a686c1b4 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,14 @@ +# Defines a default set of lint rules enforced for +# projects at Google. For details and rationale, +# see https://github.com/dart-lang/pedantic#enabled-lints. +include: package:pedantic/analysis_options.yaml + +# For lint rules and documentation, see http://dart-lang.github.io/linter/lints. +# Uncomment to specify additional rules. +# linter: +# rules: +# - camel_case_types + +analyzer: +# exclude: +# - path/to/excluded/files/** diff --git a/lib/api/user_api.dart b/lib/api/user_api.dart index e994879b..5ba22f56 100755 --- a/lib/api/user_api.dart +++ b/lib/api/user_api.dart @@ -1,5 +1,4 @@ import 'dart:io'; -import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:extended_image/extended_image.dart'; @@ -16,12 +15,12 @@ class UserAPI { static List cookiesForJWGL; - static Future login(Map params) async { - return NetUtils.tokenDio.post(API.login, data: params); + static Future> login(Map params) async { + return NetUtils.tokenDio.post(API.login, data: params); } - static void logout(context) async { - final confirm = await ConfirmationBottomSheet.show( + static Future logout(BuildContext context) async { + final bool confirm = await ConfirmationBottomSheet.show( context, title: '退出登录', showConfirm: true, @@ -32,7 +31,7 @@ class UserAPI { } } - static UserTag createUserTag(tagData) => UserTag( + static UserTag createUserTag(Map tagData) => UserTag( id: tagData['id'], name: tagData['tagname'], ); @@ -74,13 +73,13 @@ class UserAPI { avatarLastModified = DateTime.now().millisecondsSinceEpoch; } - static Future getUserInfo({int uid}) async { + static Future getUserInfo({int uid}) async { if (uid == null) { return currentUser; } else { return NetUtils.getWithCookieAndHeaderSet( API.userInfo, - data: {'uid': uid}, + data: {'uid': uid}, ); } } @@ -124,27 +123,22 @@ class UserAPI { static Future getNotifications() async => NetUtils.getWithCookieAndHeaderSet(API.postUnread); static Future follow(int uid) async { - NetUtils.postWithCookieAndHeaderSet('${API.userRequestFollow}$uid').then((response) { - return NetUtils.postWithCookieAndHeaderSet( - API.userFollowAdd, - data: {'fid': uid, 'tagid': 0}, - ); - }).catchError((e) { - debugPrint(e.toString()); - showCenterErrorToast('关注失败,${jsonDecode(e.response.data)['msg']}'); - }); + try { + await NetUtils.postWithCookieAndHeaderSet('${API.userRequestFollow}$uid'); + await NetUtils.postWithCookieAndHeaderSet(API.userFollowAdd, data: {'fid': uid, 'tagid': 0}); + } catch (e) { + debugPrint('Failed when folloe: $e'); + } } static Future unFollow(int uid, {bool fromBlacklist = false}) async { - NetUtils.deleteWithCookieAndHeaderSet('${API.userRequestFollow}$uid').then((response) { - return NetUtils.postWithCookieAndHeaderSet( - API.userFollowDel, - data: {'fid': uid}, - ); - }).catchError((e) { + try { + await NetUtils.deleteWithCookieAndHeaderSet('${API.userRequestFollow}$uid'); + await NetUtils.postWithCookieAndHeaderSet(API.userFollowAdd, data: {'fid': uid}); + } catch (e) { debugPrint('Failed when unfollow $uid: $e'); - if (!fromBlacklist) showCenterErrorToast('取消关注失败,${e.response.data['msg']}'); - }); + if (!fromBlacklist) showCenterErrorToast('取消关注失败'); + } } static Future setSignature(content) async { diff --git a/lib/constants/constants.dart b/lib/constants/constants.dart index ce0d8187..a67c2fdb 100644 --- a/lib/constants/constants.dart +++ b/lib/constants/constants.dart @@ -8,8 +8,10 @@ import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:openjmu/constants/constants.dart'; export 'package:dartx/dartx.dart'; +export 'package:dio/dio.dart' show Response; export 'package:ff_annotation_route/ff_annotation_route.dart' show FFRoute, PageRouteType; export 'package:oktoast/oktoast.dart' hide showToast; +export 'package:pedantic/pedantic.dart'; export 'package:url_launcher/url_launcher.dart'; export 'package:openjmu/api/api.dart'; diff --git a/lib/constants/hive_boxes.dart b/lib/constants/hive_boxes.dart index 77bdb5a3..f6a0b92f 100644 --- a/lib/constants/hive_boxes.dart +++ b/lib/constants/hive_boxes.dart @@ -49,7 +49,7 @@ class HiveBoxes { changelogBox = await Hive.openBox('openjmu_changelog'); } - static void clearBoxes({context}) async { + static Future clearBoxes({context}) async { bool confirm = true; if (context != null) { confirm = await ConfirmationBottomSheet.show( @@ -72,7 +72,7 @@ class HiveBoxes { await settingsBox?.clear(); await startWeekBox?.clear(); debugPrint('Boxes cleared'); - if (kReleaseMode) SystemNavigator.pop(); + if (kReleaseMode) unawaited(SystemNavigator.pop()); } } } diff --git a/lib/controller/comment_controller.dart b/lib/controller/comment_controller.dart index 7ba999de..f273b690 100755 --- a/lib/controller/comment_controller.dart +++ b/lib/controller/comment_controller.dart @@ -317,7 +317,7 @@ class CommentListInPostState extends State with AutomaticKeep Routes.OPENJMU_ADD_COMMENT, arguments: { 'post': widget.post, - 'comment': _comments?.elementAt(index) ?? null, + 'comment': _comments?.elementAt(index), }, ); } diff --git a/lib/model/special_text.dart b/lib/model/special_text.dart index 6562c678..b03dc9c7 100755 --- a/lib/model/special_text.dart +++ b/lib/model/special_text.dart @@ -110,7 +110,9 @@ class MentionText extends SpecialText { int getUidFromContent(content) { Iterable matches = mTagStartReg.allMatches(content); String result; - for (Match m in matches) result = m.group(0); + for (Match m in matches) { + result = m.group(0); + } return int.parse(result.substring(3, result.length - 1)); } @@ -286,8 +288,8 @@ class StackSpecialTextSpanBuilder extends SpecialTextSpanBuilder { final List suffixSpans; StackSpecialTextSpanBuilder({ - this.builderType: BuilderType.extendedText, - this.widgetType: WidgetType.post, + this.builderType = BuilderType.extendedText, + this.widgetType = WidgetType.post, this.prefixSpans, this.suffixSpans, }); @@ -333,7 +335,7 @@ class StackSpecialTextSpanBuilder extends SpecialTextSpanBuilder { if (specialText != null) { if (textStack.length - specialText.startFlag.length >= 0) { textStack = textStack.substring(0, textStack.length - specialText.startFlag.length); - if (textStack.length > 0) { + if (textStack.isNotEmpty) { inlineList.add(TextSpan(text: textStack, style: textStyle)); } } @@ -346,7 +348,7 @@ class StackSpecialTextSpanBuilder extends SpecialTextSpanBuilder { text: specialText.startFlag + specialText.getContent(), style: textStyle, )); - } else if (textStack.length > 0) { + } else if (textStack.isNotEmpty) { inlineList.add(TextSpan(text: textStack, style: textStyle)); } } else { diff --git a/lib/model/user.dart b/lib/model/user.dart index adb23101..529936bf 100644 --- a/lib/model/user.dart +++ b/lib/model/user.dart @@ -34,7 +34,7 @@ class User { nickname: json['nickname'] ?? json['username'] ?? json['name'] ?? json['uid'].toString(), gender: json['gender'] ?? 0, topics: json['topics'] ?? 0, - latestTid: json['latest_tid'] ?? null, + latestTid: json['latest_tid'], fans: json['fans'] ?? 0, idols: json['idols'] ?? 0, isFollowing: json['is_following'] == 1, diff --git a/lib/pages/chat/chat_app_message_page.dart b/lib/pages/chat/chat_app_message_page.dart index c3485537..eb503948 100644 --- a/lib/pages/chat/chat_app_message_page.dart +++ b/lib/pages/chat/chat_app_message_page.dart @@ -223,7 +223,9 @@ class _ChatAppMessagePageState extends State { final content = jsonDecode(message.content); message.content = content['content']; if (mounted) setState(() {}); - } catch (e) {} + } catch (e) { + return; + } } @override diff --git a/lib/pages/chat/chat_person_page.dart b/lib/pages/chat/chat_person_page.dart index df371d4f..ebe15069 100644 --- a/lib/pages/chat/chat_person_page.dart +++ b/lib/pages/chat/chat_person_page.dart @@ -291,8 +291,8 @@ class _ChatPersonPageState extends State { } else { if (MediaQuery.of(context).viewInsets.bottom != 0.0) { SystemChannels.textInput.invokeMethod('TextInput.hide').whenComplete( - () async { - Future.delayed(const Duration(milliseconds: 300), () {}).whenComplete(change); + () { + Future.delayed(300.milliseconds, () {}).whenComplete(change); }, ); } else { diff --git a/lib/pages/home/add_button_page.dart b/lib/pages/home/add_button_page.dart index 4c6d5d90..f26b6c7d 100755 --- a/lib/pages/home/add_button_page.dart +++ b/lib/pages/home/add_button_page.dart @@ -17,10 +17,10 @@ class _AddingButtonPageState extends State with TickerProvider final List itemTitles = ['广场', '集市']; final List itemColors = [Colors.orange, Colors.indigoAccent]; final List itemOnTap = [ - (context) async { + (context) { navigatorState.pushNamed(Routes.OPENJMU_PUBLISH_POST); }, - (context) async { + (context) { navigatorState.pushNamed(Routes.OPENJMU_PUBLISH_TEAM_POST); }, ]; diff --git a/lib/pages/home/app_center_page.dart b/lib/pages/home/app_center_page.dart index a7c8f88b..bd6b4744 100644 --- a/lib/pages/home/app_center_page.dart +++ b/lib/pages/home/app_center_page.dart @@ -56,7 +56,9 @@ class AppCenterPage extends StatelessWidget { content: '是否使用浏览器打开该应用?', showConfirm: true, ); - if (confirm) launch(webApp.replacedUrl, forceSafariVC: false); + if (confirm) { + unawaited(launch(webApp.replacedUrl, forceSafariVC: false)); + } }, ); } diff --git a/lib/pages/home/course_schedule_page.dart b/lib/pages/home/course_schedule_page.dart index eee87127..473b7e5c 100755 --- a/lib/pages/home/course_schedule_page.dart +++ b/lib/pages/home/course_schedule_page.dart @@ -80,12 +80,13 @@ class CourseSchedulePageState extends State with AutomaticKe void scrollToWeek(int week) { currentWeek = week; if (mounted) setState(() {}); - if (weekScrollController?.hasClients ?? false) + if (weekScrollController?.hasClients ?? false) { weekScrollController.animateTo( math.max(0, (week - 0.5) * suSetWidth(weekSize) - Screens.width / 2), duration: const Duration(milliseconds: 300), curve: Curves.ease, ); + } } void showRemarkDetail(context) { diff --git a/lib/pages/home/post_square_list_page.dart b/lib/pages/home/post_square_list_page.dart index 0c61b893..99b705c2 100755 --- a/lib/pages/home/post_square_list_page.dart +++ b/lib/pages/home/post_square_list_page.dart @@ -114,7 +114,7 @@ class PostSquareListPageState extends State [PermissionGroup.camera], ); if (permissions[PermissionGroup.camera] == PermissionStatus.granted) { - navigatorState.pushNamed(Routes.OPENJMU_SCAN_QRCODE); + unawaited(navigatorState.pushNamed(Routes.OPENJMU_SCAN_QRCODE)); } }, ); diff --git a/lib/pages/home/scan_qrcode_page.dart b/lib/pages/home/scan_qrcode_page.dart index 1b51cbae..1fd495f4 100755 --- a/lib/pages/home/scan_qrcode_page.dart +++ b/lib/pages/home/scan_qrcode_page.dart @@ -17,15 +17,14 @@ class _ScanQrCodePageState extends State { Future onScan(context, String data) async { if (data == null) { showCenterErrorToast('没有识别到二维码~换一张试试'); - return; } if (API.urlReg.stringMatch(data) != null) { - API.launchWeb(url: '$data'); + unawaited(API.launchWeb(url: '$data')); } else if (API.schemeUserPage.stringMatch(data) != null) { - Navigator.of(context).pushReplacementNamed( + unawaited(Navigator.of(context).pushReplacementNamed( Routes.OPENJMU_USER, arguments: {'uid': int.parse(data.substring(API.schemeUserPage.pattern.length - 2))}, - ); + )); } else { final needCopy = await ConfirmationDialog.show( context, @@ -35,7 +34,9 @@ class _ScanQrCodePageState extends State { confirmLabel: '复制', cancelLabel: '返回', ); - if (needCopy) Clipboard.setData(ClipboardData(text: '$data')); + if (needCopy) { + unawaited(Clipboard.setData(ClipboardData(text: '$data'))); + } _key.currentState.startScan(); } } diff --git a/lib/pages/login_page.dart b/lib/pages/login_page.dart index 785a655c..fb4f70da 100755 --- a/lib/pages/login_page.dart +++ b/lib/pages/login_page.dart @@ -63,11 +63,11 @@ class LoginPageState extends State with SingleTickerProviderStateMixi void usernameListener() { _username = _usernameController.text; if (this.mounted) { - if (_usernameController.text.length > 0 && !_usernameCanClear) { + if (_usernameController.text.isNotEmpty && !_usernameCanClear) { setState(() { _usernameCanClear = true; }); - } else if (_usernameController.text.length == 0 && _usernameCanClear) { + } else if (_usernameController.text.isEmpty && _usernameCanClear) { setState(() { _usernameCanClear = false; }); @@ -476,11 +476,11 @@ class LoginPageState extends State with SingleTickerProviderStateMixi showConfirm: true, ); if (confirm) { - API.launchWeb( + unawaited(API.launchWeb( url: 'https://net.jmu.edu.cn/info/1309/2476.htm', title: '网页链接', withCookie: false, - ); + )); } } diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 426557d7..1830260d 100755 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -83,7 +83,7 @@ class MainPageState extends State with AutomaticKeepAliveClientMixin { super.dispose(); } - void initPushService() async { + void initPushService() { try { final data = { 'token': DeviceUtils.devicePushToken, diff --git a/lib/pages/notification/notification_entry_page.dart b/lib/pages/notification/notification_entry_page.dart index a3c0f701..435432c4 100644 --- a/lib/pages/notification/notification_entry_page.dart +++ b/lib/pages/notification/notification_entry_page.dart @@ -28,7 +28,7 @@ class _NotificationEntryPageState extends State currentContext, listen: false, ).notifications, - 'onTap': (context) async { + 'onTap': (context) { navigatorState.pushNamed(Routes.OPENJMU_NOTIFICATIONS); }, }, @@ -39,7 +39,7 @@ class _NotificationEntryPageState extends State currentContext, listen: false, ).teamNotifications, - 'onTap': (context) async { + 'onTap': (context) { navigatorState.pushNamed(Routes.OPENJMU_TEAM_NOTIFICATIONS); }, }, diff --git a/lib/pages/post/post_detail_page.dart b/lib/pages/post/post_detail_page.dart index 661fc329..4d14d2b1 100755 --- a/lib/pages/post/post_detail_page.dart +++ b/lib/pages/post/post_detail_page.dart @@ -190,7 +190,7 @@ class PostDetailPageState extends State { onPressed: () => postExtraActions(context), ); - void confirmDelete(context) async { + Future confirmDelete(context) async { final confirm = await ConfirmationDialog.show( context, title: '删除动态', @@ -205,14 +205,15 @@ class PostDetailPageState extends State { text: '正在删除动态', isGlobal: false, ); - PostAPI.deletePost(widget.post.id).then((response) { + try { + await PostAPI.deletePost(widget.post.id); _loadingDialogController.changeState('success', '动态删除成功'); Instances.eventBus.fire(PostDeletedEvent(widget.post.id, widget.fromPage, widget.index)); - }).catchError((e) { + } catch (e) { debugPrint(e.toString()); debugPrint(e.response?.toString()); _loadingDialogController.changeState('failed', '动态删除失败'); - }); + } } } @@ -254,7 +255,7 @@ class PostDetailPageState extends State { final provider = Provider.of(context, listen: false); final canReport = await provider.addRecord(widget.post.id); if (canReport) { - PostAPI.reportPost(widget.post); + unawaited(PostAPI.reportPost(widget.post)); showToast('举报成功'); navigatorState.pop(); } diff --git a/lib/pages/post/publish_post_page.dart b/lib/pages/post/publish_post_page.dart index a99f64d5..08c077ec 100755 --- a/lib/pages/post/publish_post_page.dart +++ b/lib/pages/post/publish_post_page.dart @@ -62,7 +62,7 @@ class PublishPostPageState extends State { void addTopic() { final currentPosition = _textEditingController.selection.baseOffset; String result; - if (_textEditingController.text.length > 0) { + if (_textEditingController.text.isNotEmpty) { final leftText = _textEditingController.text.substring(0, currentPosition); final rightText = _textEditingController.text .substring(currentPosition, _textEditingController.text.length); @@ -415,7 +415,7 @@ class PublishPostPageState extends State { } } - void post(context) async { + Future post(context) async { final content = _textEditingController.text; if (content?.trim()?.isEmpty ?? true) { showCenterToast('内容不能为空'); @@ -456,12 +456,12 @@ class PublishPostPageState extends State { LoadingDialog.show( context, controller: _dialogController, - text: assets.length > 0 ? '正在上传图片 (1/${assets.length})' : '正在发布动态...', + text: assets.isNotEmpty ? '正在上传图片 (1/${assets.length})' : '正在发布动态...', ); Map data = {}; data['category'] = 'text'; data['content'] = Uri.encodeFull(content); - if (assets.length > 0) { + if (assets.isNotEmpty) { try { if (query == null) query = List(assets.length); _imageIdList = List(assets.length); @@ -470,8 +470,8 @@ class PublishPostPageState extends State { final _form = await createForm(imageData); query[i] = getImageRequest(_form, i); } - _postImagesQuery().then((responses) { - final rs = responses as List; + try { + final List rs = await _postImagesQuery(); if (rs != null && rs.length == assets.length && !rs.contains(null)) { final extraId = _imageIdList.toString(); data['extra_id'] = extraId.substring(1, extraId.length - 1); @@ -482,13 +482,13 @@ class PublishPostPageState extends State { isLoading = false; if (mounted) setState(() {}); } - }).catchError((e) { + } catch (e) { query = []; _dialogController.changeState('failed', '图片上传失败'); isLoading = false; if (mounted) setState(() {}); debugPrint(e.toString()); - }); + } } catch (exception) { query = []; debugPrint(exception.toString()); @@ -544,8 +544,8 @@ class PublishPostPageState extends State { if (mounted) setState(() {}); }); - Future _postContent(content) async { - if (assets.length > 0) { + void _postContent(content) { + if (assets.isNotEmpty) { _dialogController.updateText('正在发布动态...'); } NetUtils.postWithCookieAndHeaderSet( diff --git a/lib/pages/post/publish_team_post_page.dart b/lib/pages/post/publish_team_post_page.dart index 64971c6c..da00f44d 100644 --- a/lib/pages/post/publish_team_post_page.dart +++ b/lib/pages/post/publish_team_post_page.dart @@ -66,7 +66,7 @@ class PublishTeamPostPageState extends State { void addTopic() { final currentPosition = _textEditingController.selection.baseOffset; String result; - if (_textEditingController.text.length > 0) { + if (_textEditingController.text.isNotEmpty) { final leftText = _textEditingController.text.substring(0, currentPosition); final rightText = _textEditingController.text .substring(currentPosition, _textEditingController.text.length); @@ -473,10 +473,10 @@ class PublishTeamPostPageState extends State { LoadingDialog.show( context, controller: _dialogController, - text: assets.length > 0 ? '正在上传图片 (1/${assets.length})' : '正在发布动态...', + text: assets.isNotEmpty ? '正在上传图片 (1/${assets.length})' : '正在发布动态...', ); - if (assets.length > 0) { + if (assets.isNotEmpty) { try { if (query == null) query = List(assets.length); _imageIdList = List(assets.length); @@ -485,8 +485,8 @@ class PublishTeamPostPageState extends State { final _form = await createForm(imageData); query[i] = getImageRequest(_form, i); } - _postImagesQuery().then((responses) { - final rs = responses as List; + try { + final List rs = await _postImagesQuery(); if (rs != null && rs.length == assets.length && !rs.contains(null)) { _postContent(); } else { @@ -495,13 +495,13 @@ class PublishTeamPostPageState extends State { isLoading = false; if (mounted) setState(() {}); } - }).catchError((e) { + } catch (e) { query = []; _dialogController.changeState('failed', '图片上传失败'); isLoading = false; if (mounted) setState(() {}); debugPrint(e.toString()); - }); + } } catch (exception) { query = []; debugPrint(exception.toString()); @@ -555,12 +555,12 @@ class PublishTeamPostPageState extends State { if (mounted) setState(() {}); }); - Future _postContent() async { + void _postContent() { String content = _textEditingController.text; - if (imagesLength != 0 && content == null || content.trim().length == 0) { + if (imagesLength != 0 && content == null || content.trim().isEmpty) { content = '分享图片~'; } - if (assets.length > 0) { + if (assets.isNotEmpty) { _dialogController.updateText('正在发布动态...'); } TeamPostAPI.publishPost( diff --git a/lib/pages/post/team_post_detail_page.dart b/lib/pages/post/team_post_detail_page.dart index 874f16f4..6c6ad732 100644 --- a/lib/pages/post/team_post_detail_page.dart +++ b/lib/pages/post/team_post_detail_page.dart @@ -80,18 +80,20 @@ class TeamPostDetailPageState extends State { initialLoad(); _textEditingController.addListener(() { - final _canSend = _textEditingController.text.length > 0; - if (mounted && canSend != _canSend) + final _canSend = _textEditingController.text.isNotEmpty; + if (mounted && canSend != _canSend) { setState(() { canSend = _canSend; }); + } }); _focusNode.addListener(() { - if (mounted && _focusNode.hasFocus) + if (mounted && _focusNode.hasFocus) { setState(() { showExtendedPad = false; }); + } }); Instances.eventBus @@ -378,7 +380,7 @@ class TeamPostDetailPageState extends State { await Future.delayed(const Duration(milliseconds: 100)); final currentPosition = _textEditingController.selection.baseOffset; String result; - if (_textEditingController.text.length > 0) { + if (_textEditingController.text.isNotEmpty) { final leftText = _textEditingController.text.substring(0, currentPosition); final rightText = _textEditingController.text .substring(currentPosition, _textEditingController.text.length); diff --git a/lib/pages/search_page.dart b/lib/pages/search_page.dart index ca34de41..105d1b4a 100755 --- a/lib/pages/search_page.dart +++ b/lib/pages/search_page.dart @@ -56,7 +56,7 @@ class SearchPageState extends State with AutomaticKeepAliveClientMix bool get wantKeepAlive => true; void canClearListener() { - _canClear = _controller.text.length > 0; + _canClear = _controller.text.isNotEmpty; if (mounted) setState(() {}); } @@ -81,7 +81,7 @@ class SearchPageState extends State with AutomaticKeepAliveClientMix Future getPosts(String searchQuery) async { bool loadMore = false; - if (postList != null && postList.length > 0) { + if (postList != null && postList.isNotEmpty) { loadMore = true; } await PostAPI.getPostList( @@ -92,7 +92,7 @@ class SearchPageState extends State with AutomaticKeepAliveClientMix additionAttrs: {'words': searchQuery}, ).then((response) { List _ps = response.data['topics']; - if (_ps.length == 0) _canLoadMore = false; + if (_ps.isEmpty) _canLoadMore = false; _ps.forEach((post) { Post p = Post.fromJson(post['topic']); if (postList == null) postList = []; diff --git a/lib/pages/settings/about_page.dart b/lib/pages/settings/about_page.dart index 0f1766d2..6021ee60 100755 --- a/lib/pages/settings/about_page.dart +++ b/lib/pages/settings/about_page.dart @@ -77,7 +77,7 @@ class AboutPage extends StatelessWidget { ), ); if (copy) { - Clipboard.setData(ClipboardData(text: info)); + unawaited(Clipboard.setData(ClipboardData(text: info))); showToast('已复制到剪贴板'); } } diff --git a/lib/pages/splash_page.dart b/lib/pages/splash_page.dart index 37c54e9f..b7838b9f 100755 --- a/lib/pages/splash_page.dart +++ b/lib/pages/splash_page.dart @@ -124,7 +124,7 @@ class SplashState extends State { if (mounted) setState(() {}); } - Future navigate({bool forceToLogin = false}) async { + void navigate({bool forceToLogin = false}) { try { navigatorState.pushAndRemoveUntil( PageRouteBuilder( diff --git a/lib/pages/user/backpack_page.dart b/lib/pages/user/backpack_page.dart index cd803716..f56c4408 100755 --- a/lib/pages/user/backpack_page.dart +++ b/lib/pages/user/backpack_page.dart @@ -91,9 +91,9 @@ class _BackpackPageState extends State { getBackpackItem(); } - Future getBackpackItem() async { + Future getBackpackItem() async { try { - Map types = (await NetUtils.getWithHeaderSet( + final Map types = (await NetUtils.getWithHeaderSet( API.backPackItemType(), headers: _header, )) @@ -104,7 +104,7 @@ class _BackpackPageState extends State { _itemTypes['${item.type}'] = item; } - Future.wait([ + await Future.wait([ NetUtils.getWithHeaderSet( API.backPackMyItemList(), headers: _header, @@ -121,7 +121,7 @@ class _BackpackPageState extends State { API.backPackReceiveList(), headers: _header, ).then((response) { -// print(response); +// print(response); }), ]).then((responses) { setState(() { diff --git a/lib/pages/user/user_page.dart b/lib/pages/user/user_page.dart index 99d0ae71..27c5c83b 100755 --- a/lib/pages/user/user_page.dart +++ b/lib/pages/user/user_page.dart @@ -114,7 +114,7 @@ class _UserPageState extends State } } - Future _fetchUserInformation(uid) async { + Future _fetchUserInformation(uid) async { if (uid == UserAPI.currentUser.uid) { _user = UserAPI.currentUser; } else { @@ -122,7 +122,7 @@ class _UserPageState extends State _user = UserInfo.fromJson(user); } - Future.wait([ + await Future.wait([ UserAPI.getLevel(uid).then((response) { userLevel = int.parse(response.data['score']['levelinfo']['level'].toString()); }), @@ -135,24 +135,25 @@ class _UserPageState extends State _tags = _userTags; }), _getCount(uid), - ]).then((whatever) { - if (mounted) { - setState(() { - isLoading = false; - refreshing = false; - }); - } - }); + ]); + + if (mounted) { + setState(() { + isLoading = false; + refreshing = false; + }); + } } Future _getCount(id) async { Map data = (await UserAPI.getFansAndFollowingsCount(id)).data; - if (this.mounted) + if (this.mounted) { setState(() { _user.isFollowing = data['is_following'] == 1; _fansCount = data['fans'].toString(); _idolsCount = data['idols'].toString(); }); + } } Widget avatar(context, double width) { @@ -199,6 +200,9 @@ class _UserPageState extends State UserAPI.follow(widget.uid).then((response) { _user.isFollowing = true; if (mounted) setState(() {}); + }).catchError((e) { + debugPrint('Failed when follow: $e'); + showCenterErrorToast('关注失败'); }); } } @@ -387,7 +391,7 @@ class _UserPageState extends State ), ], ), - _tags?.length != 0 + _tags?.isNotEmpty ?? false ? SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( @@ -468,7 +472,7 @@ class _UserPageState extends State ); } - void avatarExtraActions(context) async { + void avatarExtraActions(context) { ConfirmationBottomSheet.show( context, children: [ @@ -495,7 +499,7 @@ class _UserPageState extends State ConfirmationBottomSheetAction( icon: Icon(Icons.photo_library), text: '更换头像', - onTap: () async { + onTap: () { Navigator.of(context).pop(); navigatorState.pushNamed(Routes.OPENJMU_IMAGE_CROP).then((result) { if (result != null && result) { @@ -782,8 +786,10 @@ class _UserListState extends State { int total = int.parse(response.data['total'].toString()); if (_users.length + data.length < total) canLoadMore = true; List users = []; - for (int i = 0; i < data.length; i++) users.add(data[i]); - if (mounted) + for (int i = 0; i < data.length; i++) { + users.add(data[i]); + } + if (mounted) { setState(() { if (isMore) { List _u = _users; @@ -794,6 +800,7 @@ class _UserListState extends State { } isLoading = false; }); + } } Widget renderRow(context, i) { @@ -912,7 +919,7 @@ class _UserListState extends State { FixedAppBar(title: Text('$_type列表')), Expanded( child: !isLoading - ? _users.length != 0 + ? _users?.isNotEmpty ?? false ? ListView.builder( padding: EdgeInsets.zero, itemCount: (_users.length / 2).ceil(), diff --git a/lib/providers/courses_provider.dart b/lib/providers/courses_provider.dart index ac2ed307..f5970d99 100644 --- a/lib/providers/courses_provider.dart +++ b/lib/providers/courses_provider.dart @@ -119,6 +119,7 @@ class CoursesProvider extends ChangeNotifier { if (showWeek) { showWeek = false; if (Instances.appsPageStateKey.currentState?.mounted ?? false) { + // ignore: invalid_use_of_protected_member Instances.appsPageStateKey.currentState?.setState(() {}); } } @@ -133,6 +134,7 @@ class CoursesProvider extends ChangeNotifier { Instances.courseSchedulePageStateKey.currentState?.updateScrollController(); notifyListeners(); + // ignore: invalid_use_of_protected_member Instances.courseSchedulePageStateKey.currentState?.setState(() {}); } catch (e) { debugPrint('Error when updating course: $e'); diff --git a/lib/providers/date_provider.dart b/lib/providers/date_provider.dart index a78f68ba..f25d6856 100644 --- a/lib/providers/date_provider.dart +++ b/lib/providers/date_provider.dart @@ -66,9 +66,9 @@ class DateProvider extends ChangeNotifier { _day = DateTime.parse(jsonDecode(result)['start']); } if (_startDate == null) { - updateStartDate(_day); + unawaited(updateStartDate(_day)); } else { - if (_startDate != _day) updateStartDate(_day); + if (_startDate != _day) unawaited(updateStartDate(_day)); } final _d = _startDate.difference(now).inDays; diff --git a/lib/providers/themes_provider.dart b/lib/providers/themes_provider.dart index 877cdc7b..edce006b 100644 --- a/lib/providers/themes_provider.dart +++ b/lib/providers/themes_provider.dart @@ -54,7 +54,7 @@ class ThemesProvider with ChangeNotifier { _platformBrightness = HiveFieldUtils.getBrightnessPlatform(); } - Future resetTheme() async { + void resetTheme() { HiveFieldUtils.setColorTheme(0); HiveFieldUtils.setAMOLEDDark(false); HiveFieldUtils.setBrightnessDark(false); diff --git a/lib/providers/webapps_provider.dart b/lib/providers/webapps_provider.dart index 43eb9634..9ebc260b 100644 --- a/lib/providers/webapps_provider.dart +++ b/lib/providers/webapps_provider.dart @@ -20,7 +20,7 @@ class WebAppsProvider extends ChangeNotifier { Future getAppList() async => NetUtils.getWithCookieSet(API.webAppLists); - void initApps() async { + void initApps() { _appCategoriesList = >{ for (final key in categories.keys) key: {}, }; diff --git a/lib/utils/channel_utils.dart b/lib/utils/channel_utils.dart index 0f79737b..95c0e31a 100755 --- a/lib/utils/channel_utils.dart +++ b/lib/utils/channel_utils.dart @@ -4,9 +4,9 @@ import 'package:flutter/services.dart'; class ChannelUtils { const ChannelUtils._(); - static const _pmc_flagSecure = const MethodChannel('cn.edu.jmu.openjmu/setFlagSecure'); - static const _pmc_schemeLauncher = const MethodChannel('cn.edu.jmu.openjmu/schemeLauncher'); - static const _pmc_iOSPushToken = const MethodChannel('cn.edu.jmu.openjmu/iOSPushToken'); + static const _pmc_flagSecure = MethodChannel('cn.edu.jmu.openjmu/setFlagSecure'); + static const _pmc_schemeLauncher = MethodChannel('cn.edu.jmu.openjmu/schemeLauncher'); + static const _pmc_iOSPushToken = MethodChannel('cn.edu.jmu.openjmu/iOSPushToken'); static Future setFlagSecure(bool secure) async { try { diff --git a/lib/utils/data_utils.dart b/lib/utils/data_utils.dart index 7cff350b..1952f8ff 100755 --- a/lib/utils/data_utils.dart +++ b/lib/utils/data_utils.dart @@ -60,7 +60,7 @@ class DataUtils { } } - static Future logout() async { + static void logout() { UserAPI.blacklist?.clear(); MessageUtils.sendLogout(); NetUtils.postWithCookieSet(API.logout).whenComplete(() { @@ -84,7 +84,7 @@ class DataUtils { static String recoverWorkId() => settingsBox.get(spUserWorkId); - static Future recoverLoginInfo() async { + static void recoverLoginInfo() async { final info = getSpTicket(); UserAPI.currentUser.ticket = info['ticket']; } diff --git a/lib/utils/message_utils.dart b/lib/utils/message_utils.dart index 45b26bb4..90811ed1 100755 --- a/lib/utils/message_utils.dart +++ b/lib/utils/message_utils.dart @@ -239,7 +239,7 @@ class MessageUtils { try { final package = packageBuilder( Messages.messageCommands[command], - content?.requestBody() ?? null, + content?.requestBody(), ); messageSocket.add(package); debugPrint('\nSending $command: $package'); @@ -357,7 +357,9 @@ class MessageUtils { // Fire [MessageReceivedEvent]. Instances.eventBus.fire(event); // Notify each listener with event. - for (final listener in messageListeners) listener(event); + for (final listener in messageListeners) { + listener(event); + } } static decodeMultiOfflineMessage(Packet packet) { @@ -416,13 +418,17 @@ class UintConverter { final bytes = value.toUtf8(); // String package needs to add length before content. addWrapper(UintWrapper(bytes.length, 16)); - for (final byte in bytes) add(byte, 8); + for (final byte in bytes) { + add(byte, 8); + } } Uint8List asUint8List() { int size = 0; int offset = 0; - for (final number in numbers) size += number.radix ~/ 8; + for (final number in numbers) { + size += number.radix ~/ 8; + } final ByteBuffer buffer = Uint8List(size).buffer; final ByteData data = ByteData.view(buffer); diff --git a/lib/utils/net_utils.dart b/lib/utils/net_utils.dart index 46b65eac..9230a51b 100755 --- a/lib/utils/net_utils.dart +++ b/lib/utils/net_utils.dart @@ -97,12 +97,12 @@ class NetUtils { ), ); - static Future getWithCookieSet( + static Future> getWithCookieSet( String url, { data, cookies, }) async => - await dio.get( + await dio.get( url, queryParameters: data, options: Options( @@ -110,13 +110,13 @@ class NetUtils { ), ); - static Future getWithCookieAndHeaderSet( + static Future> getWithCookieAndHeaderSet( String url, { data, cookies, headers, }) async => - await dio.get( + await dio.get( url, queryParameters: data, options: Options( @@ -125,9 +125,12 @@ class NetUtils { ), ); - static Future post(String url, {data}) async => await dio.post(url, data: data); + static Future> post(String url, {data}) async => await dio.post( + url, + data: data, + ); - static Future postWithCookieSet(String url, {data}) async => await dio.post( + static Future> postWithCookieSet(String url, {data}) async => await dio.post( url, data: data, options: Options( @@ -135,13 +138,13 @@ class NetUtils { ), ); - static Future postWithCookieAndHeaderSet( + static Future> postWithCookieAndHeaderSet( String url, { cookies, headers, data, }) async => - await dio.post( + await dio.post( url, data: data, options: Options( @@ -150,12 +153,12 @@ class NetUtils { ), ); - static Future deleteWithCookieAndHeaderSet( + static Future> deleteWithCookieAndHeaderSet( String url, { data, headers, }) async => - await dio.delete( + await dio.delete( url, data: data, options: Options( diff --git a/lib/utils/ota_utils.dart b/lib/utils/ota_utils.dart index ee90dde3..9c12e8ed 100755 --- a/lib/utils/ota_utils.dart +++ b/lib/utils/ota_utils.dart @@ -28,8 +28,8 @@ class OTAUtils { _packageInfo = await PackageInfo.fromPlatform(); } - static Future checkUpdate({bool fromHome = false}) async { - NetUtils.get(API.checkUpdate).then((response) async { + static void checkUpdate({bool fromHome = false}) { + NetUtils.get(API.checkUpdate).then((response) { final data = jsonDecode(response.data); updateChangelog(data['changelog']); final _currentBuild = buildNumber; @@ -63,13 +63,13 @@ class OTAUtils { LaunchReview.launch(iOSAppId: '1459832676'); } else { if (await canLaunch('coolmarket://apk/$packageName')) { - launch('coolmarket://apk/$packageName'); + unawaited(launch('coolmarket://apk/$packageName')); } else { - launch( + unawaited(launch( 'https://www.coolapk.com/apk/$packageName', forceSafariVC: false, forceWebView: false, - ); + )); } } } @@ -197,11 +197,11 @@ class OTAUtils { final box = HiveBoxes.changelogBox; final List logs = data.map((log) => ChangeLog.fromJson(log)).toList(); if (box.values == null) { - box.addAll(logs); + await box.addAll(logs); } else { if (box.values.toString() != logs.toString()) { await box.clear(); - box.addAll(logs); + await box.addAll(logs); } } } diff --git a/lib/utils/toast_utils.dart b/lib/utils/toast_utils.dart index b7c4b7f1..edc02d96 100644 --- a/lib/utils/toast_utils.dart +++ b/lib/utils/toast_utils.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +// ignore: library_prefixes import 'package:oktoast/oktoast.dart' as OKToast; void showToast(String text) { diff --git a/lib/widgets/cards/post_card.dart b/lib/widgets/cards/post_card.dart index 27259976..ddf4f6e2 100755 --- a/lib/widgets/cards/post_card.dart +++ b/lib/widgets/cards/post_card.dart @@ -534,14 +534,15 @@ class _PostCardState extends State { text: '正在删除动态', isGlobal: false, ); - PostAPI.deletePost(widget.post.id).then((response) { + try { + await PostAPI.deletePost(widget.post.id); _loadingDialogController.changeState('success', '动态删除成功'); Instances.eventBus.fire(PostDeletedEvent(widget.post.id, widget.fromPage, widget.index)); - }).catchError((e) { + } catch (e) { debugPrint(e.toString()); debugPrint(e.response?.toString()); _loadingDialogController.changeState('failed', '动态删除失败'); - }); + } } } @@ -579,7 +580,7 @@ class _PostCardState extends State { final provider = Provider.of(context, listen: false); final canReport = await provider.addRecord(widget.post.id); if (canReport) { - PostAPI.reportPost(widget.post); + unawaited(PostAPI.reportPost(widget.post)); showToast('举报成功'); } } diff --git a/lib/widgets/cards/team_comment_preview_card.dart b/lib/widgets/cards/team_comment_preview_card.dart index 20a8bc40..6329121c 100644 --- a/lib/widgets/cards/team_comment_preview_card.dart +++ b/lib/widgets/cards/team_comment_preview_card.dart @@ -207,11 +207,9 @@ class TeamCommentPreviewCard extends StatelessWidget { shrinkWrap: true, itemCount: post.replyInfo.length + (post.replyInfo.length != post.repliesCount ? 1 : 0), itemBuilder: (_, index) { - if (index == post.replyInfo.length) + if (index == post.replyInfo.length) { return Container( - margin: EdgeInsets.only( - top: suSetHeight(12.0), - ), + margin: EdgeInsets.only(top: suSetHeight(12.0)), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -234,11 +232,10 @@ class TeamCommentPreviewCard extends StatelessWidget { ], ), ); + } final _post = post.replyInfo[index]; return Padding( - padding: EdgeInsets.symmetric( - vertical: suSetHeight(4.0), - ), + padding: EdgeInsets.symmetric(vertical: suSetHeight(4.0)), child: Row( children: [ Expanded( @@ -248,9 +245,7 @@ class TeamCommentPreviewCard extends StatelessWidget { prefixSpans: [ TextSpan( text: '@${_post['user']['nickname']}', - style: TextStyle( - color: Colors.blue, - ), + style: TextStyle(color: Colors.blue), recognizer: TapGestureRecognizer() ..onTap = () { navigatorState.pushNamed( @@ -286,9 +281,7 @@ class TeamCommentPreviewCard extends StatelessWidget { ), TextSpan( text: ': ', - style: TextStyle( - color: Colors.blue, - ), + style: TextStyle(color: Colors.blue), ), ], ), diff --git a/lib/widgets/cards/team_post_preview_card.dart b/lib/widgets/cards/team_post_preview_card.dart index a7332926..99db51b4 100644 --- a/lib/widgets/cards/team_post_preview_card.dart +++ b/lib/widgets/cards/team_post_preview_card.dart @@ -80,7 +80,7 @@ class TeamPostPreviewCard extends StatelessWidget { showConfirm: true, ); if (confirm) { - TeamPostAPI.reportPost(post); + unawaited(TeamPostAPI.reportPost(post)); showToast('举报成功'); } } @@ -186,11 +186,9 @@ class TeamPostPreviewCard extends StatelessWidget { shrinkWrap: true, itemCount: provider.post.postInfo.length + (provider.post.repliesCount > 2 ? 1 : 0), itemBuilder: (_, index) { - if (index == provider.post.postInfo.length) + if (index == provider.post.postInfo.length) { return Container( - margin: EdgeInsets.only( - top: suSetHeight(12.0), - ), + margin: EdgeInsets.only(top: suSetHeight(12.0)), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -213,6 +211,7 @@ class TeamPostPreviewCard extends StatelessWidget { ], ), ); + } final _post = provider.post.postInfo[index]; return Padding( padding: EdgeInsets.symmetric( diff --git a/lib/widgets/custom_switch.dart b/lib/widgets/custom_switch.dart index 140f4ba2..f7c7b38d 100644 --- a/lib/widgets/custom_switch.dart +++ b/lib/widgets/custom_switch.dart @@ -230,10 +230,11 @@ class _RenderCustomSwitch extends RenderConstrainedBox { _position ..curve = Curves.ease ..reverseCurve = Curves.ease.flipped; - if (value) + if (value) { _positionController.forward(); - else + } else { _positionController.reverse(); + } } TickerProvider get vsync => _vsync; @@ -300,10 +301,11 @@ class _RenderCustomSwitch extends RenderConstrainedBox { @override void attach(PipelineOwner owner) { super.attach(owner); - if (value) + if (value) { _positionController.forward(); - else + } else { _positionController.reverse(); + } if (isInteractive) { switch (_reactionController.status) { case AnimationStatus.forward: @@ -329,9 +331,11 @@ class _RenderCustomSwitch extends RenderConstrainedBox { void _handlePositionStateChanged(AnimationStatus status) { if (isInteractive) { - if (status == AnimationStatus.completed && !_value) + if (status == AnimationStatus.completed && !_value) { onChanged(true); - else if (status == AnimationStatus.dismissed && _value) onChanged(false); + } else if (status == AnimationStatus.dismissed && _value) { + onChanged(false); + } } } @@ -379,10 +383,11 @@ class _RenderCustomSwitch extends RenderConstrainedBox { } void _handleDragEnd(DragEndDetails details) { - if (_position.value >= 0.5) + if (_position.value >= 0.5) { _positionController.forward(); - else + } else { _positionController.reverse(); + } _reactionController.reverse(); } diff --git a/lib/widgets/dialogs/comment_positioned.dart b/lib/widgets/dialogs/comment_positioned.dart index 66bf3831..0ad05255 100755 --- a/lib/widgets/dialogs/comment_positioned.dart +++ b/lib/widgets/dialogs/comment_positioned.dart @@ -53,10 +53,11 @@ class CommentPositionedState extends State { @override void initState() { super.initState(); - if (widget.comment != null) + if (widget.comment != null) { setState(() { toComment = widget.comment; }); + } _commentController ..addListener(() { setState(() { @@ -133,7 +134,7 @@ class CommentPositionedState extends State { } Future _request(context) async { - if (commentContent.length <= 0 && _image == null) { + if (commentContent.isEmpty && _image == null) { showCenterErrorToast('内容不能为空!'); } else { setState(() { @@ -333,7 +334,7 @@ class CommentPositionedState extends State { color: currentThemeColor, ), ), - onTap: (_commentController.text.length > 0 || _image != null) + onTap: (_commentController.text.isNotEmpty || _image != null) ? () => _request(context) : null, ) diff --git a/lib/widgets/dialogs/confirmation_dialog.dart b/lib/widgets/dialogs/confirmation_dialog.dart index 8879f948..799a79cf 100644 --- a/lib/widgets/dialogs/confirmation_dialog.dart +++ b/lib/widgets/dialogs/confirmation_dialog.dart @@ -234,7 +234,7 @@ class RegExpSpecialTextSpanBuilder extends SpecialTextSpanBuilder { }); } - if (data.length > 0) { + if (data.isNotEmpty) { SpecialText specialText; String textStack = ''; for (int i = 0; i < data.length; i++) { @@ -253,7 +253,7 @@ class RegExpSpecialTextSpanBuilder extends SpecialTextSpanBuilder { if (specialText != null) { if (textStack.length - specialText.startFlag.length >= 0) { textStack = textStack.substring(0, textStack.length - specialText.startFlag.length); - if (textStack.length > 0) { + if (textStack.isNotEmpty) { inlineList.add(TextSpan(text: textStack, style: textStyle)); } } @@ -265,7 +265,7 @@ class RegExpSpecialTextSpanBuilder extends SpecialTextSpanBuilder { if (specialText != null) { inlineList.add( TextSpan(text: specialText.startFlag + specialText.getContent(), style: textStyle)); - } else if (textStack.length > 0) { + } else if (textStack.isNotEmpty) { inlineList.add(TextSpan(text: textStack, style: textStyle)); } } else { diff --git a/lib/widgets/dialogs/forward_positioned.dart b/lib/widgets/dialogs/forward_positioned.dart index 933b9ad7..4f549069 100755 --- a/lib/widgets/dialogs/forward_positioned.dart +++ b/lib/widgets/dialogs/forward_positioned.dart @@ -106,32 +106,29 @@ class ForwardPositionedState extends State { maxLines: 3, ); - void _request(context) async { + Future _request(context) async { setState(() { _forwarding = true; }); String content; - _forwardController.text.length == 0 ? content = '转发' : content = _forwardController.text; + _forwardController.text.isEmpty ? content = '转发' : content = _forwardController.text; /// Sending image if it exist. if (_image != null) { - Map data = (await getImageRequest(createForm(_image))).data; + final Map data = (await getImageRequest(createForm(_image))).data; _imageID = int.parse(data['image_id']); content += ' |$_imageID| '; } - PostAPI.postForward( - content, - widget.post.id, - commentAtTheMeanTime, - ).then((response) { + try { + await PostAPI.postForward(content, widget.post.id, commentAtTheMeanTime); showToast('转发成功'); Navigator.of(context).pop(); Instances.eventBus.fire(PostForwardedEvent( widget.post.id, widget.post.forwards, )); - }).catchError((e) { + } catch (e) { _forwarding = false; debugPrint('Forward post failed: $e'); if (e is DioError && e.response.statusCode == 404) { @@ -141,7 +138,7 @@ class ForwardPositionedState extends State { showToast('转发失败'); } if (mounted) setState(() {}); - }); + } } void updatePadStatus(bool active) { diff --git a/lib/widgets/dialogs/loading_dialog.dart b/lib/widgets/dialogs/loading_dialog.dart index d637d976..dc3c10d9 100755 --- a/lib/widgets/dialogs/loading_dialog.dart +++ b/lib/widgets/dialogs/loading_dialog.dart @@ -98,7 +98,9 @@ class LoadingDialogState extends State { } else { Navigator.pop(context); } - } catch (e) {} + } catch (e) { + debugPrint('Error when running pop in loading dialog: $e'); + } }); } else if (this.type == 'dismiss') { try { @@ -107,7 +109,9 @@ class LoadingDialogState extends State { } else { Navigator.pop(context); } - } catch (e) {} + } catch (e) { + debugPrint('Error when running pop in loading dialog: $e'); + } } } Widget child = Center( diff --git a/lib/widgets/fab_bottom_appbar.dart b/lib/widgets/fab_bottom_appbar.dart index 47259adf..3b8b5ff0 100755 --- a/lib/widgets/fab_bottom_appbar.dart +++ b/lib/widgets/fab_bottom_appbar.dart @@ -31,9 +31,9 @@ class FABBottomAppBar extends StatefulWidget { FABBottomAppBar({ this.items, this.centerItemText, - this.height: 64.0, - this.iconSize: 28.0, - this.itemFontSize: 18.0, + this.height = 64.0, + this.iconSize = 28.0, + this.itemFontSize = 18.0, this.backgroundColor, this.color, this.selectedColor, diff --git a/lib/widgets/image/image_crop_helper.dart b/lib/widgets/image/image_crop_helper.dart index 7e1ab838..c4d3806a 100644 --- a/lib/widgets/image/image_crop_helper.dart +++ b/lib/widgets/image/image_crop_helper.dart @@ -58,10 +58,13 @@ Future> cropImage({ExtendedImageEditorState state}) async { if (action.needCrop) option.addOption(ClipOption.fromRect(cropRect)); - if (action.needFlip) + if (action.needFlip) { option.addOption(FlipOption(horizontal: flipHorizontal, vertical: flipVertical)); + } - if (action.hasRotateAngle) option.addOption(RotateOption(rotateAngle)); + if (action.hasRotateAngle) { + option.addOption(RotateOption(rotateAngle)); + } final result = await ImageEditor.editImage( image: img, diff --git a/lib/widgets/image/image_crop_page.dart b/lib/widgets/image/image_crop_page.dart index da5d275e..42ce55b5 100755 --- a/lib/widgets/image/image_crop_page.dart +++ b/lib/widgets/image/image_crop_page.dart @@ -76,29 +76,27 @@ class _ImageCropPageState extends State { targetWidth: 640, targetHeight: 640, ); - uploadImage(context, compressedFile); + unawaited(uploadImage(context, compressedFile)); } catch (e) { debugPrint('Crop image faild: $e'); _controller.changeState('failed', '头像更新失败'); } } - Future uploadImage(context, file) async { - final formData = await createForm(file); - NetUtils.postWithCookieSet( - API.userAvatarUpload, - data: formData, - ).then((response) { + Future uploadImage(context, file) async { + try { + final formData = await createForm(file); + await NetUtils.postWithCookieSet(API.userAvatarUpload, data: formData); _controller.changeState('success', '头像更新成功'); _cropping = false; Future.delayed(Duration(milliseconds: 2200), () { Navigator.of(context).pop(true); }); - }).catchError((e) { + } catch (e) { debugPrint(e.toString()); _controller.changeState('failed', '头像更新失败'); _cropping = false; - }); + } } Future createForm(File file) async { diff --git a/lib/widgets/messages/app_message_preview_widget.dart b/lib/widgets/messages/app_message_preview_widget.dart index cedd62bb..b13db059 100644 --- a/lib/widgets/messages/app_message_preview_widget.dart +++ b/lib/widgets/messages/app_message_preview_widget.dart @@ -105,7 +105,9 @@ class _AppMessagePreviewWidgetState extends State widget.message.content = content['content']; Provider.of(currentContext, listen: false).saveAppsMessages(); if (mounted) setState(() {}); - } catch (e) {} + } catch (e) { + return; + } } @mustCallSuper diff --git a/lib/widgets/no_scale_text_widget.dart b/lib/widgets/no_scale_text_widget.dart index cc07d671..afb395c2 100755 --- a/lib/widgets/no_scale_text_widget.dart +++ b/lib/widgets/no_scale_text_widget.dart @@ -1,4 +1,4 @@ -import 'dart:math' as Math; +import 'dart:math' as math; import 'package:flutter/material.dart'; @@ -28,7 +28,7 @@ class MaxScaleTextWidget extends StatelessWidget { @override Widget build(BuildContext context) { final data = MediaQuery.of(context); - final scale = Math.min(max, data.textScaleFactor); + final scale = math.min(max, data.textScaleFactor); return MediaQuery( data: data.copyWith(textScaleFactor: scale), child: child, diff --git a/lib/widgets/rounded_check_box.dart b/lib/widgets/rounded_check_box.dart index d7decde7..245f06c5 100755 --- a/lib/widgets/rounded_check_box.dart +++ b/lib/widgets/rounded_check_box.dart @@ -362,10 +362,11 @@ class _RenderCheckbox extends RenderToggleable { _initStrokePaint(paint); final double tShrink = (t - 0.5) * 2.0; - if (_oldValue == null || value == null) + if (_oldValue == null || value == null) { _drawDash(canvas, origin, tShrink, paint); - else + } else { _drawCheck(canvas, origin, tShrink, paint); + } } } else { // Two cases: null to true, true to null @@ -376,16 +377,18 @@ class _RenderCheckbox extends RenderToggleable { _initStrokePaint(paint); if (tNormalized <= 0.5) { final double tShrink = 1.0 - tNormalized * 2.0; - if (_oldValue == true) + if (_oldValue == true) { _drawCheck(canvas, origin, tShrink, paint); - else + } else { _drawDash(canvas, origin, tShrink, paint); + } } else { final double tExpand = (tNormalized - 0.5) * 2.0; - if (value == true) + if (value == true) { _drawCheck(canvas, origin, tExpand, paint); - else + } else { _drawDash(canvas, origin, tExpand, paint); + } } } } diff --git a/lib/widgets/webview/in_app_webview.dart b/lib/widgets/webview/in_app_webview.dart index 7929bbfc..269a191b 100755 --- a/lib/widgets/webview/in_app_webview.dart +++ b/lib/widgets/webview/in_app_webview.dart @@ -97,12 +97,14 @@ class _InAppBrowserPageState extends State with AutomaticKeepA debugPrint('Found scheme when load: $url'); if (Platform.isAndroid) { Future.delayed(1.microseconds, () async { - controller.stopLoading(); + unawaited(controller.stopLoading()); debugPrint('Try to launch intent...'); final appName = await ChannelUtils.getSchemeLaunchAppName(url); if (appName != null) { final shouldLaunch = await waitForConfirmation(appName); - if (shouldLaunch) _launchURL(url: url); + if (shouldLaunch) { + await _launchURL(url: url); + } } }); } @@ -187,7 +189,7 @@ class _InAppBrowserPageState extends State with AutomaticKeepA ); } - Future showMore(context) async { + void showMore(context) { showModalBottomSheet( shape: RoundedRectangleBorder( borderRadius: BorderRadius.only(