diff --git a/lib/common/widgets/image/image_view.dart b/lib/common/widgets/image/image_view.dart index c31b1eeeb..4d7dc9e33 100644 --- a/lib/common/widgets/image/image_view.dart +++ b/lib/common/widgets/image/image_view.dart @@ -91,6 +91,31 @@ Widget imageView( }; } + void onTap(BuildContext context, int index) { + if (callback != null) { + callback(picArr.map((item) => item.url).toList(), index); + } else { + onViewImage?.call(); + context.imageView( + initialPage: index, + imgList: picArr.map( + (item) { + bool isLive = item.isLivePhoto && enableLivePhoto; + return SourceModel( + sourceType: + isLive ? SourceType.livePhoto : SourceType.networkImage, + url: item.url, + liveUrl: isLive ? item.liveUrl : null, + width: isLive ? parseSize(item.width) : null, + height: isLive ? parseSize(item.height) : null, + ); + }, + ).toList(), + onDismissed: onDismissed, + ); + } + } + return NineGridView( type: NineGridType.weiBo, margin: const EdgeInsets.only(top: 6), @@ -103,30 +128,7 @@ Widget imageView( itemBuilder: (context, index) => Hero( tag: picArr[index].url, child: GestureDetector( - onTap: () { - if (callback != null) { - callback(picArr.map((item) => item.url).toList(), index); - } else { - onViewImage?.call(); - context.imageView( - initialPage: index, - imgList: picArr.map( - (item) { - bool isLive = item.isLivePhoto && enableLivePhoto; - return SourceModel( - sourceType: - isLive ? SourceType.livePhoto : SourceType.networkImage, - url: item.url, - liveUrl: isLive ? item.liveUrl : null, - width: isLive ? parseSize(item.width) : null, - height: isLive ? parseSize(item.height) : null, - ); - }, - ).toList(), - onDismissed: onDismissed, - ); - } - }, + onTap: () => onTap(context, index), child: Stack( clipBehavior: Clip.none, alignment: Alignment.center, diff --git a/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart b/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart index 5de2fdeba..713fddfbf 100644 --- a/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart +++ b/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart @@ -110,8 +110,9 @@ class _InteractiveviewerGalleryState extends State setStatusBar(); } - if (widget.sources[currentIndex.value].sourceType == SourceType.livePhoto) { - _onPlay(currentIndex.value); + var item = widget.sources[currentIndex.value]; + if (item.sourceType == SourceType.livePhoto) { + _onPlay(item.liveUrl!); } } @@ -148,9 +149,9 @@ class _InteractiveviewerGalleryState extends State ); } } - for (int index = 0; index < widget.sources.length; index++) { - if (widget.sources[index].sourceType == SourceType.networkImage) { - CachedNetworkImageProvider(_getActualUrl(index)).evict(); + for (var item in widget.sources) { + if (item.sourceType == SourceType.networkImage) { + CachedNetworkImageProvider(_getActualUrl(item.url)).evict(); } } super.dispose(); @@ -209,10 +210,10 @@ class _InteractiveviewerGalleryState extends State } } - void _onPlay(int index) { + void _onPlay(String liveUrl) { _player ??= Player(); _videoController ??= VideoController(_player!); - _player!.open(Media(widget.sources[index].liveUrl!)); + _player!.open(Media(liveUrl)); } /// When the page view changed its page, the source will animate back into the @@ -222,8 +223,9 @@ class _InteractiveviewerGalleryState extends State void _onPageChanged(int page) { _player?.pause(); currentIndex.value = page; - if (widget.sources[page].sourceType == SourceType.livePhoto) { - _onPlay(page); + var item = widget.sources[page]; + if (item.sourceType == SourceType.livePhoto) { + _onPlay(item.liveUrl!); } widget.onPageChanged?.call(page); if (_transformationController!.value != Matrix4.identity()) { @@ -240,10 +242,10 @@ class _InteractiveviewerGalleryState extends State } } - String _getActualUrl(int index) { + String _getActualUrl(String url) { return _quality != 100 - ? Utils.thumbnailImgUrl(widget.sources[index].url, _quality) - : widget.sources[index].url.http2https; + ? Utils.thumbnailImgUrl(url, _quality) + : url.http2https; } void onClose() { @@ -287,6 +289,7 @@ class _InteractiveviewerGalleryState extends State _enablePageView ? null : const NeverScrollableScrollPhysics(), itemCount: widget.sources.length, itemBuilder: (BuildContext context, int index) { + final item = widget.sources[index]; return GestureDetector( behavior: HitTestBehavior.opaque, onTap: onClose, @@ -294,10 +297,9 @@ class _InteractiveviewerGalleryState extends State _doubleTapLocalPosition = details.localPosition; }, onDoubleTap: onDoubleTap, - onLongPress: - widget.sources[index].sourceType == SourceType.fileImage - ? null - : onLongPress, + onLongPress: item.sourceType == SourceType.fileImage + ? null + : () => onLongPress(item), child: widget.itemBuilder != null ? widget.itemBuilder!( context, @@ -305,7 +307,7 @@ class _InteractiveviewerGalleryState extends State index == currentIndex.value, _enablePageView, ) - : _itemBuilder(index), + : _itemBuilder(index, item), ); }, ), @@ -356,53 +358,40 @@ class _InteractiveviewerGalleryState extends State alignment: Alignment.centerRight, child: PopupMenuButton( itemBuilder: (context) { + final item = widget.sources[currentIndex.value]; return [ PopupMenuItem( - onTap: () => DownloadUtils.onShareImg( - widget.sources[currentIndex.value].url), + onTap: () => DownloadUtils.onShareImg(item.url), child: const Text("分享图片"), ), PopupMenuItem( - onTap: () { - Utils.copyText( - widget.sources[currentIndex.value].url); - }, + onTap: () => Utils.copyText(item.url), child: const Text("复制链接"), ), PopupMenuItem( - onTap: () { - DownloadUtils.downloadImg( - this.context, - [widget.sources[currentIndex.value].url], - ); - }, + onTap: () => DownloadUtils.downloadImg( + this.context, + [item.url], + ), child: const Text("保存图片"), ), if (widget.sources.length > 1) PopupMenuItem( - onTap: () { - DownloadUtils.downloadImg( - this.context, - widget.sources - .map((item) => item.url) - .toList(), - ); - }, + onTap: () => DownloadUtils.downloadImg( + this.context, + widget.sources.map((item) => item.url).toList(), + ), child: const Text("保存全部"), ), - if (widget.sources[currentIndex.value].sourceType == - SourceType.livePhoto) + if (item.sourceType == SourceType.livePhoto) PopupMenuItem( onTap: () { DownloadUtils.downloadLivePhoto( context: this.context, - url: widget.sources[currentIndex.value].url, - liveUrl: widget - .sources[currentIndex.value].liveUrl!, - width: - widget.sources[currentIndex.value].width!, - height: widget - .sources[currentIndex.value].height!, + url: item.url, + liveUrl: item.liveUrl!, + width: item.width!, + height: item.height!, ); }, child: const Text("保存 Live Photo"), @@ -420,25 +409,25 @@ class _InteractiveviewerGalleryState extends State ); } - Widget _itemBuilder(index) { + Widget _itemBuilder(int index, SourceModel item) { return Center( child: Hero( - tag: widget.sources[index].url, - child: switch (widget.sources[index].sourceType) { + tag: item.url, + child: switch (item.sourceType) { SourceType.fileImage => Image( filterQuality: FilterQuality.low, - image: FileImage(File(widget.sources[index].url)), + image: FileImage(File(item.url)), ), SourceType.networkImage => CachedNetworkImage( fadeInDuration: Duration.zero, fadeOutDuration: Duration.zero, - imageUrl: _getActualUrl(index), + imageUrl: _getActualUrl(item.url), placeholderFadeInDuration: Duration.zero, placeholder: (context, url) { return CachedNetworkImage( fadeInDuration: Duration.zero, fadeOutDuration: Duration.zero, - imageUrl: Utils.thumbnailImgUrl(widget.sources[index].url), + imageUrl: Utils.thumbnailImgUrl(item.url), ); }, ), @@ -502,7 +491,7 @@ class _InteractiveviewerGalleryState extends State .whenComplete(() => _onScaleChanged(targetScale)); } - void onLongPress() { + void onLongPress(SourceModel item) { showDialog( context: context, builder: (context) { @@ -514,8 +503,7 @@ class _InteractiveviewerGalleryState extends State children: [ ListTile( onTap: () { - DownloadUtils.onShareImg( - widget.sources[currentIndex.value].url); + DownloadUtils.onShareImg(item.url); Get.back(); }, dense: true, @@ -524,7 +512,7 @@ class _InteractiveviewerGalleryState extends State ListTile( onTap: () { Get.back(); - Utils.copyText(widget.sources[currentIndex.value].url); + Utils.copyText(item.url); }, dense: true, title: const Text('复制链接', style: TextStyle(fontSize: 14)), @@ -534,7 +522,7 @@ class _InteractiveviewerGalleryState extends State Get.back(); DownloadUtils.downloadImg( this.context, - [widget.sources[currentIndex.value].url], + [item.url], ); }, dense: true, @@ -552,17 +540,16 @@ class _InteractiveviewerGalleryState extends State dense: true, title: const Text('保存全部图片', style: TextStyle(fontSize: 14)), ), - if (widget.sources[currentIndex.value].sourceType == - SourceType.livePhoto) + if (item.sourceType == SourceType.livePhoto) ListTile( onTap: () { Get.back(); DownloadUtils.downloadLivePhoto( context: this.context, - url: widget.sources[currentIndex.value].url, - liveUrl: widget.sources[currentIndex.value].liveUrl!, - width: widget.sources[currentIndex.value].width!, - height: widget.sources[currentIndex.value].height!, + url: item.url, + liveUrl: item.liveUrl!, + width: item.width!, + height: item.height!, ); }, dense: true, diff --git a/lib/common/widgets/pendant_avatar.dart b/lib/common/widgets/pendant_avatar.dart index 2e3b8add6..493c8652e 100644 --- a/lib/common/widgets/pendant_avatar.dart +++ b/lib/common/widgets/pendant_avatar.dart @@ -70,9 +70,7 @@ class PendantAvatar extends StatelessWidget { Positioned( bottom: 0, child: InkWell( - onTap: () { - Get.toNamed('/liveRoom?roomid=$roomId'); - }, + onTap: () => Get.toNamed('/liveRoom?roomid=$roomId'), child: Container( padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1), decoration: BoxDecoration( diff --git a/lib/common/widgets/refresh_indicator.dart b/lib/common/widgets/refresh_indicator.dart index 6009bddf3..266ee6505 100644 --- a/lib/common/widgets/refresh_indicator.dart +++ b/lib/common/widgets/refresh_indicator.dart @@ -593,7 +593,7 @@ class RefreshIndicatorState extends State _positionController .animateTo(1.0 / _kDragSizeFactorLimit, duration: _kIndicatorSnapDuration) - .then((void value) { + .whenComplete(() { if (mounted && _status == RefreshIndicatorStatus.snap) { setState(() { // Show the indeterminate progress indicator. diff --git a/lib/common/widgets/video_popup_menu.dart b/lib/common/widgets/video_popup_menu.dart index d5451172c..e9f48230c 100644 --- a/lib/common/widgets/video_popup_menu.dart +++ b/lib/common/widgets/video_popup_menu.dart @@ -40,9 +40,7 @@ class VideoCustomActions { Icon(MdiIcons.circleOutline, size: 16), ], ), - () { - Utils.copyText(videoItem.bvid!); - }, + () => Utils.copyText(videoItem.bvid!), ), VideoCustomAction( '稍后再看', @@ -59,11 +57,9 @@ class VideoCustomActions { '访问:${videoItem.owner.name}', 'visit', const Icon(MdiIcons.accountCircleOutline, size: 16), - () { - Get.toNamed('/member?mid=${videoItem.owner.mid}', arguments: { - 'heroTag': '${videoItem.owner.mid}', - }); - }, + () => Get.toNamed('/member?mid=${videoItem.owner.mid}', arguments: { + 'heroTag': '${videoItem.owner.mid}', + }), ), if (videoItem is! SpaceArchiveItem) VideoCustomAction( @@ -234,42 +230,40 @@ class VideoCustomActions { '拉黑:${videoItem.owner.name}', 'block', const Icon(MdiIcons.cancel, size: 16), - () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('提示'), - content: Text( - '确定拉黑:${videoItem.owner.name}(${videoItem.owner.mid})?' - '\n\n注:被拉黑的Up可以在隐私设置-黑名单管理中解除'), - actions: [ - TextButton( - onPressed: () => Get.back(), - child: Text( - '点错了', - style: TextStyle( - color: Theme.of(context).colorScheme.outline), - ), + () => showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text('提示'), + content: + Text('确定拉黑:${videoItem.owner.name}(${videoItem.owner.mid})?' + '\n\n注:被拉黑的Up可以在隐私设置-黑名单管理中解除'), + actions: [ + TextButton( + onPressed: Get.back, + child: Text( + '点错了', + style: TextStyle( + color: Theme.of(context).colorScheme.outline), ), - TextButton( - onPressed: () async { - var res = await VideoHttp.relationMod( - mid: videoItem.owner.mid!, - act: 5, - reSrc: 11, - ); - GStorage.setBlackMid(videoItem.owner.mid!); - Get.back(); - SmartDialog.showToast(res['msg'] ?? '成功'); - }, - child: const Text('确认'), - ) - ], - ); - }, - ); - }, + ), + TextButton( + onPressed: () async { + var res = await VideoHttp.relationMod( + mid: videoItem.owner.mid!, + act: 5, + reSrc: 11, + ); + GStorage.setBlackMid(videoItem.owner.mid!); + Get.back(); + SmartDialog.showToast(res['msg'] ?? '成功'); + }, + child: const Text('确认'), + ) + ], + ); + }, + ), ), VideoCustomAction( "${MineController.anonymity.value ? '退出' : '进入'}无痕模式", diff --git a/lib/pages/about/view.dart b/lib/pages/about/view.dart index 6505f5369..51a9dbe67 100644 --- a/lib/pages/about/view.dart +++ b/lib/pages/about/view.dart @@ -155,9 +155,7 @@ Commit Hash: ${BuildConfig.commitHash}''', ), if (Platform.isAndroid) ListTile( - onTap: () { - Utils.channel.invokeMethod('linkVerifySettings'); - }, + onTap: () => Utils.channel.invokeMethod('linkVerifySettings'), leading: const Icon(MdiIcons.linkBoxOutline), title: const Text('打开受支持的链接'), trailing: Icon( @@ -167,9 +165,7 @@ Commit Hash: ${BuildConfig.commitHash}''', ), ), ListTile( - onTap: () { - PageUtils.launchURL('$_sourceCodeUrl/issues'); - }, + onTap: () => PageUtils.launchURL('$_sourceCodeUrl/issues'), leading: const Icon(Icons.feedback_outlined), title: const Text('问题反馈'), trailing: Icon( @@ -179,9 +175,7 @@ Commit Hash: ${BuildConfig.commitHash}''', ), ), ListTile( - onTap: () { - Get.toNamed('/logs'); - }, + onTap: () => Get.toNamed('/logs'), onLongPress: clearLogs, leading: const Icon(Icons.bug_report_outlined), title: const Text('错误日志'), @@ -189,25 +183,23 @@ Commit Hash: ${BuildConfig.commitHash}''', trailing: Icon(Icons.arrow_forward, size: 16, color: outline), ), ListTile( - onTap: () { - showConfirmDialog( - context: context, - title: '提示', - content: '该操作将清除图片及网络请求缓存数据,确认清除?', - onConfirm: () async { - SmartDialog.showLoading(msg: '正在清除...'); - try { - await CacheManage.clearLibraryCache(); - SmartDialog.showToast('清除成功'); - } catch (err) { - SmartDialog.showToast(err.toString()); - } finally { - SmartDialog.dismiss(); - } - getCacheSize(); - }, - ); - }, + onTap: () => showConfirmDialog( + context: context, + title: '提示', + content: '该操作将清除图片及网络请求缓存数据,确认清除?', + onConfirm: () async { + SmartDialog.showLoading(msg: '正在清除...'); + try { + await CacheManage.clearLibraryCache(); + SmartDialog.showToast('清除成功'); + } catch (err) { + SmartDialog.showToast(err.toString()); + } finally { + SmartDialog.dismiss(); + } + getCacheSize(); + }, + ), leading: const Icon(Icons.delete_outline), title: const Text('清除缓存'), subtitle: Obx( @@ -220,28 +212,109 @@ Commit Hash: ${BuildConfig.commitHash}''', ListTile( title: const Text('导入/导出登录信息'), leading: const Icon(Icons.import_export_outlined), - onTap: () { - showDialog( - context: context, - builder: (context) => SimpleDialog( - title: const Text('导入/导出登录信息'), + onTap: () => showDialog( + context: context, + builder: (context) => SimpleDialog( + title: const Text('导入/导出登录信息'), + clipBehavior: Clip.hardEdge, + children: [ + ListTile( + title: const Text('导出'), + onTap: () { + Get.back(); + String res = jsonEncode(Accounts.account.toMap()); + Utils.copyText(res); + }, + ), + ListTile( + title: const Text('导入'), + onTap: () async { + Get.back(); + ClipboardData? data = + await Clipboard.getData('text/plain'); + if (data?.text?.isNotEmpty != true) { + SmartDialog.showToast('剪贴板无数据'); + return; + } + if (!context.mounted) return; + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text('是否导入以下登录信息?'), + content: SingleChildScrollView( + child: Text(data!.text!), + ), + actions: [ + TextButton( + onPressed: Get.back, + child: Text( + '取消', + style: TextStyle(color: outline), + ), + ), + TextButton( + onPressed: () { + Get.back(); + try { + final res = (jsonDecode(data.text!) as Map) + .map((key, value) => MapEntry( + key, LoginAccount.fromJson(value))); + Accounts.account + .putAll(res) + .whenComplete(() => Accounts.refresh()) + .whenComplete(() { + MineController.anonymity.value = + !Accounts.get(AccountType.heartbeat) + .isLogin; + if (Accounts.main.isLogin) { + return LoginUtils.onLoginMain(); + } + }); + } catch (e) { + SmartDialog.showToast('导入失败:$e'); + } + }, + child: const Text('确定'), + ), + ], + ); + }, + ); + }, + ), + ], + ), + ), + ), + ListTile( + title: const Text('导入/导出设置'), + dense: false, + leading: const Icon(Icons.import_export_outlined), + onTap: () => showDialog( + context: context, + builder: (context) { + return SimpleDialog( clipBehavior: Clip.hardEdge, + title: const Text('导入/导出设置'), children: [ ListTile( - title: const Text('导出'), + title: const Text('导出设置至剪贴板'), onTap: () { Get.back(); - String res = jsonEncode(Accounts.account.toMap()); - Utils.copyText(res); + String data = GStorage.exportAllSettings(); + Utils.copyText(data); }, ), ListTile( - title: const Text('导入'), + title: const Text('从剪贴板导入设置'), onTap: () async { Get.back(); ClipboardData? data = await Clipboard.getData('text/plain'); - if (data?.text?.isNotEmpty != true) { + if (data == null || + data.text == null || + data.text!.isEmpty) { SmartDialog.showToast('剪贴板无数据'); return; } @@ -250,9 +323,9 @@ Commit Hash: ${BuildConfig.commitHash}''', context: context, builder: (context) { return AlertDialog( - title: const Text('是否导入以下登录信息?'), + title: const Text('是否导入如下设置?'), content: SingleChildScrollView( - child: Text(data!.text!), + child: Text(data.text!), ), actions: [ TextButton( @@ -263,24 +336,12 @@ Commit Hash: ${BuildConfig.commitHash}''', ), ), TextButton( - onPressed: () { + onPressed: () async { Get.back(); try { - final res = (jsonDecode(data.text!) - as Map) - .map((key, value) => MapEntry(key, - LoginAccount.fromJson(value))); - Accounts.account - .putAll(res) - .then((_) => Accounts.refresh()) - .then((_) { - MineController.anonymity.value = - !Accounts.get(AccountType.heartbeat) - .isLogin; - if (Accounts.main.isLogin) { - return LoginUtils.onLoginMain(); - } - }); + await GStorage.importAllSettings( + data.text!); + SmartDialog.showToast('导入成功'); } catch (e) { SmartDialog.showToast('导入失败:$e'); } @@ -294,132 +355,54 @@ Commit Hash: ${BuildConfig.commitHash}''', }, ), ], - ), - ); - }, - ), - ListTile( - title: const Text('导入/导出设置'), - dense: false, - leading: const Icon(Icons.import_export_outlined), - onTap: () { - showDialog( - context: context, - builder: (context) { - return SimpleDialog( - clipBehavior: Clip.hardEdge, - title: const Text('导入/导出设置'), - children: [ - ListTile( - title: const Text('导出设置至剪贴板'), - onTap: () { - Get.back(); - String data = GStorage.exportAllSettings(); - Utils.copyText(data); - }, - ), - ListTile( - title: const Text('从剪贴板导入设置'), - onTap: () async { - Get.back(); - ClipboardData? data = - await Clipboard.getData('text/plain'); - if (data == null || - data.text == null || - data.text!.isEmpty) { - SmartDialog.showToast('剪贴板无数据'); - return; - } - if (!context.mounted) return; - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('是否导入如下设置?'), - content: SingleChildScrollView( - child: Text(data.text!), - ), - actions: [ - TextButton( - onPressed: Get.back, - child: Text( - '取消', - style: TextStyle(color: outline), - ), - ), - TextButton( - onPressed: () async { - Get.back(); - try { - await GStorage.importAllSettings( - data.text!); - SmartDialog.showToast('导入成功'); - } catch (e) { - SmartDialog.showToast('导入失败:$e'); - } - }, - child: const Text('确定'), - ), - ], - ); - }, - ); - }, - ), - ], - ); - }, - ); - }, + ); + }, + ), ), ListTile( title: const Text('重置所有设置'), leading: const Icon(Icons.settings_backup_restore_outlined), - onTap: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('重置所有设置'), - content: const Text('是否重置所有设置?'), - actions: [ - TextButton( - onPressed: () { - Get.back(); - }, - child: const Text('取消'), - ), - TextButton( - onPressed: () async { - Get.back(); - await Future.wait([ - GStorage.setting.clear(), - GStorage.video.clear(), - ]); - SmartDialog.showToast('重置成功'); - }, - child: const Text('重置可导出的设置'), - ), - TextButton( - onPressed: () async { - Get.back(); - await Future.wait([ - GStorage.userInfo.clear(), - GStorage.setting.clear(), - GStorage.localCache.clear(), - GStorage.video.clear(), - GStorage.historyWord.clear(), - Accounts.clear(), - ]); - SmartDialog.showToast('重置成功'); - }, - child: const Text('重置所有数据(含登录信息)'), - ), - ], - ); - }, - ); - }, + onTap: () => showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text('重置所有设置'), + content: const Text('是否重置所有设置?'), + actions: [ + TextButton( + onPressed: Get.back, + child: const Text('取消'), + ), + TextButton( + onPressed: () async { + Get.back(); + await Future.wait([ + GStorage.setting.clear(), + GStorage.video.clear(), + ]); + SmartDialog.showToast('重置成功'); + }, + child: const Text('重置可导出的设置'), + ), + TextButton( + onPressed: () async { + Get.back(); + await Future.wait([ + GStorage.userInfo.clear(), + GStorage.setting.clear(), + GStorage.localCache.clear(), + GStorage.video.clear(), + GStorage.historyWord.clear(), + Accounts.clear(), + ]); + SmartDialog.showToast('重置成功'); + }, + child: const Text('重置所有数据(含登录信息)'), + ), + ], + ); + }, + ), ), const SizedBox(height: 80), ], diff --git a/lib/pages/article/view.dart b/lib/pages/article/view.dart index 16226bc3c..acb12c23e 100644 --- a/lib/pages/article/view.dart +++ b/lib/pages/article/view.dart @@ -447,15 +447,13 @@ class _ArticlePageState extends State final pic = pics[index]; return GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - context.imageView( - imgList: pics - .map((e) => - SourceModel(url: e.url!)) - .toList(), - initialPage: index, - ); - }, + onTap: () => context.imageView( + imgList: pics + .map( + (e) => SourceModel(url: e.url!)) + .toList(), + initialPage: index, + ), child: Hero( tag: pic.url!, child: Stack( @@ -602,13 +600,11 @@ class _ArticlePageState extends State replyLevel: '1', replyReply: (replyItem, id) => replyReply(context, replyItem, id), - onReply: () { - _articleCtr.onReply( - context, - replyItem: response[index], - index: index, - ); - }, + onReply: () => _articleCtr.onReply( + context, + replyItem: response[index], + index: index, + ), onDelete: (subIndex) => _articleCtr.onRemove(index, subIndex), upMid: _articleCtr.upMid, @@ -680,41 +676,39 @@ class _ArticlePageState extends State if (context.orientation == Orientation.landscape) IconButton( tooltip: '页面比例调节', - onPressed: () { - showDialog( - context: context, - builder: (context) => Align( - alignment: Alignment.topRight, - child: Container( - margin: const EdgeInsets.only( - top: 56, - right: 16, - ), - width: context.width / 4, - height: 32, - child: Builder( - builder: (context) => Slider( - min: 1, - max: 100, - value: _ratio.first, - onChanged: (value) { - if (value >= 10 && value <= 90) { - _ratio[0] = value; - _ratio[1] = 100 - value; - GStorage.setting.put( - SettingBoxKey.dynamicDetailRatio, - _ratio, - ); - (context as Element).markNeedsBuild(); - setState(() {}); - } - }, - ), + onPressed: () => showDialog( + context: context, + builder: (context) => Align( + alignment: Alignment.topRight, + child: Container( + margin: const EdgeInsets.only( + top: 56, + right: 16, + ), + width: context.width / 4, + height: 32, + child: Builder( + builder: (context) => Slider( + min: 1, + max: 100, + value: _ratio.first, + onChanged: (value) { + if (value >= 10 && value <= 90) { + _ratio[0] = value; + _ratio[1] = 100 - value; + GStorage.setting.put( + SettingBoxKey.dynamicDetailRatio, + _ratio, + ); + (context as Element).markNeedsBuild(); + setState(() {}); + } + }, ), ), ), - ); - }, + ), + ), icon: Transform.rotate( angle: pi / 2, child: const Icon(Icons.splitscreen, size: 19), @@ -722,9 +716,7 @@ class _ArticlePageState extends State ), IconButton( tooltip: '浏览器打开', - onPressed: () { - PageUtils.inAppWebview(_articleCtr.url); - }, + onPressed: () => PageUtils.inAppWebview(_articleCtr.url), icon: const Icon(Icons.open_in_browser_outlined, size: 19), ), PopupMenuButton( diff --git a/lib/pages/article/widgets/opus_content.dart b/lib/pages/article/widgets/opus_content.dart index c7ef6ebd0..5b58aef96 100644 --- a/lib/pages/article/widgets/opus_content.dart +++ b/lib/pages/article/widgets/opus_content.dart @@ -737,12 +737,10 @@ Widget opusCollection(ThemeData theme, ModuleCollection item) { color: theme.colorScheme.onInverseSurface, child: InkWell( borderRadius: const BorderRadius.all(Radius.circular(8)), - onTap: () { - Get.toNamed( - '/articleList', - parameters: {'id': '${item.id}'}, - ); - }, + onTap: () => Get.toNamed( + '/articleList', + parameters: {'id': '${item.id}'}, + ), child: Padding( padding: const EdgeInsets.all(10), child: Row( diff --git a/lib/pages/article_list/view.dart b/lib/pages/article_list/view.dart index 5f84bec44..b23703157 100644 --- a/lib/pages/article_list/view.dart +++ b/lib/pages/article_list/view.dart @@ -142,9 +142,8 @@ class _ArticleListPageState extends State { if (_controller.author != null) ...[ const SizedBox(height: 10), GestureDetector( - onTap: () { - Get.toNamed('/member?mid=${_controller.author!.mid}'); - }, + onTap: () => + Get.toNamed('/member?mid=${_controller.author!.mid}'), child: Row( children: [ NetworkImgLayer( @@ -193,10 +192,8 @@ class _ArticleListPageState extends State { actions: [ IconButton( tooltip: '浏览器打开', - onPressed: () { - PageUtils.inAppWebview( - '${HttpString.baseUrl}/read/mobile-readlist/rl${_controller.id}'); - }, + onPressed: () => PageUtils.inAppWebview( + '${HttpString.baseUrl}/read/mobile-readlist/rl${_controller.id}'), icon: const Icon(Icons.open_in_browser_outlined, size: 19), ) ], diff --git a/lib/pages/bangumi/view.dart b/lib/pages/bangumi/view.dart index 453f6574e..bbc2247cf 100644 --- a/lib/pages/bangumi/view.dart +++ b/lib/pages/bangumi/view.dart @@ -363,12 +363,10 @@ class _BangumiPageState extends CommonPageState const Spacer(), IconButton( tooltip: '刷新', - onPressed: () { - controller - ..followPage = 1 - ..followEnd = false - ..queryBangumiFollow(); - }, + onPressed: () => controller + ..followPage = 1 + ..followEnd = false + ..queryBangumiFollow(), icon: const Icon( Icons.refresh, size: 20, @@ -380,14 +378,12 @@ class _BangumiPageState extends CommonPageState padding: const EdgeInsets.symmetric(horizontal: 10), child: GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - Get.toNamed( - '/fav', - arguments: widget.tabType == HomeTabType.bangumi - ? FavTabType.bangumi.index - : FavTabType.cinema.index, - ); - }, + onTap: () => Get.toNamed( + '/fav', + arguments: widget.tabType == HomeTabType.bangumi + ? FavTabType.bangumi.index + : FavTabType.cinema.index, + ), child: Padding( padding: const EdgeInsets.symmetric(vertical: 8), child: Row( diff --git a/lib/pages/bangumi/widgets/bangumi_card_v.dart b/lib/pages/bangumi/widgets/bangumi_card_v.dart index 8cf8fb921..d1b1e0536 100644 --- a/lib/pages/bangumi/widgets/bangumi_card_v.dart +++ b/lib/pages/bangumi/widgets/bangumi_card_v.dart @@ -26,10 +26,7 @@ class BangumiCardV extends StatelessWidget { title: bangumiItem.title, cover: bangumiItem.cover, ), - onTap: () { - final int seasonId = bangumiItem.seasonId; - PageUtils.viewBangumi(seasonId: seasonId); - }, + onTap: () => PageUtils.viewBangumi(seasonId: bangumiItem.seasonId), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/pages/bangumi/widgets/bangumi_card_v_member_home.dart b/lib/pages/bangumi/widgets/bangumi_card_v_member_home.dart index 2a286bd82..d08a91600 100644 --- a/lib/pages/bangumi/widgets/bangumi_card_v_member_home.dart +++ b/lib/pages/bangumi/widgets/bangumi_card_v_member_home.dart @@ -21,10 +21,7 @@ class BangumiCardVMemberHome extends StatelessWidget { clipBehavior: Clip.hardEdge, margin: EdgeInsets.zero, child: InkWell( - onTap: () { - final int seasonId = int.tryParse(bangumiItem.param ?? '') ?? -1; - PageUtils.viewBangumi(seasonId: seasonId); - }, + onTap: () => PageUtils.viewBangumi(seasonId: bangumiItem.param), onLongPress: () => imageSaveDialog( title: bangumiItem.title, cover: bangumiItem.cover, diff --git a/lib/pages/bangumi/widgets/bangumi_card_v_pgc_index.dart b/lib/pages/bangumi/widgets/bangumi_card_v_pgc_index.dart index a0b8c83cd..768cf6200 100644 --- a/lib/pages/bangumi/widgets/bangumi_card_v_pgc_index.dart +++ b/lib/pages/bangumi/widgets/bangumi_card_v_pgc_index.dart @@ -24,9 +24,7 @@ class BangumiCardVPgcIndex extends StatelessWidget { title: bangumiItem['title'], cover: bangumiItem['cover'], ), - onTap: () { - PageUtils.viewBangumi(seasonId: bangumiItem['season_id']); - }, + onTap: () => PageUtils.viewBangumi(seasonId: bangumiItem['season_id']), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/pages/bangumi/widgets/bangumi_card_v_search.dart b/lib/pages/bangumi/widgets/bangumi_card_v_search.dart index 6a7a7f9b5..f17d7bf44 100644 --- a/lib/pages/bangumi/widgets/bangumi_card_v_search.dart +++ b/lib/pages/bangumi/widgets/bangumi_card_v_search.dart @@ -24,9 +24,7 @@ class BangumiCardVSearch extends StatelessWidget { title: item.title?.map((e) => e['text']).join(), cover: item.cover, ), - onTap: () { - PageUtils.viewBangumi(seasonId: item.seasonId); - }, + onTap: () => PageUtils.viewBangumi(seasonId: item.seasonId), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/pages/bangumi/widgets/bangumi_card_v_timeline.dart b/lib/pages/bangumi/widgets/bangumi_card_v_timeline.dart index 45019f70d..27db40fa0 100644 --- a/lib/pages/bangumi/widgets/bangumi_card_v_timeline.dart +++ b/lib/pages/bangumi/widgets/bangumi_card_v_timeline.dart @@ -25,9 +25,8 @@ class BangumiCardVTimeline extends StatelessWidget { title: item.title, cover: item.cover, ), - onTap: () { - PageUtils.viewBangumi(seasonId: item.seasonId, epId: item.episodeId); - }, + onTap: () => PageUtils.viewBangumi( + seasonId: item.seasonId, epId: item.episodeId), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/pages/blacklist/view.dart b/lib/pages/blacklist/view.dart index 041e355ef..9d1d78936 100644 --- a/lib/pages/blacklist/view.dart +++ b/lib/pages/blacklist/view.dart @@ -75,9 +75,7 @@ class _BlackListPageState extends State { } final item = response[index]; return ListTile( - onTap: () { - Get.toNamed('/member?mid=${item.mid}'); - }, + onTap: () => Get.toNamed('/member?mid=${item.mid}'), leading: NetworkImgLayer( width: 45, height: 45, diff --git a/lib/pages/common/common_publish_page.dart b/lib/pages/common/common_publish_page.dart index e231d9566..f81baaf2b 100644 --- a/lib/pages/common/common_publish_page.dart +++ b/lib/pages/common/common_publish_page.dart @@ -60,7 +60,7 @@ abstract class CommonPublishPageState } if (widget.autofocus) { - Future.delayed(const Duration(milliseconds: 300)).then((_) { + Future.delayed(const Duration(milliseconds: 300)).whenComplete(() { if (mounted) { focusNode.requestFocus(); } @@ -319,9 +319,7 @@ abstract class CommonPublishPageState child: iconButton( context: context, icon: Icons.edit, - onPressed: () { - onCropImage(index); - }, + onPressed: () => onCropImage(index), size: 24, iconSize: 14, bgColor: color, diff --git a/lib/pages/common/common_search_page.dart b/lib/pages/common/common_search_page.dart index e488af865..43c44c45b 100644 --- a/lib/pages/common/common_search_page.dart +++ b/lib/pages/common/common_search_page.dart @@ -37,12 +37,10 @@ abstract class CommonSearchPageState suffixIcon: IconButton( tooltip: '清空', icon: const Icon(Icons.clear, size: 22), - onPressed: () { - controller - ..loadingState.value = LoadingState.loading() - ..onClear() - ..focusNode.requestFocus(); - }, + onPressed: () => controller + ..loadingState.value = LoadingState.loading() + ..onClear() + ..focusNode.requestFocus(), ), ), onSubmitted: (value) => controller.onRefresh(), diff --git a/lib/pages/danmaku_block/view.dart b/lib/pages/danmaku_block/view.dart index 18e2a917e..42a4076c7 100644 --- a/lib/pages/danmaku_block/view.dart +++ b/lib/pages/danmaku_block/view.dart @@ -116,9 +116,8 @@ class _DanmakuBlockPageState extends State { ], ), floatingActionButton: FloatingActionButton( - onPressed: () { - _showAddDialog(_danmakuBlockController.tabController.index); - }, + onPressed: () => + _showAddDialog(_danmakuBlockController.tabController.index), child: const Icon(Icons.add), ), ); @@ -131,14 +130,16 @@ class _DanmakuBlockPageState extends State { padding: const EdgeInsets.only(bottom: 100), itemBuilder: (BuildContext context, int listIndex) { return ListTile( - title: Text( - list[listIndex].value, - style: Theme.of(context).textTheme.bodyMedium, - ), - trailing: IconButton( - icon: const Icon(Icons.delete), - onPressed: () => _danmakuBlockController.danmakuFilterDel( - tabIndex, list[listIndex].key))); + title: Text( + list[listIndex].value, + style: Theme.of(context).textTheme.bodyMedium, + ), + trailing: IconButton( + icon: const Icon(Icons.delete), + onPressed: () => _danmakuBlockController.danmakuFilterDel( + tabIndex, list[listIndex].key), + ), + ); }, ); } diff --git a/lib/pages/dynamics/view.dart b/lib/pages/dynamics/view.dart index 4e52feb73..32871b16c 100644 --- a/lib/pages/dynamics/view.dart +++ b/lib/pages/dynamics/view.dart @@ -100,9 +100,7 @@ class _DynamicsPageState extends State return Center( child: IconButton( icon: const Icon(Icons.refresh), - onPressed: () { - _dynamicsController.queryFollowUp(); - }, + onPressed: _dynamicsController.queryFollowUp, ), ); } else { diff --git a/lib/pages/dynamics/widgets/action_panel.dart b/lib/pages/dynamics/widgets/action_panel.dart index 406688982..472cb018d 100644 --- a/lib/pages/dynamics/widgets/action_panel.dart +++ b/lib/pages/dynamics/widgets/action_panel.dart @@ -68,22 +68,20 @@ class _ActionPanelState extends State { Expanded( flex: 1, child: TextButton.icon( - onPressed: () { - showModalBottomSheet( - context: context, - isScrollControlled: true, - useSafeArea: true, - builder: (context) => RepostPanel( - item: widget.item, - callback: () { - int count = - widget.item.modules.moduleStat?.forward?.count ?? 0; - widget.item.modules.moduleStat!.forward!.count = count + 1; - setState(() {}); - }, - ), - ); - }, + onPressed: () => showModalBottomSheet( + context: context, + isScrollControlled: true, + useSafeArea: true, + builder: (context) => RepostPanel( + item: widget.item, + callback: () { + int count = + widget.item.modules.moduleStat?.forward?.count ?? 0; + widget.item.modules.moduleStat!.forward!.count = count + 1; + setState(() {}); + }, + ), + ), icon: Icon( FontAwesomeIcons.shareFromSquare, size: 16, diff --git a/lib/pages/dynamics/widgets/additional_panel.dart b/lib/pages/dynamics/widgets/additional_panel.dart index 5b10c8e8d..06226dc1b 100644 --- a/lib/pages/dynamics/widgets/additional_panel.dart +++ b/lib/pages/dynamics/widgets/additional_panel.dart @@ -30,9 +30,7 @@ Widget addWidget( borderRadius: borderRadius, onTap: ugc.jumpUrl == null ? null - : () { - PiliScheme.routePushFromUrl(ugc.jumpUrl!); - }, + : () => PiliScheme.routePushFromUrl(ugc.jumpUrl!), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), @@ -146,10 +144,8 @@ Widget addWidget( MaterialTapTargetSize.shrinkWrap, ), onPressed: canJump - ? () { - PiliScheme.routePushFromUrl( - btn.jumpUrl!); - } + ? () => PiliScheme.routePushFromUrl( + btn.jumpUrl!) : btn.disable == 1 ? null : () async { @@ -214,9 +210,7 @@ Widget addWidget( children: content.items!.map((e) { return InkWell( borderRadius: borderRadius, - onTap: () { - PiliScheme.routePushFromUrl(e.jumpUrl!); - }, + onTap: () => PiliScheme.routePushFromUrl(e.jumpUrl!), child: Padding( padding: const EdgeInsets.symmetric( horizontal: 12, vertical: 8), @@ -263,9 +257,8 @@ Widget addWidget( if (e.jumpDesc?.isNotEmpty == true) ...[ const SizedBox(width: 10), FilledButton.tonal( - onPressed: () { - PiliScheme.routePushFromUrl(e.jumpUrl!); - }, + onPressed: () => + PiliScheme.routePushFromUrl(e.jumpUrl!), style: FilledButton.styleFrom( shape: const RoundedRectangleBorder( borderRadius: @@ -306,17 +299,15 @@ Widget addWidget( borderRadius: borderRadius, child: InkWell( borderRadius: borderRadius, - onTap: () { - showVoteDialog( - context, - vote.voteId!, - item.idStr is int - ? item.idStr - : item.idStr is String - ? int.parse(item.idStr) - : null, - ); - }, + onTap: () => showVoteDialog( + context, + vote.voteId!, + item.idStr is int + ? item.idStr + : item.idStr is String + ? int.parse(item.idStr) + : null, + ), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), @@ -359,17 +350,15 @@ Widget addWidget( ), const SizedBox(width: 10), FilledButton.tonal( - onPressed: () { - showVoteDialog( - context, - vote.voteId!, - item.idStr is int - ? item.idStr - : item.idStr is String - ? int.parse(item.idStr) - : null, - ); - }, + onPressed: () => showVoteDialog( + context, + vote.voteId!, + item.idStr is int + ? item.idStr + : item.idStr is String + ? int.parse(item.idStr) + : null, + ), style: FilledButton.styleFrom( shape: const RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(6)), diff --git a/lib/pages/dynamics/widgets/content_panel.dart b/lib/pages/dynamics/widgets/content_panel.dart index 070113655..b56c0145d 100644 --- a/lib/pages/dynamics/widgets/content_panel.dart +++ b/lib/pages/dynamics/widgets/content_panel.dart @@ -47,15 +47,13 @@ Widget content( children: [ if (item.modules.moduleDynamic?.topic != null) GestureDetector( - onTap: () { - Get.toNamed( - '/dynTopic', - parameters: { - 'id': item.modules.moduleDynamic!.topic!.id!.toString(), - 'name': item.modules.moduleDynamic!.topic!.name!, - }, - ); - }, + onTap: () => Get.toNamed( + '/dynTopic', + parameters: { + 'id': item.modules.moduleDynamic!.topic!.id!.toString(), + 'name': item.modules.moduleDynamic!.topic!.name!, + }, + ), child: Text.rich( TextSpan( children: [ diff --git a/lib/pages/dynamics/widgets/forward_panel.dart b/lib/pages/dynamics/widgets/forward_panel.dart index 0304140ca..6ec42416a 100644 --- a/lib/pages/dynamics/widgets/forward_panel.dart +++ b/lib/pages/dynamics/widgets/forward_panel.dart @@ -96,15 +96,13 @@ Widget forWard( const SizedBox(height: 5), if (item.modules.moduleDynamic?.topic != null) ...[ GestureDetector( - onTap: () { - Get.toNamed( - '/dynTopic', - parameters: { - 'id': item.modules.moduleDynamic!.topic!.id!.toString(), - 'name': item.modules.moduleDynamic!.topic!.name!, - }, - ); - }, + onTap: () => Get.toNamed( + '/dynTopic', + parameters: { + 'id': item.modules.moduleDynamic!.topic!.id!.toString(), + 'name': item.modules.moduleDynamic!.topic!.name!, + }, + ), child: Text.rich( TextSpan( children: [ @@ -389,9 +387,7 @@ Widget forWard( case 'DYNAMIC_TYPE_MUSIC': final Map music = item.modules.moduleDynamic!.major!.music!; return InkWell( - onTap: () { - PageUtils.handleWebview("https:${music['jump_url']}"); - }, + onTap: () => PageUtils.handleWebview("https:${music['jump_url']}"), child: Container( width: double.infinity, padding: @@ -439,11 +435,8 @@ Widget forWard( children: [ if (floor == 2) ...[ GestureDetector( - onTap: () { - Get.toNamed( - '/member?mid=${item.modules.moduleAuthor!.mid}', - ); - }, + onTap: () => + Get.toNamed('/member?mid=${item.modules.moduleAuthor!.mid}'), child: Row( children: [ NetworkImgLayer( diff --git a/lib/pages/dynamics/widgets/live_panel.dart b/lib/pages/dynamics/widgets/live_panel.dart index 335a7edc7..1e775f7cc 100644 --- a/lib/pages/dynamics/widgets/live_panel.dart +++ b/lib/pages/dynamics/widgets/live_panel.dart @@ -66,9 +66,7 @@ Widget livePanel( ], GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - Get.toNamed('/liveRoom?roomid=${content.live?.id}'); - }, + onTap: () => Get.toNamed('/liveRoom?roomid=${content.live?.id}'), onLongPress: () { Feedback.forLongPress(context); imageSaveDialog( diff --git a/lib/pages/dynamics/widgets/live_rcmd_panel.dart b/lib/pages/dynamics/widgets/live_rcmd_panel.dart index d19dd5e42..59f28d7de 100644 --- a/lib/pages/dynamics/widgets/live_rcmd_panel.dart +++ b/lib/pages/dynamics/widgets/live_rcmd_panel.dart @@ -54,15 +54,13 @@ Widget liveRcmdPanel( const SizedBox(height: 4), if (item.modules.moduleDynamic?.topic != null) ...[ GestureDetector( - onTap: () { - Get.toNamed( - '/dynTopic', - parameters: { - 'id': item.modules.moduleDynamic!.topic!.id!.toString(), - 'name': item.modules.moduleDynamic!.topic!.name!, - }, - ); - }, + onTap: () => Get.toNamed( + '/dynTopic', + parameters: { + 'id': item.modules.moduleDynamic!.topic!.id!.toString(), + 'name': item.modules.moduleDynamic!.topic!.name!, + }, + ), child: Padding( padding: const EdgeInsets.symmetric(horizontal: StyleString.safeSpace), @@ -83,9 +81,7 @@ Widget liveRcmdPanel( Padding( padding: const EdgeInsets.symmetric(horizontal: StyleString.safeSpace), child: GestureDetector( - onTap: () { - PageUtils.pushDynDetail(item, floor); - }, + onTap: () => PageUtils.pushDynDetail(item, floor), child: LayoutBuilder( builder: (context, box) { double width = box.maxWidth; diff --git a/lib/pages/dynamics/widgets/rich_node_panel.dart b/lib/pages/dynamics/widgets/rich_node_panel.dart index e58057e16..2f95eada8 100644 --- a/lib/pages/dynamics/widgets/rich_node_panel.dart +++ b/lib/pages/dynamics/widgets/rich_node_panel.dart @@ -59,9 +59,7 @@ TextSpan? richNode( text: ' ${i.text}', style: style, recognizer: TapGestureRecognizer() - ..onTap = () { - Get.toNamed('/member?mid=${i.rid}'); - }, + ..onTap = () => Get.toNamed('/member?mid=${i.rid}'), ), ); break; @@ -72,15 +70,13 @@ TextSpan? richNode( text: i.origText!, style: style, recognizer: TapGestureRecognizer() - ..onTap = () { - Get.toNamed( - '/searchResult', - parameters: { - 'keyword': - i.origText!.substring(1, i.origText!.length - 1), - }, - ); - }, + ..onTap = () => Get.toNamed( + '/searchResult', + parameters: { + 'keyword': + i.origText!.substring(1, i.origText!.length - 1), + }, + ), ), ); break; @@ -172,15 +168,13 @@ TextSpan? richNode( text: '${i.origText} ', style: style, recognizer: TapGestureRecognizer() - ..onTap = () { - Get.toNamed( - '/webview', - parameters: { - 'url': - 'https://www.bilibili.com/h5/lottery/result?business_id=${item.idStr}' - }, - ); - }, + ..onTap = () => Get.toNamed( + '/webview', + parameters: { + 'url': + 'https://www.bilibili.com/h5/lottery/result?business_id=${item.idStr}' + }, + ), ), ); break; @@ -204,9 +198,8 @@ TextSpan? richNode( recognizer: i.jumpUrl == null ? null : (TapGestureRecognizer() - ..onTap = () { - PiliScheme.routePushFromUrl(i.jumpUrl!); - }), + ..onTap = + () => PiliScheme.routePushFromUrl(i.jumpUrl!)), ), ); break; diff --git a/lib/pages/dynamics/widgets/up_panel.dart b/lib/pages/dynamics/widgets/up_panel.dart index 171704be9..ce7c5f6be 100644 --- a/lib/pages/dynamics/widgets/up_panel.dart +++ b/lib/pages/dynamics/widgets/up_panel.dart @@ -39,12 +39,10 @@ class _UpPanelState extends State { slivers: [ SliverToBoxAdapter( child: InkWell( - onTap: () { - setState(() { - widget.dynamicsController.showLiveItems = - !widget.dynamicsController.showLiveItems; - }); - }, + onTap: () => setState(() { + widget.dynamicsController.showLiveItems = + !widget.dynamicsController.showLiveItems; + }), child: Container( alignment: Alignment.center, height: isTop ? 76 : 60, diff --git a/lib/pages/dynamics_create/view.dart b/lib/pages/dynamics_create/view.dart index bab9a8681..30ae9e5d9 100644 --- a/lib/pages/dynamics_create/view.dart +++ b/lib/pages/dynamics_create/view.dart @@ -104,13 +104,11 @@ class _CreateDynPanelState extends CommonPublishPageState { borderRadius: const BorderRadius.all(Radius.circular(12)), child: InkWell( borderRadius: const BorderRadius.all(Radius.circular(12)), - onTap: () { - onPickImage(() { - if (pathList.isNotEmpty && !enablePublish.value) { - enablePublish.value = true; - } - }); - }, + onTap: () => onPickImage(() { + if (pathList.isNotEmpty && !enablePublish.value) { + enablePublish.value = true; + } + }), child: Ink( width: 100, height: 100, @@ -385,11 +383,7 @@ class _CreateDynPanelState extends CommonPublishPageState { ), visualDensity: VisualDensity.compact, ), - onPressed: () { - setState(() { - _publishTime = null; - }); - }, + onPressed: () => setState(() => _publishTime = null), label: Text(DateFormat('yyyy-MM-dd HH:mm').format(_publishTime!)), icon: const Icon(Icons.clear, size: 20), iconAlignment: IconAlignment.end, diff --git a/lib/pages/dynamics_detail/view.dart b/lib/pages/dynamics_detail/view.dart index 1e8783c8a..cd1a7c54d 100644 --- a/lib/pages/dynamics_detail/view.dart +++ b/lib/pages/dynamics_detail/view.dart @@ -265,41 +265,39 @@ class _DynamicDetailPageState extends State ? [ IconButton( tooltip: '页面比例调节', - onPressed: () { - showDialog( - context: context, - builder: (context) => Align( - alignment: Alignment.topRight, - child: Container( - margin: const EdgeInsets.only( - top: 56, - right: 16, - ), - width: context.width / 4, - height: 32, - child: Builder( - builder: (context) => Slider( - min: 1, - max: 100, - value: _ratio.first, - onChanged: (value) { - if (value >= 10 && value <= 90) { - _ratio[0] = value; - _ratio[1] = 100 - value; - GStorage.setting.put( - SettingBoxKey.dynamicDetailRatio, - _ratio, - ); - (context as Element).markNeedsBuild(); - setState(() {}); - } - }, - ), + onPressed: () => showDialog( + context: context, + builder: (context) => Align( + alignment: Alignment.topRight, + child: Container( + margin: const EdgeInsets.only( + top: 56, + right: 16, + ), + width: context.width / 4, + height: 32, + child: Builder( + builder: (context) => Slider( + min: 1, + max: 100, + value: _ratio.first, + onChanged: (value) { + if (value >= 10 && value <= 90) { + _ratio[0] = value; + _ratio[1] = 100 - value; + GStorage.setting.put( + SettingBoxKey.dynamicDetailRatio, + _ratio, + ); + (context as Element).markNeedsBuild(); + setState(() {}); + } + }, ), ), ), - ); - }, + ), + ), icon: Transform.rotate( angle: pi / 2, child: const Icon(Icons.splitscreen, size: 19), @@ -467,43 +465,41 @@ class _DynamicDetailPageState extends State Expanded( child: Builder( builder: (btnContext) => TextButton.icon( - onPressed: () { - showModalBottomSheet( - context: context, - isScrollControlled: true, - useSafeArea: true, - builder: (context) => RepostPanel( - item: _controller.dynItem, - callback: () { - int count = _controller - .dynItem - .modules - .moduleStat - ?.forward - ?.count ?? - 0; - _controller.dynItem.modules - .moduleStat ??= - ModuleStatModel(); - _controller - .dynItem - .modules - .moduleStat - ?.forward ??= DynamicStat(); - _controller - .dynItem - .modules - .moduleStat! - .forward! - .count = count + 1; - if (btnContext.mounted) { - (btnContext as Element?) - ?.markNeedsBuild(); - } - }, - ), - ); - }, + onPressed: () => showModalBottomSheet( + context: context, + isScrollControlled: true, + useSafeArea: true, + builder: (context) => RepostPanel( + item: _controller.dynItem, + callback: () { + int count = _controller + .dynItem + .modules + .moduleStat + ?.forward + ?.count ?? + 0; + _controller.dynItem.modules + .moduleStat ??= + ModuleStatModel(); + _controller + .dynItem + .modules + .moduleStat + ?.forward ??= DynamicStat(); + _controller + .dynItem + .modules + .moduleStat! + .forward! + .count = count + 1; + if (btnContext.mounted) { + (btnContext as Element?) + ?.markNeedsBuild(); + } + }, + ), + ), icon: Icon( FontAwesomeIcons.shareFromSquare, size: 16, @@ -533,10 +529,8 @@ class _DynamicDetailPageState extends State ), Expanded( child: TextButton.icon( - onPressed: () { - Utils.shareText( - '${HttpString.dynamicShareBaseUrl}/${_controller.dynItem.idStr}'); - }, + onPressed: () => Utils.shareText( + '${HttpString.dynamicShareBaseUrl}/${_controller.dynItem.idStr}'), icon: Icon( CustomIcon.share_node, size: 16, @@ -730,13 +724,11 @@ class _DynamicDetailPageState extends State replyLevel: '1', replyReply: (replyItem, id) => replyReply(context, replyItem, id), - onReply: () { - _controller.onReply( - context, - replyItem: response[index], - index: index, - ); - }, + onReply: () => _controller.onReply( + context, + replyItem: response[index], + index: index, + ), onDelete: (subIndex) => _controller.onRemove(index, subIndex), upMid: _controller.upMid, diff --git a/lib/pages/dynamics_topic/view.dart b/lib/pages/dynamics_topic/view.dart index 9e2b2ba8d..a5c273eeb 100644 --- a/lib/pages/dynamics_topic/view.dart +++ b/lib/pages/dynamics_topic/view.dart @@ -156,9 +156,8 @@ class _DynTopicPageState extends State { margin: const EdgeInsets.only(left: 45, right: 78), child: GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - Get.toNamed('/member?mid=${response.topicCreator!.uid}'); - }, + onTap: () => Get.toNamed( + '/member?mid=${response.topicCreator!.uid}'), child: Row( mainAxisSize: MainAxisSize.min, children: [ @@ -266,11 +265,10 @@ class _DynTopicPageState extends State { ), actions: [ IconButton( - onPressed: () { - // https://www.bilibili.com/v/topic/detail?topic_id=${_controller.topicId} - Utils.shareText( - '${_controller.topicName} https://m.bilibili.com/topic-detail?topic_id=${_controller.topicId}'); - }, + onPressed: () => Utils.shareText( + '${_controller.topicName} https://m.bilibili.com/topic-detail?topic_id=${_controller.topicId}') + // https://www.bilibili.com/v/topic/detail?topic_id=${_controller.topicId} + , icon: const Icon(MdiIcons.share), ), PopupMenuButton( diff --git a/lib/pages/emote/view.dart b/lib/pages/emote/view.dart index 2965bd0b1..e07c0a7fd 100644 --- a/lib/pages/emote/view.dart +++ b/lib/pages/emote/view.dart @@ -65,9 +65,7 @@ class _EmotePanelState extends State child: InkWell( borderRadius: const BorderRadius.all(Radius.circular(8)), - onTap: () { - widget.onChoose(e.emote![index]); - }, + onTap: () => widget.onChoose(e.emote![index]), child: Padding( padding: const EdgeInsets.all(6), child: type == 4 @@ -109,15 +107,13 @@ class _EmotePanelState extends State .withValues(alpha: 0.8), bgColor: Colors.transparent, context: context, - onPressed: () { - Get.toNamed( - '/webview', - parameters: { - 'url': - 'https://www.bilibili.com/h5/mall/emoji-package/home?navhide=1&native.theme=1&night=${Get.isDarkMode ? 1 : 0}', - }, - ); - }, + onPressed: () => Get.toNamed( + '/webview', + parameters: { + 'url': + 'https://www.bilibili.com/h5/mall/emoji-package/home?navhide=1&native.theme=1&night=${Get.isDarkMode ? 1 : 0}', + }, + ), icon: Icons.settings, ), ), diff --git a/lib/pages/episode_panel/view.dart b/lib/pages/episode_panel/view.dart index 51cb2470a..357b72835 100644 --- a/lib/pages/episode_panel/view.dart +++ b/lib/pages/episode_panel/view.dart @@ -131,7 +131,7 @@ class _EpisodePanelState extends CommonSlidePageState { widget.initialTabIndex, duration: const Duration(milliseconds: 200), ); - Future.delayed(const Duration(milliseconds: 300)).then((_) { + Future.delayed(const Duration(milliseconds: 300)).whenComplete(() { jumpToCurrent(); }); } else { @@ -544,9 +544,7 @@ class _EpisodePanelState extends CommonSlidePageState { icon: widget.isReversed == true ? MdiIcons.sortDescending : MdiIcons.sortAscending, - onPressed: () { - widget.onReverse?.call(); - }, + onPressed: () => widget.onReverse?.call(), ); Widget _buildToolbar(ThemeData theme) => Container( @@ -631,12 +629,10 @@ class _EpisodePanelState extends CommonSlidePageState { icon: !_isReversed[_currentTabIndex.value] ? MdiIcons.sortNumericAscending : MdiIcons.sortNumericDescending, - onPressed: () { - setState(() { - _isReversed[_currentTabIndex.value] = - !_isReversed[_currentTabIndex.value]; - }); - }, + onPressed: () => setState(() { + _isReversed[_currentTabIndex.value] = + !_isReversed[_currentTabIndex.value]; + }), ), ), if (widget.onClose != null) diff --git a/lib/pages/fan/view.dart b/lib/pages/fan/view.dart index d0a506608..245c626b5 100644 --- a/lib/pages/fan/view.dart +++ b/lib/pages/fan/view.dart @@ -119,16 +119,12 @@ class _FansPageState extends State { onLongPress: widget.onSelect != null ? null : isOwner - ? () { - showConfirmDialog( + ? () => showConfirmDialog( context: context, title: '确定移除 ${item.uname} ?', - onConfirm: () { - _fansController.onRemoveFan( - index, item.mid!); - }, - ); - } + onConfirm: () => _fansController.onRemoveFan( + index, item.mid!), + ) : null, leading: Hero( tag: heroTag, diff --git a/lib/pages/fav/article/view.dart b/lib/pages/fav/article/view.dart index 784c4b044..b0de13630 100644 --- a/lib/pages/fav/article/view.dart +++ b/lib/pages/fav/article/view.dart @@ -66,18 +66,16 @@ class _FavArticlePageState extends State } return FavArticleItem( item: response[index], - onDelete: () { - showConfirmDialog( - context: context, - title: '确定取消收藏?', - onConfirm: () { - _favArticleController.onRemove( - index, - response[index]['opus_id'], - ); - }, - ); - }, + onDelete: () => showConfirmDialog( + context: context, + title: '确定取消收藏?', + onConfirm: () { + _favArticleController.onRemove( + index, + response[index]['opus_id'], + ); + }, + ), ); }, childCount: response!.length, diff --git a/lib/pages/fav/article/widget/item.dart b/lib/pages/fav/article/widget/item.dart index 86d33aa1c..62fec58f4 100644 --- a/lib/pages/fav/article/widget/item.dart +++ b/lib/pages/fav/article/widget/item.dart @@ -24,15 +24,13 @@ class FavArticleItem extends StatelessWidget { clipBehavior: Clip.none, children: [ InkWell( - onTap: () { - Get.toNamed( - '/articlePage', - parameters: { - 'id': item['opus_id'], - 'type': 'opus', - }, - ); - }, + onTap: () => Get.toNamed( + '/articlePage', + parameters: { + 'id': item['opus_id'], + 'type': 'opus', + }, + ), child: Padding( padding: const EdgeInsets.symmetric( horizontal: StyleString.safeSpace, diff --git a/lib/pages/fav/note/child_view.dart b/lib/pages/fav/note/child_view.dart index 773a620f7..312f791dc 100644 --- a/lib/pages/fav/note/child_view.dart +++ b/lib/pages/fav/note/child_view.dart @@ -90,10 +90,8 @@ class _FavNoteChildPageState extends State ), GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - _favNoteController.handleSelect( - !_favNoteController.allSelected.value); - }, + onTap: () => _favNoteController.handleSelect( + !_favNoteController.allSelected.value), child: const Padding( padding: EdgeInsets.only( top: 14, @@ -154,9 +152,7 @@ class _FavNoteChildPageState extends State return FavNoteItem( item: response[index], ctr: _favNoteController, - onSelect: () { - _favNoteController.onSelect(index); - }, + onSelect: () => _favNoteController.onSelect(index), ); }, childCount: response!.length, diff --git a/lib/pages/fav/pgc/child_view.dart b/lib/pages/fav/pgc/child_view.dart index bd48d31c4..1dbe98245 100644 --- a/lib/pages/fav/pgc/child_view.dart +++ b/lib/pages/fav/pgc/child_view.dart @@ -97,10 +97,8 @@ class _FavPgcChildPageState extends State ), GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - _favPgcController.handleSelect( - !_favPgcController.allSelected.value); - }, + onTap: () => _favPgcController + .handleSelect(!_favPgcController.allSelected.value), child: const Padding( padding: EdgeInsets.only( top: 14, @@ -178,30 +176,26 @@ class _FavPgcChildPageState extends State return FavPgcItem( item: item, ctr: _favPgcController, - onSelect: () { - _favPgcController.onSelect(index); - }, - onUpdateStatus: () { - showPgcFollowDialog( - context: context, - type: widget.type == 0 ? '追番' : '追剧', - followStatus: widget.followStatus, - onUpdateStatus: (followStatus) { - if (followStatus == -1) { - _favPgcController.bangumiDel( - index, - item.seasonId, - ); - } else { - _favPgcController.onUpdate( - index, - followStatus, - item.seasonId, - ); - } - }, - ); - }, + onSelect: () => _favPgcController.onSelect(index), + onUpdateStatus: () => showPgcFollowDialog( + context: context, + type: widget.type == 0 ? '追番' : '追剧', + followStatus: widget.followStatus, + onUpdateStatus: (followStatus) { + if (followStatus == -1) { + _favPgcController.bangumiDel( + index, + item.seasonId, + ); + } else { + _favPgcController.onUpdate( + index, + followStatus, + item.seasonId, + ); + } + }, + ), ); }, childCount: response!.length, diff --git a/lib/pages/fav/topic/view.dart b/lib/pages/fav/topic/view.dart index 1e9d10347..d6c59cac5 100644 --- a/lib/pages/fav/topic/view.dart +++ b/lib/pages/fav/topic/view.dart @@ -68,24 +68,20 @@ class _FavTopicPageState extends State color: theme.colorScheme.onInverseSurface, borderRadius: const BorderRadius.all(Radius.circular(6)), child: InkWell( - onTap: () { - Get.toNamed( - '/dynTopic', - parameters: { - 'id': item.id!.toString(), - 'name': item.name!, - }, - ); - }, - onLongPress: () { - showConfirmDialog( - context: context, - title: '确定取消收藏?', - onConfirm: () { - _controller.onRemove(index, item.id); - }, - ); - }, + onTap: () => Get.toNamed( + '/dynTopic', + parameters: { + 'id': item.id!.toString(), + 'name': item.name!, + }, + ), + onLongPress: () => showConfirmDialog( + context: context, + title: '确定取消收藏?', + onConfirm: () { + _controller.onRemove(index, item.id); + }, + ), borderRadius: const BorderRadius.all(Radius.circular(6)), child: Container( alignment: Alignment.centerLeft, diff --git a/lib/pages/fav/view.dart b/lib/pages/fav/view.dart index 2f11d0d8e..8693dece5 100644 --- a/lib/pages/fav/view.dart +++ b/lib/pages/fav/view.dart @@ -54,21 +54,19 @@ class _FavPageState extends State with SingleTickerProviderStateMixin { Obx( () => _showVideoFavMenu.value ? IconButton( - onPressed: () { - Get.toNamed('/createFav')?.then( - (data) { - if (data != null) { - List list = _favController - .loadingState.value is Success - ? (_favController.loadingState.value as Success) - .response - : []; - list.insert(list.isNotEmpty ? 1 : 0, data); - _favController.loadingState.refresh(); - } - }, - ); - }, + onPressed: () => Get.toNamed('/createFav')?.then( + (data) { + if (data != null) { + List list = _favController + .loadingState.value is Success + ? (_favController.loadingState.value as Success) + .response + : []; + list.insert(list.isNotEmpty ? 1 : 0, data); + _favController.loadingState.refresh(); + } + }, + ), icon: const Icon(Icons.add), tooltip: '新建收藏夹', ) diff --git a/lib/pages/fav_create/view.dart b/lib/pages/fav_create/view.dart index f0bfa3be2..160874729 100644 --- a/lib/pages/fav_create/view.dart +++ b/lib/pages/fav_create/view.dart @@ -365,11 +365,9 @@ class _CreateFavPageState extends State { const SizedBox(height: 16), ], ListTile( - onTap: () { - setState(() { - _isPublic = !_isPublic; - }); - }, + onTap: () => setState(() { + _isPublic = !_isPublic; + }), tileColor: theme.colorScheme.onInverseSurface, leading: Text( '公开', diff --git a/lib/pages/fav_detail/view.dart b/lib/pages/fav_detail/view.dart index 8c8080d1f..fe473646b 100644 --- a/lib/pages/fav_detail/view.dart +++ b/lib/pages/fav_detail/view.dart @@ -125,15 +125,14 @@ class _FavDetailPageState extends State { style: TextButton.styleFrom( visualDensity: VisualDensity.compact, ), - onPressed: () { - RequestUtils.onCopyOrMove( - context: context, - isCopy: true, - ctr: _favDetailController, - mediaId: _favDetailController.mediaId, - mid: _favDetailController.mid, - ); - }, + onPressed: () => + RequestUtils.onCopyOrMove( + context: context, + isCopy: true, + ctr: _favDetailController, + mediaId: _favDetailController.mediaId, + mid: _favDetailController.mid, + ), child: Text( '复制', style: TextStyle( @@ -145,15 +144,14 @@ class _FavDetailPageState extends State { style: TextButton.styleFrom( visualDensity: VisualDensity.compact, ), - onPressed: () { - RequestUtils.onCopyOrMove( - context: context, - isCopy: false, - ctr: _favDetailController, - mediaId: _favDetailController.mediaId, - mid: _favDetailController.mid, - ); - }, + onPressed: () => + RequestUtils.onCopyOrMove( + context: context, + isCopy: false, + ctr: _favDetailController, + mediaId: _favDetailController.mediaId, + mid: _favDetailController.mid, + ), child: Text( '移动', style: TextStyle( @@ -194,32 +192,29 @@ class _FavDetailPageState extends State { icon: const Icon(Icons.more_vert), itemBuilder: (context) => [ PopupMenuItem( - onTap: () { - Get.toNamed( - '/createFav', - parameters: {'mediaId': mediaId}, - )?.then((res) { - if (res is FavFolderItemData) { - _favDetailController.item.value = res; - } - }); - }, + onTap: () => Get.toNamed( + '/createFav', + parameters: {'mediaId': mediaId}, + )?.then((res) { + if (res is FavFolderItemData) { + _favDetailController.item.value = res; + } + }), child: const Text('编辑信息'), ), PopupMenuItem( - onTap: () { - UserHttp.cleanFav(mediaId: mediaId).then((data) { - if (data['status']) { - SmartDialog.showToast('清除成功'); - Future.delayed( - const Duration(milliseconds: 200), () { - _favDetailController.onReload(); - }); - } else { - SmartDialog.showToast(data['msg']); - } - }); - }, + onTap: () => UserHttp.cleanFav(mediaId: mediaId) + .then((data) { + if (data['status']) { + SmartDialog.showToast('清除成功'); + Future.delayed( + const Duration(milliseconds: 200), () { + _favDetailController.onReload(); + }); + } else { + SmartDialog.showToast(data['msg']); + } + }), child: const Text('清除失效内容'), ), PopupMenuItem( @@ -250,23 +245,20 @@ class _FavDetailPageState extends State { if (!Utils.isDefaultFav( _favDetailController.item.value.attr ?? 0)) PopupMenuItem( - onTap: () { - showConfirmDialog( - context: context, - title: '确定删除该收藏夹?', - onConfirm: () { + onTap: () => showConfirmDialog( + context: context, + title: '确定删除该收藏夹?', + onConfirm: () => UserHttp.deleteFolder(mediaIds: [mediaId]) .then((data) { - if (data['status']) { - SmartDialog.showToast('删除成功'); - Get.back(result: true); - } else { - SmartDialog.showToast(data['msg']); - } - }); - }, - ); - }, + if (data['status']) { + SmartDialog.showToast('删除成功'); + Get.back(result: true); + } else { + SmartDialog.showToast(data['msg']); + } + }), + ), child: Text( '删除', style: TextStyle( @@ -402,29 +394,24 @@ class _FavDetailPageState extends State { item.type!, ) : null, - onViewFav: () { - PageUtils.toVideoPage( - 'bvid=${item.bvid}&cid=${item.cid}', - arguments: { - 'videoItem': item, - 'heroTag': Utils.makeHeroTag(item.bvid), - 'sourceType': 'fav', - 'mediaId': _favDetailController.item.value.id, - 'oid': item.id, - 'favTitle': - _favDetailController.item.value.title, - 'count': - _favDetailController.item.value.mediaCount, - 'desc': true, - 'isContinuePlaying': index != 0, - 'isOwner': _favDetailController.isOwner.value, - }, - ); - }, + onViewFav: () => PageUtils.toVideoPage( + 'bvid=${item.bvid}&cid=${item.cid}', + arguments: { + 'videoItem': item, + 'heroTag': Utils.makeHeroTag(item.bvid), + 'sourceType': 'fav', + 'mediaId': _favDetailController.item.value.id, + 'oid': item.id, + 'favTitle': _favDetailController.item.value.title, + 'count': + _favDetailController.item.value.mediaCount, + 'desc': true, + 'isContinuePlaying': index != 0, + 'isOwner': _favDetailController.isOwner.value, + }, + ), onTap: _favDetailController.enableMultiSelect.value - ? () { - _favDetailController.onSelect(index); - } + ? () => _favDetailController.onSelect(index) : null, onLongPress: _favDetailController.isOwner.value ? () { diff --git a/lib/pages/fav_detail/widget/fav_video_card.dart b/lib/pages/fav_detail/widget/fav_video_card.dart index 481f6cd3c..78d8408f0 100644 --- a/lib/pages/fav_detail/widget/fav_video_card.dart +++ b/lib/pages/fav_detail/widget/fav_video_card.dart @@ -189,34 +189,31 @@ class FavVideoCardH extends StatelessWidget { tooltip: '取消收藏', iconColor: theme.colorScheme.outline, bgColor: Colors.transparent, - onPressed: () { - showDialog( - context: Get.context!, - builder: (context) { - return AlertDialog( - title: const Text('提示'), - content: const Text('要取消收藏吗?'), - actions: [ - TextButton( - onPressed: Get.back, - child: Text( - '取消', - style: - TextStyle(color: theme.colorScheme.outline), - ), + onPressed: () => showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text('提示'), + content: const Text('要取消收藏吗?'), + actions: [ + TextButton( + onPressed: Get.back, + child: Text( + '取消', + style: TextStyle(color: theme.colorScheme.outline), ), - TextButton( - onPressed: () { - Get.back(); - onDelFav!(); - }, - child: const Text('确定取消'), - ) - ], - ); - }, - ); - }, + ), + TextButton( + onPressed: () { + Get.back(); + onDelFav!(); + }, + child: const Text('确定取消'), + ) + ], + ); + }, + ), ), ), ], diff --git a/lib/pages/fav_folder_sort/view.dart b/lib/pages/fav_folder_sort/view.dart index f3e283781..6b43caf98 100644 --- a/lib/pages/fav_folder_sort/view.dart +++ b/lib/pages/fav_folder_sort/view.dart @@ -32,7 +32,7 @@ class _FavFolderSortPageState extends State { } if (_scrollController.position.pixels >= _scrollController.position.maxScrollExtent - 200) { - _favController.onLoadMore().then((_) { + _favController.onLoadMore().whenComplete(() { try { if (_favController.loadingState.value is Success) { List list = @@ -130,11 +130,8 @@ class _FavFolderSortPageState extends State { child: FavItem( heroTag: key, favFolderItem: item, - onLongPress: index == 0 - ? () { - SmartDialog.showToast('默认收藏夹不支持排序'); - } - : null, + onLongPress: + index == 0 ? () => SmartDialog.showToast('默认收藏夹不支持排序') : null, ), ); }, diff --git a/lib/pages/fav_panel/view.dart b/lib/pages/fav_panel/view.dart index 0142da32a..53d4efb89 100644 --- a/lib/pages/fav_panel/view.dart +++ b/lib/pages/fav_panel/view.dart @@ -50,16 +50,14 @@ class _FavPanelState extends State { title: const Text('添加到收藏夹'), actions: [ TextButton.icon( - onPressed: () { - Get.toNamed('/createFav')?.then((data) { - if (data != null) { - (widget.ctr?.favFolderData.value as FavFolderData?) - ?.list - ?.insert(1, data); - widget.ctr?.favFolderData.refresh(); - } - }); - }, + onPressed: () => Get.toNamed('/createFav')?.then((data) { + if (data != null) { + (widget.ctr?.favFolderData.value as FavFolderData?) + ?.list + ?.insert(1, data); + widget.ctr?.favFolderData.refresh(); + } + }), icon: Icon( Icons.add, color: theme.colorScheme.primary, diff --git a/lib/pages/fav_search/view.dart b/lib/pages/fav_search/view.dart index fb2ecfacd..15187602b 100644 --- a/lib/pages/fav_search/view.dart +++ b/lib/pages/fav_search/view.dart @@ -37,30 +37,26 @@ class _FavSearchPageState extends CommonSearchPageState controller.onCancelFav( index, item.id!, item.type, - ); - } + ) : null, - onViewFav: () { - PageUtils.toVideoPage( - 'bvid=${item.bvid}&cid=${item.cid}', - arguments: { - 'videoItem': item, - 'heroTag': Utils.makeHeroTag(item.bvid), - 'sourceType': 'fav', - 'mediaId': controller.mediaId, - 'oid': item.id, - 'favTitle': controller.title, - 'count': controller.count, - 'desc': true, - 'isContinuePlaying': true, - }, - ); - }, + onViewFav: () => PageUtils.toVideoPage( + 'bvid=${item.bvid}&cid=${item.cid}', + arguments: { + 'videoItem': item, + 'heroTag': Utils.makeHeroTag(item.bvid), + 'sourceType': 'fav', + 'mediaId': controller.mediaId, + 'oid': item.id, + 'favTitle': controller.title, + 'count': controller.count, + 'desc': true, + 'isContinuePlaying': true, + }, + ), ); }, ), diff --git a/lib/pages/fav_sort/view.dart b/lib/pages/fav_sort/view.dart index c6e209805..7fcd500f2 100644 --- a/lib/pages/fav_sort/view.dart +++ b/lib/pages/fav_sort/view.dart @@ -33,7 +33,7 @@ class _FavSortPageState extends State { } if (_scrollController.position.pixels >= _scrollController.position.maxScrollExtent - 200) { - _favDetailController.onLoadMore().then((_) { + _favDetailController.onLoadMore().whenComplete(() { try { if (_favDetailController.loadingState.value is Success) { List list = diff --git a/lib/pages/follow/child_view.dart b/lib/pages/follow/child_view.dart index c452be74c..164fc828d 100644 --- a/lib/pages/follow/child_view.dart +++ b/lib/pages/follow/child_view.dart @@ -45,14 +45,12 @@ class _FollowChildPageState extends State backgroundColor: Colors.transparent, body: _child, floatingActionButton: FloatingActionButton.extended( - onPressed: () { - _followController - ..orderType.value = - _followController.orderType.value == FollowOrderType.def - ? FollowOrderType.attention - : FollowOrderType.def - ..onReload(); - }, + onPressed: () => _followController + ..orderType.value = + _followController.orderType.value == FollowOrderType.def + ? FollowOrderType.attention + : FollowOrderType.def + ..onReload(), icon: const Icon(Icons.format_list_bulleted, size: 20), label: Obx(() => Text(_followController.orderType.value.title)), ), diff --git a/lib/pages/follow/view.dart b/lib/pages/follow/view.dart index ff52d369f..563a8a3dc 100644 --- a/lib/pages/follow/view.dart +++ b/lib/pages/follow/view.dart @@ -97,9 +97,7 @@ class _FollowPageState extends State { int? count = item.count; if (_isCustomTag(item.tagid)) { return GestureDetector( - onLongPress: () { - _onHandleTag(index, item); - }, + onLongPress: () => _onHandleTag(index, item), child: Tab( child: Row( children: [ @@ -200,9 +198,7 @@ class _FollowPageState extends State { context: context, title: '删除分组', content: '删除后,该分组下的用户依旧保留?', - onConfirm: () { - _followController.onDelTag(item.tagid); - }, + onConfirm: () => _followController.onDelTag(item.tagid), ); }, dense: true, @@ -232,9 +228,7 @@ class _FollowPageState extends State { ], decoration: const InputDecoration(border: OutlineInputBorder()), ), - onConfirm: () { - _followController.onCreateTag(tagName); - }, + onConfirm: () => _followController.onCreateTag(tagName), ); } } diff --git a/lib/pages/follow/widgets/follow_item.dart b/lib/pages/follow/widgets/follow_item.dart index 10533cdd9..e6cc0d3d1 100644 --- a/lib/pages/follow/widgets/follow_item.dart +++ b/lib/pages/follow/widgets/follow_item.dart @@ -91,14 +91,12 @@ class FollowItem extends StatelessWidget { ? SizedBox( height: 34, child: FilledButton.tonal( - onPressed: () { - RequestUtils.actionRelationMod( - context: context, - mid: item.mid, - isFollow: item.attribute != -1, - callback: callback, - ); - }, + onPressed: () => RequestUtils.actionRelationMod( + context: context, + mid: item.mid, + isFollow: item.attribute != -1, + callback: callback, + ), style: FilledButton.styleFrom( padding: const EdgeInsets.fromLTRB(15, 0, 15, 0), foregroundColor: diff --git a/lib/pages/follow_search/view.dart b/lib/pages/follow_search/view.dart index 15dba147d..a8557dc36 100644 --- a/lib/pages/follow_search/view.dart +++ b/lib/pages/follow_search/view.dart @@ -39,9 +39,7 @@ class _FollowSearchPageState extends CommonSearchPageState Get.back(result: userModel) : null, ); }), diff --git a/lib/pages/history/view.dart b/lib/pages/history/view.dart index 0478098bc..1b90a6082 100644 --- a/lib/pages/history/view.dart +++ b/lib/pages/history/view.dart @@ -147,9 +147,7 @@ class _HistoryPageState extends State child2: AppBar( leading: IconButton( tooltip: '取消', - onPressed: () { - currCtr().handleSelect(); - }, + onPressed: currCtr().handleSelect, icon: const Icon(Icons.close_outlined), ), title: Obx( diff --git a/lib/pages/history/widgets/item.dart b/lib/pages/history/widgets/item.dart index c2771c9ef..4f78b0bfe 100644 --- a/lib/pages/history/widgets/item.dart +++ b/lib/pages/history/widgets/item.dart @@ -253,14 +253,12 @@ class HistoryItem extends StatelessWidget { if (videoItem.authorMid != null && videoItem.authorName?.isNotEmpty == true) PopupMenuItem( - onTap: () { - Get.toNamed( - '/member?mid=${videoItem.authorMid}', - arguments: { - 'heroTag': '${videoItem.authorMid}', - }, - ); - }, + onTap: () => Get.toNamed( + '/member?mid=${videoItem.authorMid}', + arguments: { + 'heroTag': '${videoItem.authorMid}', + }, + ), height: 35, child: Row( children: [ diff --git a/lib/pages/hot/view.dart b/lib/pages/hot/view.dart index 9cdaec42d..31ba75e22 100644 --- a/lib/pages/hot/view.dart +++ b/lib/pages/hot/view.dart @@ -103,31 +103,27 @@ class _HotPageState extends CommonPageState iconUrl: 'http://i0.hdslb.com/bfs/archive/552ebe8c4794aeef30ebd1568b59ad35f15e21ad.png', title: '每周必看', - onTap: () { - Get.toNamed( - '/webview', - parameters: { - 'url': - 'https://www.bilibili.com/h5/weekly-recommend' - }, - arguments: {'off': false}, - ); - }, + onTap: () => Get.toNamed( + '/webview', + parameters: { + 'url': + 'https://www.bilibili.com/h5/weekly-recommend' + }, + arguments: {'off': false}, + ), ), _buildEntranceItem( iconUrl: 'http://i0.hdslb.com/bfs/archive/3693ec9335b78ca57353ac0734f36a46f3d179a9.png', title: '入站必刷', - onTap: () { - Get.toNamed( - '/webview', - parameters: { - 'url': - 'https://www.bilibili.com/h5/good-history' - }, - arguments: {'off': false}, - ); - }, + onTap: () => Get.toNamed( + '/webview', + parameters: { + 'url': + 'https://www.bilibili.com/h5/good-history' + }, + arguments: {'off': false}, + ), ), ], ), diff --git a/lib/pages/later/child_view.dart b/lib/pages/later/child_view.dart index b0168bf63..9a343dc0d 100644 --- a/lib/pages/later/child_view.dart +++ b/lib/pages/later/child_view.dart @@ -104,9 +104,7 @@ class _LaterViewChildPageState extends State onTap: _laterController.baseCtr.enableMultiSelect.value.not ? null - : () { - _laterController.onSelect(index); - }, + : () => _laterController.onSelect(index), onLongPress: () { if (_laterController .baseCtr.enableMultiSelect.value.not) { @@ -173,13 +171,11 @@ class _LaterViewChildPageState extends State child: iconButton( tooltip: '移除', context: context, - onPressed: () { - _laterController.toViewDel( - context, - index, - videoItem.aid, - ); - }, + onPressed: () => _laterController.toViewDel( + context, + index, + videoItem.aid, + ), icon: Icons.clear, iconColor: theme.colorScheme.outline, bgColor: Colors.transparent, diff --git a/lib/pages/later_search/view.dart b/lib/pages/later_search/view.dart index 3c8ad2282..7098569a8 100644 --- a/lib/pages/later_search/view.dart +++ b/lib/pages/later_search/view.dart @@ -64,13 +64,11 @@ class _LaterSearchPageState child: iconButton( tooltip: '移除', context: context, - onPressed: () { - controller.toViewDel( - context, - index, - item.aid, - ); - }, + onPressed: () => controller.toViewDel( + context, + index, + item.aid, + ), icon: Icons.clear, iconColor: Theme.of(context).colorScheme.onSurfaceVariant, bgColor: Colors.transparent, diff --git a/lib/pages/live/view.dart b/lib/pages/live/view.dart index 12d3742cd..55dea2b24 100644 --- a/lib/pages/live/view.dart +++ b/lib/pages/live/view.dart @@ -118,9 +118,7 @@ class _LivePageState extends CommonPageState context: context, tooltip: '全部标签', icon: Icons.widgets, - onPressed: () { - Get.to(const LiveAreaPage()); - }, + onPressed: () => Get.to(const LiveAreaPage()), ), ], ), @@ -250,9 +248,7 @@ class _LivePageState extends CommonPageState ), const Spacer(), GestureDetector( - onTap: () { - Get.to(const LiveFollowPage()); - }, + onTap: () => Get.to(const LiveFollowPage()), child: Row( mainAxisSize: MainAxisSize.min, children: [ @@ -289,9 +285,7 @@ class _LivePageState extends CommonPageState return SizedBox( width: 65, child: GestureDetector( - onTap: () { - Get.toNamed('/liveRoom?roomid=${item.roomid}'); - }, + onTap: () => Get.toNamed('/liveRoom?roomid=${item.roomid}'), onLongPress: () { Feedback.forLongPress(context); Get.toNamed('/member?mid=${item.uid}'); diff --git a/lib/pages/live/widgets/live_item.dart b/lib/pages/live/widgets/live_item.dart index a06e0cd12..543afa1e2 100644 --- a/lib/pages/live/widgets/live_item.dart +++ b/lib/pages/live/widgets/live_item.dart @@ -22,9 +22,7 @@ class LiveCardV extends StatelessWidget { clipBehavior: Clip.hardEdge, margin: EdgeInsets.zero, child: InkWell( - onTap: () { - Get.toNamed('/liveRoom?roomid=${liveItem.roomId}'); - }, + onTap: () => Get.toNamed('/liveRoom?roomid=${liveItem.roomId}'), onLongPress: () => imageSaveDialog( title: liveItem.title, cover: liveItem.cover, diff --git a/lib/pages/live/widgets/live_item_app.dart b/lib/pages/live/widgets/live_item_app.dart index b88c85b3d..374c51a36 100644 --- a/lib/pages/live/widgets/live_item_app.dart +++ b/lib/pages/live/widgets/live_item_app.dart @@ -22,9 +22,7 @@ class LiveCardVApp extends StatelessWidget { clipBehavior: Clip.hardEdge, margin: EdgeInsets.zero, child: InkWell( - onTap: () { - Get.toNamed('/liveRoom?roomid=${item.roomid}'); - }, + onTap: () => Get.toNamed('/liveRoom?roomid=${item.roomid}'), onLongPress: () => imageSaveDialog( title: item.title, cover: item.cover, diff --git a/lib/pages/live_area_detail/view.dart b/lib/pages/live_area_detail/view.dart index 9e3f4c711..395559abf 100644 --- a/lib/pages/live_area_detail/view.dart +++ b/lib/pages/live_area_detail/view.dart @@ -38,9 +38,7 @@ class _LiveAreaDetailPageState extends State { title: Text(widget.parentName), actions: [ IconButton( - onPressed: () { - Get.to(const LiveSearchPage()); - }, + onPressed: () => Get.to(const LiveSearchPage()), icon: const Icon(Icons.search), ), const SizedBox(width: 16), @@ -84,9 +82,8 @@ class _LiveAreaDetailPageState extends State { context: context, icon: Icons.menu, bgColor: Colors.transparent, - onPressed: () { - _showTags(context, theme, response); - }, + onPressed: () => + _showTags(context, theme, response), ), ], ), diff --git a/lib/pages/live_follow/widgets/live_item_follow.dart b/lib/pages/live_follow/widgets/live_item_follow.dart index d48778de5..c87daed0d 100644 --- a/lib/pages/live_follow/widgets/live_item_follow.dart +++ b/lib/pages/live_follow/widgets/live_item_follow.dart @@ -22,9 +22,7 @@ class LiveCardVFollow extends StatelessWidget { clipBehavior: Clip.hardEdge, margin: EdgeInsets.zero, child: InkWell( - onTap: () { - Get.toNamed('/liveRoom?roomid=${liveItem.roomid}'); - }, + onTap: () => Get.toNamed('/liveRoom?roomid=${liveItem.roomid}'), onLongPress: () => imageSaveDialog( title: liveItem.title, cover: liveItem.roomCover, diff --git a/lib/pages/live_room/view.dart b/lib/pages/live_room/view.dart index 925857ee5..f57a076e6 100644 --- a/lib/pages/live_room/view.dart +++ b/lib/pages/live_room/view.dart @@ -420,21 +420,18 @@ class _LiveRoomPageState extends State actions: [ IconButton( tooltip: '刷新', - onPressed: () { - _futureBuilderFuture = _liveRoomController.queryLiveInfo(); - }, + onPressed: () => + _futureBuilderFuture = _liveRoomController.queryLiveInfo(), icon: const Icon(Icons.refresh), ), PopupMenuButton( icon: const Icon(Icons.more_vert, size: 19), itemBuilder: (BuildContext context) => [ PopupMenuItem( - onTap: () { - PageUtils.inAppWebview( - 'https://live.bilibili.com/h5/${_liveRoomController.roomId}', - off: true, - ); - }, + onTap: () => PageUtils.inAppWebview( + 'https://live.bilibili.com/h5/${_liveRoomController.roomId}', + off: true, + ), child: const Row( mainAxisSize: MainAxisSize.min, children: [ @@ -590,9 +587,7 @@ class _LiveRoomPageState extends State ), ), IconButton( - onPressed: () { - onSendDanmaku(true); - }, + onPressed: () => onSendDanmaku(true), icon: Icon(Icons.emoji_emotions_outlined, color: _color), ), ], diff --git a/lib/pages/live_room/widgets/bottom_control.dart b/lib/pages/live_room/widgets/bottom_control.dart index 949c927d6..cc5b47ef7 100644 --- a/lib/pages/live_room/widgets/bottom_control.dart +++ b/lib/pages/live_room/widgets/bottom_control.dart @@ -80,9 +80,7 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget { height: 35, padding: const EdgeInsets.only(left: 30), value: boxFit, - onTap: () { - plPlayerController.toggleVideoFit(boxFit); - }, + onTap: () => plPlayerController.toggleVideoFit(boxFit), child: Text( boxFit.desc, style: @@ -116,9 +114,7 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget { height: 35, padding: const EdgeInsets.only(left: 30), value: e['code'], - onTap: () { - liveRoomCtr.changeQn(e['code']); - }, + onTap: () => liveRoomCtr.changeQn(e['code']), child: Text( e['desc'], style: diff --git a/lib/pages/live_room/widgets/chat.dart b/lib/pages/live_room/widgets/chat.dart index 4a605fe78..a6f9ee6db 100644 --- a/lib/pages/live_room/widgets/chat.dart +++ b/lib/pages/live_room/widgets/chat.dart @@ -90,10 +90,9 @@ class LiveRoomChat extends StatelessWidget { size: 20, ), label: const Text('回到底部'), - onPressed: () { - liveRoomController.disableAutoScroll.value = false; - liveRoomController.scrollToBottom(); - }, + onPressed: () => liveRoomController + ..disableAutoScroll.value = false + ..scrollToBottom(), ), ) : const SizedBox.shrink(), diff --git a/lib/pages/live_search/widgets/live_search_room.dart b/lib/pages/live_search/widgets/live_search_room.dart index 6a9c0b8fb..32dcebbd8 100644 --- a/lib/pages/live_search/widgets/live_search_room.dart +++ b/lib/pages/live_search/widgets/live_search_room.dart @@ -22,9 +22,7 @@ class LiveCardVSearch extends StatelessWidget { clipBehavior: Clip.hardEdge, margin: EdgeInsets.zero, child: InkWell( - onTap: () { - Get.toNamed('/liveRoom?roomid=${item.roomid}'); - }, + onTap: () => Get.toNamed('/liveRoom?roomid=${item.roomid}'), onLongPress: () => imageSaveDialog( title: item.title, cover: item.cover, diff --git a/lib/pages/login/view.dart b/lib/pages/login/view.dart index d562ef7f2..645a6d23b 100644 --- a/lib/pages/login/view.dart +++ b/lib/pages/login/view.dart @@ -112,11 +112,9 @@ class _LoginPageState extends State { style: TextStyle(color: theme.colorScheme.secondaryFixedDim), )), Obx(() => GestureDetector( - onTap: () { - // 复制到剪贴板 - Utils.copyText(_loginPageCtr.codeInfo['data']?['url'] ?? '', - toastText: '已复制到剪贴板,可粘贴至已登录的app私信处发送,然后点击已发送的链接打开'); - }, + onTap: () => Utils.copyText( + _loginPageCtr.codeInfo['data']?['url'] ?? '', + toastText: '已复制到剪贴板,可粘贴至已登录的app私信处发送,然后点击已发送的链接打开'), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20), @@ -252,44 +250,42 @@ class _LoginPageState extends State { padding: EdgeInsets.fromLTRB(25, 0, 25, 10), child: Text("试试扫码、手机号登录,或选择")), ListTile( - title: const Text( - '找回密码(手机版)', - ), - leading: const Icon(Icons.smartphone_outlined), - subtitle: const Text( - 'https://passport.bilibili.com/h5-app/passport/login/findPassword', - ), - dense: false, - onTap: () async { - Get - ..back() - ..toNamed('/webview', parameters: { - 'url': - 'https://passport.bilibili.com/h5-app/passport/login/findPassword', - 'type': 'url', - 'pageTitle': '忘记密码', - }); + title: const Text( + '找回密码(手机版)', + ), + leading: const Icon(Icons.smartphone_outlined), + subtitle: const Text( + 'https://passport.bilibili.com/h5-app/passport/login/findPassword', + ), + dense: false, + onTap: () => Get + ..back() + ..toNamed('/webview', parameters: { + 'url': + 'https://passport.bilibili.com/h5-app/passport/login/findPassword', + 'type': 'url', + 'pageTitle': '忘记密码', }), + ), ListTile( - title: const Text( - '找回密码(电脑版)', - ), - leading: const Icon(Icons.desktop_windows_outlined), - subtitle: const Text( - 'https://passport.bilibili.com/pc/passport/findPassword', - ), - dense: false, - onTap: () { - Get - ..back() - ..toNamed('/webview', parameters: { - 'url': - 'https://passport.bilibili.com/pc/passport/findPassword', - 'type': 'url', - 'pageTitle': '忘记密码', - 'uaType': 'pc' - }); + title: const Text( + '找回密码(电脑版)', + ), + leading: const Icon(Icons.desktop_windows_outlined), + subtitle: const Text( + 'https://passport.bilibili.com/pc/passport/findPassword', + ), + dense: false, + onTap: () => Get + ..back() + ..toNamed('/webview', parameters: { + 'url': + 'https://passport.bilibili.com/pc/passport/findPassword', + 'type': 'url', + 'pageTitle': '忘记密码', + 'uaType': 'pc' }), + ), ], ); }, @@ -353,11 +349,9 @@ class _LoginPageState extends State { .internationalDialingPrefix .map((Map item) { return PopupMenuItem>( - onTap: () { - setState(() { - _loginPageCtr.selectedCountryCodeId = item; - }); - }, + onTap: () => setState(() { + _loginPageCtr.selectedCountryCodeId = item; + }), value: item, child: Row(children: [ Text(item['cname']), diff --git a/lib/pages/media/view.dart b/lib/pages/media/view.dart index 49acc107a..29741973f 100644 --- a/lib/pages/media/view.dart +++ b/lib/pages/media/view.dart @@ -68,9 +68,7 @@ class _MediaPageState extends CommonPageState ), trailing: IconButton( tooltip: '设置', - onPressed: () { - Get.toNamed('/setting'); - }, + onPressed: () => Get.toNamed('/setting'), icon: const Icon( Icons.settings_outlined, size: 20, diff --git a/lib/pages/member/controller.dart b/lib/pages/member/controller.dart index 2923bff69..6670d4b65 100644 --- a/lib/pages/member/controller.dart +++ b/lib/pages/member/controller.dart @@ -246,4 +246,15 @@ class MemberController extends CommonDataController SmartDialog.showToast(res['msg']); } } + + void onTapTab(int value) { + if (tabController?.indexIsChanging == false && + key.currentState?.outerController.hasClients == true) { + key.currentState!.outerController.animateTo( + key.currentState!.outerController.offset, + duration: const Duration(milliseconds: 500), + curve: Curves.easeInOut, + ); + } + } } diff --git a/lib/pages/member/view.dart b/lib/pages/member/view.dart index 61d108b25..9db29d9ea 100644 --- a/lib/pages/member/view.dart +++ b/lib/pages/member/view.dart @@ -11,7 +11,6 @@ import 'package:PiliPlus/pages/member_dynamics/view.dart'; import 'package:PiliPlus/pages/member_favorite/view.dart'; import 'package:PiliPlus/pages/member_home/view.dart'; import 'package:PiliPlus/pages/member_pgc/view.dart'; -import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/utils.dart'; import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart'; import 'package:flutter/material.dart'; @@ -124,22 +123,20 @@ class _MemberPageState extends State { _userController.mid != _userController.ownerMid) ...[ const PopupMenuDivider(), PopupMenuItem( - onTap: () { - showDialog( - context: context, - builder: (context) => AlertDialog( - clipBehavior: Clip.hardEdge, - contentPadding: const EdgeInsets.symmetric( - horizontal: 20, - vertical: 16, - ), - content: MemberReportPanel( - name: _userController.username, - mid: _mid, - ), + onTap: () => showDialog( + context: context, + builder: (context) => AlertDialog( + clipBehavior: Clip.hardEdge, + contentPadding: const EdgeInsets.symmetric( + horizontal: 20, + vertical: 16, ), - ); - }, + content: MemberReportPanel( + name: _userController.username, + mid: _mid, + ), + ), + ), child: Row( mainAxisSize: MainAxisSize.min, children: [ @@ -209,11 +206,7 @@ class _MemberPageState extends State { child: TabBar( controller: _userController.tabController, tabs: _userController.tabs, - onTap: (value) { - if (_userController.tabController?.indexIsChanging == false) { - _userController.key.currentState?.outerController.animToTop(); - } - }, + onTap: _userController.onTapTab, ), ); diff --git a/lib/pages/member/widget/user_info_card.dart b/lib/pages/member/widget/user_info_card.dart index d7037f37b..f0fbf96eb 100644 --- a/lib/pages/member/widget/user_info_card.dart +++ b/lib/pages/member/widget/user_info_card.dart @@ -80,11 +80,9 @@ class UserInfoCard extends StatelessWidget { return Hero( tag: imgUrl, child: GestureDetector( - onTap: () { - context.imageView( - imgList: [SourceModel(url: imgUrl)], - ); - }, + onTap: () => context.imageView( + imgList: [SourceModel(url: imgUrl)], + ), child: CachedNetworkImage( imageUrl: Utils.thumbnailImgUrl(imgUrl), width: double.infinity, @@ -233,9 +231,7 @@ class UserInfoCard extends StatelessWidget { crossAxisAlignment: WrapCrossAlignment.end, children: [ GestureDetector( - onTap: () { - Utils.copyText(card.mid.toString()); - }, + onTap: () => Utils.copyText(card.mid.toString()), child: Text( 'UID: ${card.mid}', style: TextStyle( diff --git a/lib/pages/member_article/widget/item.dart b/lib/pages/member_article/widget/item.dart index 579d373c7..eab9dd6c1 100644 --- a/lib/pages/member_article/widget/item.dart +++ b/lib/pages/member_article/widget/item.dart @@ -23,12 +23,10 @@ class MemberArticleItem extends StatelessWidget { PiliScheme.routePushFromUrl(item.uri!); } }, - onLongPress: () { - imageSaveDialog( - title: item.title, - cover: item.originImageUrls?.firstOrNull, - ); - }, + onLongPress: () => imageSaveDialog( + title: item.title, + cover: item.originImageUrls?.firstOrNull, + ), child: Padding( padding: const EdgeInsets.symmetric( horizontal: StyleString.safeSpace, diff --git a/lib/pages/member_favorite/widget/item.dart b/lib/pages/member_favorite/widget/item.dart index 75adb6f1e..2b3db0198 100644 --- a/lib/pages/member_favorite/widget/item.dart +++ b/lib/pages/member_favorite/widget/item.dart @@ -58,12 +58,10 @@ class MemberFavItem extends StatelessWidget { ); } }, - onLongPress: () { - imageSaveDialog( - title: item.title, - cover: item.cover, - ); - }, + onLongPress: () => imageSaveDialog( + title: item.title, + cover: item.cover, + ), child: Padding( padding: const EdgeInsets.symmetric( horizontal: StyleString.safeSpace, diff --git a/lib/pages/member_home/widget/fav_item.dart b/lib/pages/member_home/widget/fav_item.dart index df0fd2b84..872f7207f 100644 --- a/lib/pages/member_home/widget/fav_item.dart +++ b/lib/pages/member_home/widget/fav_item.dart @@ -26,12 +26,10 @@ class MemberFavItem extends StatelessWidget { ); } }, - onLongPress: () { - imageSaveDialog( - title: item['title'], - cover: item['cover'], - ); - }, + onLongPress: () => imageSaveDialog( + title: item['title'], + cover: item['cover'], + ), child: Padding( padding: const EdgeInsets.symmetric( horizontal: StyleString.safeSpace, diff --git a/lib/pages/member_opus/view.dart b/lib/pages/member_opus/view.dart index 8df61e0c7..1f78ce982 100644 --- a/lib/pages/member_opus/view.dart +++ b/lib/pages/member_opus/view.dart @@ -63,45 +63,43 @@ class _MemberOpusState extends State right: 16, bottom: MediaQuery.paddingOf(context).bottom + 16, child: FloatingActionButton.extended( - onPressed: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - clipBehavior: Clip.hardEdge, - contentPadding: const EdgeInsets.symmetric(vertical: 12), - content: Column( - mainAxisSize: MainAxisSize.min, - children: _controller.filter! - .map( - (e) => ListTile( - onTap: () { - if (e == _controller.type.value) { - return; - } - Get.back(); - _controller - ..type.value = e - ..onReload(); - }, - tileColor: e == _controller.type.value - ? Theme.of(context) - .colorScheme - .onInverseSurface - : null, - dense: true, - title: Text( - e.text ?? e.tabName!, - style: const TextStyle(fontSize: 14), - ), + onPressed: () => showDialog( + context: context, + builder: (context) { + return AlertDialog( + clipBehavior: Clip.hardEdge, + contentPadding: const EdgeInsets.symmetric(vertical: 12), + content: Column( + mainAxisSize: MainAxisSize.min, + children: _controller.filter! + .map( + (e) => ListTile( + onTap: () { + if (e == _controller.type.value) { + return; + } + Get.back(); + _controller + ..type.value = e + ..onReload(); + }, + tileColor: e == _controller.type.value + ? Theme.of(context) + .colorScheme + .onInverseSurface + : null, + dense: true, + title: Text( + e.text ?? e.tabName!, + style: const TextStyle(fontSize: 14), ), - ) - .toList(), - ), - ); - }, - ); - }, + ), + ) + .toList(), + ), + ); + }, + ), icon: const Icon(size: 20, Icons.sort), label: Obx( () => Text(_controller.type.value.text ?? diff --git a/lib/pages/member_opus/widgets/space_opus_item.dart b/lib/pages/member_opus/widgets/space_opus_item.dart index 80cc75967..59de7c994 100644 --- a/lib/pages/member_opus/widgets/space_opus_item.dart +++ b/lib/pages/member_opus/widgets/space_opus_item.dart @@ -23,9 +23,7 @@ class SpaceOpusItem extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(6)), ), child: InkWell( - onTap: () { - PageUtils.pushDynFromId(id: item.opusId!); - }, + onTap: () => PageUtils.pushDynFromId(id: item.opusId!), borderRadius: const BorderRadius.all(Radius.circular(6)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, diff --git a/lib/pages/member_profile/view.dart b/lib/pages/member_profile/view.dart index 2343bec69..9b61755c7 100644 --- a/lib/pages/member_profile/view.dart +++ b/lib/pages/member_profile/view.dart @@ -106,12 +106,10 @@ class _EditProfilePageState extends State { ), ), ), - onTap: () { - EasyThrottle.throttle( - 'imagePicker', const Duration(milliseconds: 500), () { - _pickImg(theme); - }); - }, + onTap: () => EasyThrottle.throttle( + 'imagePicker', const Duration(milliseconds: 500), () { + _pickImg(theme); + }), ), divider, _item( @@ -135,46 +133,40 @@ class _EditProfilePageState extends State { theme: theme, title: '性别', text: _sex(response['sex']), - onTap: () { - showDialog( - context: context, - builder: (context_) => _sexDialog(response['sex']), - ); - }, + onTap: () => showDialog( + context: context, + builder: (context_) => _sexDialog(response['sex']), + ), ), divider, _item( theme: theme, title: '出生年月', text: response['birthday'], - onTap: () { - showDatePicker( - context: context, - initialDate: DateTime.parse(response['birthday']), - firstDate: DateTime(1900, 1, 1), - lastDate: DateTime.now(), - ).then((date) { - if (date != null) { - _update( - type: ProfileType.birthday, - datum: DateFormat('yyyy-MM-dd').format(date), - ); - } - }); - }, + onTap: () => showDatePicker( + context: context, + initialDate: DateTime.parse(response['birthday']), + firstDate: DateTime(1900, 1, 1), + lastDate: DateTime.now(), + ).then((date) { + if (date != null) { + _update( + type: ProfileType.birthday, + datum: DateFormat('yyyy-MM-dd').format(date), + ); + } + }), ), divider, _item( theme: theme, title: '个性签名', text: response['sign'].isEmpty ? '无' : response['sign'], - onTap: () { - _editDialog( - type: ProfileType.sign, - title: '个性签名', - text: response['sign'], - ); - }, + onTap: () => _editDialog( + type: ProfileType.sign, + title: '个性签名', + text: response['sign'], + ), ), divider1, _item( @@ -299,7 +291,7 @@ class _EditProfilePageState extends State { ], ); }, - ).then((_) { + ).whenComplete(() { _textController.clear(); }); } diff --git a/lib/pages/member_season_series/widget/season_series_card.dart b/lib/pages/member_season_series/widget/season_series_card.dart index f88bd0d46..d269c8336 100644 --- a/lib/pages/member_season_series/widget/season_series_card.dart +++ b/lib/pages/member_season_series/widget/season_series_card.dart @@ -17,12 +17,10 @@ class SeasonSeriesCard extends StatelessWidget { @override Widget build(BuildContext context) { return InkWell( - onLongPress: () { - imageSaveDialog( - title: item['meta']['name'], - cover: item['meta']['cover'], - ); - }, + onLongPress: () => imageSaveDialog( + title: item['meta']['name'], + cover: item['meta']['cover'], + ), onTap: onTap, child: Padding( padding: const EdgeInsets.symmetric( diff --git a/lib/pages/member_video/view.dart b/lib/pages/member_video/view.dart index 0e2016652..4856e7a0f 100644 --- a/lib/pages/member_video/view.dart +++ b/lib/pages/member_video/view.dart @@ -88,14 +88,12 @@ class _MemberVideoState extends State top: false, left: false, child: FloatingActionButton.extended( - onPressed: () { - _controller - ..isLocating.value = true - ..lastAid = _controller.fromViewAid - ..page = 0 - ..loadingState.value = LoadingState.loading() - ..queryData(); - }, + onPressed: () => _controller + ..isLocating.value = true + ..lastAid = _controller.fromViewAid + ..page = 0 + ..loadingState.value = LoadingState.loading() + ..queryData(), label: const Text('定位至上次观看'), ), ), diff --git a/lib/pages/msg_feed_top/at_me/view.dart b/lib/pages/msg_feed_top/at_me/view.dart index 3346db379..fdbf8e1bf 100644 --- a/lib/pages/msg_feed_top/at_me/view.dart +++ b/lib/pages/msg_feed_top/at_me/view.dart @@ -33,12 +33,10 @@ class _AtMePageState extends State { title: const Text('@我的'), actions: [ IconButton( - onPressed: () { - Get.to( - const WhisperSettingsPage( - imSettingType: IMSettingType.SETTING_TYPE_OLD_AT_ME), - ); - }, + onPressed: () => Get.to( + const WhisperSettingsPage( + imSettingType: IMSettingType.SETTING_TYPE_OLD_AT_ME), + ), icon: Icon( size: 20, Icons.settings, @@ -89,19 +87,13 @@ class _AtMePageState extends State { PiliScheme.routePushFromUrl(nativeUri); } }, - onLongPress: () { - showConfirmDialog( - context: context, - title: '确定删除该通知?', - onConfirm: () { - _atMeController.onRemove(item.id, index); - }, - ); - }, + onLongPress: () => showConfirmDialog( + context: context, + title: '确定删除该通知?', + onConfirm: () => _atMeController.onRemove(item.id, index), + ), leading: GestureDetector( - onTap: () { - Get.toNamed('/member?mid=${item.user?.mid}'); - }, + onTap: () => Get.toNamed('/member?mid=${item.user?.mid}'), child: NetworkImgLayer( width: 45, height: 45, diff --git a/lib/pages/msg_feed_top/like_me/view.dart b/lib/pages/msg_feed_top/like_me/view.dart index 3c26623e6..cb1756777 100644 --- a/lib/pages/msg_feed_top/like_me/view.dart +++ b/lib/pages/msg_feed_top/like_me/view.dart @@ -34,12 +34,10 @@ class _LikeMePageState extends State { title: const Text('收到的赞'), actions: [ IconButton( - onPressed: () { - Get.to( - const WhisperSettingsPage( - imSettingType: IMSettingType.SETTING_TYPE_OLD_RECEIVE_LIKE), - ); - }, + onPressed: () => Get.to( + const WhisperSettingsPage( + imSettingType: IMSettingType.SETTING_TYPE_OLD_RECEIVE_LIKE), + ), icon: Icon( size: 20, Icons.settings, @@ -184,63 +182,57 @@ class _LikeMePageState extends State { PiliScheme.routePushFromUrl(nativeUri); } }, - onLongPress: () { - showDialog( - context: context, - builder: (context) { - final isNotice = item.noticeState == 0; - return AlertDialog( - clipBehavior: Clip.hardEdge, - contentPadding: const EdgeInsets.symmetric(vertical: 12), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - ListTile( - onTap: () { - Get.back(); + onLongPress: () => showDialog( + context: context, + builder: (context) { + final isNotice = item.noticeState == 0; + return AlertDialog( + clipBehavior: Clip.hardEdge, + contentPadding: const EdgeInsets.symmetric(vertical: 12), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + onTap: () { + Get.back(); + showConfirmDialog( + context: context, + title: '删除', + content: '该条通知删除后,当有新点赞时会重新出现在列表,是否继续?', + onConfirm: () => onRemove(item.id), + ); + }, + dense: true, + title: const Text( + '删除', + style: TextStyle(fontSize: 14), + ), + ), + ListTile( + onTap: () { + Get.back(); + if (isNotice) { showConfirmDialog( context: context, - title: '删除', - content: '该条通知删除后,当有新点赞时会重新出现在列表,是否继续?', - onConfirm: () { - onRemove(item.id); - }, + title: '不再通知', + content: '这条内容的点赞将不再通知,但仍可在列表内查看,是否继续?', + onConfirm: () => onSetNotice(isNotice, item.id), ); - }, - dense: true, - title: const Text( - '删除', - style: TextStyle(fontSize: 14), - ), + } else { + onSetNotice(isNotice, item.id); + } + }, + dense: true, + title: Text( + isNotice ? '不再通知' : '接收通知', + style: const TextStyle(fontSize: 14), ), - ListTile( - onTap: () { - Get.back(); - if (isNotice) { - showConfirmDialog( - context: context, - title: '不再通知', - content: '这条内容的点赞将不再通知,但仍可在列表内查看,是否继续?', - onConfirm: () { - onSetNotice(isNotice, item.id); - }, - ); - } else { - onSetNotice(isNotice, item.id); - } - }, - dense: true, - title: Text( - isNotice ? '不再通知' : '接收通知', - style: const TextStyle(fontSize: 14), - ), - ), - ], - ), - ); - }, - ); - }, + ), + ], + ), + ); + }, + ), leading: Column( children: [ const Spacer(), diff --git a/lib/pages/msg_feed_top/reply_me/view.dart b/lib/pages/msg_feed_top/reply_me/view.dart index 7e1612a24..152bb2ef7 100644 --- a/lib/pages/msg_feed_top/reply_me/view.dart +++ b/lib/pages/msg_feed_top/reply_me/view.dart @@ -33,12 +33,10 @@ class _ReplyMePageState extends State { title: const Text('回复我的'), actions: [ IconButton( - onPressed: () { - Get.to( - const WhisperSettingsPage( - imSettingType: IMSettingType.SETTING_TYPE_OLD_REPLY_ME), - ); - }, + onPressed: () => Get.to( + const WhisperSettingsPage( + imSettingType: IMSettingType.SETTING_TYPE_OLD_REPLY_ME), + ), icon: Icon( size: 20, Icons.settings, @@ -94,19 +92,14 @@ class _ReplyMePageState extends State { ); } }, - onLongPress: () { - showConfirmDialog( - context: context, - title: '确定删除该通知?', - onConfirm: () { - _replyMeController.onRemove(item.id, index); - }, - ); - }, + onLongPress: () => showConfirmDialog( + context: context, + title: '确定删除该通知?', + onConfirm: () => + _replyMeController.onRemove(item.id, index), + ), leading: GestureDetector( - onTap: () { - Get.toNamed('/member?mid=${item.user?.mid}'); - }, + onTap: () => Get.toNamed('/member?mid=${item.user?.mid}'), child: NetworkImgLayer( width: 45, height: 45, diff --git a/lib/pages/msg_feed_top/sys_msg/view.dart b/lib/pages/msg_feed_top/sys_msg/view.dart index 2fa999fe3..a988ec928 100644 --- a/lib/pages/msg_feed_top/sys_msg/view.dart +++ b/lib/pages/msg_feed_top/sys_msg/view.dart @@ -79,15 +79,11 @@ class _SysMsgPageState extends State { } catch (_) {} } return ListTile( - onLongPress: () { - showConfirmDialog( - context: context, - title: '确定删除该通知?', - onConfirm: () { - _sysMsgController.onRemove(item.id, index); - }, - ); - }, + onLongPress: () => showConfirmDialog( + context: context, + title: '确定删除该通知?', + onConfirm: () => _sysMsgController.onRemove(item.id, index), + ), title: Text( "${item.title}", style: theme.textTheme.titleMedium, diff --git a/lib/pages/pgc_index/view.dart b/lib/pages/pgc_index/view.dart index d384e93fb..b7e954279 100644 --- a/lib/pages/pgc_index/view.dart +++ b/lib/pages/pgc_index/view.dart @@ -7,7 +7,6 @@ import 'package:PiliPlus/models/bangumi/pgc_index/condition.dart'; import 'package:PiliPlus/pages/bangumi/widgets/bangumi_card_v_pgc_index.dart'; import 'package:PiliPlus/pages/pgc_index/controller.dart'; import 'package:PiliPlus/pages/search/widgets/search_text.dart'; -import 'package:PiliPlus/utils/extension.dart'; import 'package:PiliPlus/utils/grid.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -82,10 +81,9 @@ class _PgcIndexPageState extends State }), Error(:var errMsg) => scrollErrorWidget( errMsg: errMsg, - onReload: () { - _ctr.conditionState.value = LoadingState.loading(); - _ctr.getPgcIndexCondition(); - }, + onReload: () => _ctr + ..conditionState.value = LoadingState.loading() + ..getPgcIndexCondition(), ), }; } @@ -175,9 +173,7 @@ class _PgcIndexPageState extends State const SizedBox(height: 8), GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - _ctr.isExpand.value = _ctr.isExpand.value.not; - }, + onTap: () => _ctr.isExpand.value = !_ctr.isExpand.value, child: Container( alignment: Alignment.center, child: Row( diff --git a/lib/pages/rank/zone/widget/pgc_rank_item.dart b/lib/pages/rank/zone/widget/pgc_rank_item.dart index 870719534..fc352389f 100644 --- a/lib/pages/rank/zone/widget/pgc_rank_item.dart +++ b/lib/pages/rank/zone/widget/pgc_rank_item.dart @@ -21,12 +21,10 @@ class PgcRankItem extends StatelessWidget { PiliScheme.routePushFromUrl(item.url!); } }, - onLongPress: () { - imageSaveDialog( - title: item.title, - cover: item.cover, - ); - }, + onLongPress: () => imageSaveDialog( + title: item.title, + cover: item.cover, + ), child: Padding( padding: const EdgeInsets.symmetric( horizontal: StyleString.safeSpace, diff --git a/lib/pages/rcmd/view.dart b/lib/pages/rcmd/view.dart index de12cb530..c403b83c4 100644 --- a/lib/pages/rcmd/view.dart +++ b/lib/pages/rcmd/view.dart @@ -71,11 +71,9 @@ class _RcmdPageState extends CommonPageState if (controller.lastRefreshAt != null) { if (controller.lastRefreshAt == index) { return GestureDetector( - onTap: () { - controller - ..animateToTop() - ..onRefresh(); - }, + onTap: () => controller + ..animateToTop() + ..onRefresh(), child: Card( margin: EdgeInsets.zero, child: Container( diff --git a/lib/pages/search/view.dart b/lib/pages/search/view.dart index f3135ba20..d0c98e7e6 100644 --- a/lib/pages/search/view.dart +++ b/lib/pages/search/view.dart @@ -43,10 +43,8 @@ class _SearchPageState extends State { ? IconButton( tooltip: 'UID搜索用户', icon: const Icon(Icons.person_outline, size: 22), - onPressed: () { - Get.toNamed( - '/member?mid=${_searchController.controller.text}'); - }, + onPressed: () => Get.toNamed( + '/member?mid=${_searchController.controller.text}'), ) : const SizedBox.shrink(), ), @@ -167,12 +165,10 @@ class _SearchPageState extends State { child: SizedBox( height: 34, child: TextButton.icon( - onPressed: () { - Get.toNamed( - '/searchTrending', - parameters: {'tag': _tag}, - ); - }, + onPressed: () => Get.toNamed( + '/searchTrending', + parameters: {'tag': _tag}, + ), label: Text( '完整榜单', style: TextStyle( diff --git a/lib/pages/search/widgets/search_text.dart b/lib/pages/search/widgets/search_text.dart index 389ce5743..d41b197e2 100644 --- a/lib/pages/search/widgets/search_text.dart +++ b/lib/pages/search/widgets/search_text.dart @@ -29,14 +29,8 @@ class SearchText extends StatelessWidget { color: bgColor ?? theme.colorScheme.onInverseSurface, borderRadius: const BorderRadius.all(Radius.circular(6)), child: InkWell( - onTap: () { - onTap?.call(text); - }, - onLongPress: onLongPress != null - ? () { - onLongPress!(text); - } - : null, + onTap: () => onTap?.call(text), + onLongPress: onLongPress != null ? () => onLongPress!(text) : null, borderRadius: const BorderRadius.all(Radius.circular(6)), child: Padding( padding: padding ?? diff --git a/lib/pages/search_panel/article/controller.dart b/lib/pages/search_panel/article/controller.dart index 6f9eca071..308d0a578 100644 --- a/lib/pages/search_panel/article/controller.dart +++ b/lib/pages/search_panel/article/controller.dart @@ -83,9 +83,10 @@ class SearchArticleController child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, - spacing: 10, children: [ + const SizedBox(height: 10), const Text('排序', style: TextStyle(fontSize: 16)), + const SizedBox(height: 10), Wrap( spacing: 8, runSpacing: 8, @@ -114,7 +115,9 @@ class SearchArticleController ) .toList(), ), + const SizedBox(height: 20), const Text('分区', style: TextStyle(fontSize: 16)), + const SizedBox(height: 10), Wrap( spacing: 8, runSpacing: 8, diff --git a/lib/pages/search_panel/article/view.dart b/lib/pages/search_panel/article/view.dart index 3005d63c9..953296ca7 100644 --- a/lib/pages/search_panel/article/view.dart +++ b/lib/pages/search_panel/article/view.dart @@ -68,9 +68,7 @@ class _SearchArticlePanelState extends CommonSearchPanelState< style: ButtonStyle( padding: WidgetStateProperty.all(EdgeInsets.zero), ), - onPressed: () { - controller.onShowFilterDialog(context); - }, + onPressed: () => controller.onShowFilterDialog(context), icon: Icon( Icons.filter_list_outlined, size: 18, diff --git a/lib/pages/search_panel/article/widgets/item.dart b/lib/pages/search_panel/article/widgets/item.dart index 739e6adde..edbf1f403 100644 --- a/lib/pages/search_panel/article/widgets/item.dart +++ b/lib/pages/search_panel/article/widgets/item.dart @@ -19,15 +19,13 @@ class SearchArticleItem extends StatelessWidget { color: theme.colorScheme.outline, ); return InkWell( - onTap: () { - Get.toNamed( - '/articlePage', - parameters: { - 'id': '${item.id}', - 'type': 'read', - }, - ); - }, + onTap: () => Get.toNamed( + '/articlePage', + parameters: { + 'id': '${item.id}', + 'type': 'read', + }, + ), onLongPress: () => imageSaveDialog( title: item.title?.map((item) => item['text']).join() ?? '', cover: item.imageUrls?.firstOrNull, diff --git a/lib/pages/search_panel/live/widgets/item.dart b/lib/pages/search_panel/live/widgets/item.dart index f960f2ee7..b006ea7ca 100644 --- a/lib/pages/search_panel/live/widgets/item.dart +++ b/lib/pages/search_panel/live/widgets/item.dart @@ -19,9 +19,7 @@ class LiveItem extends StatelessWidget { clipBehavior: Clip.hardEdge, margin: EdgeInsets.zero, child: InkWell( - onTap: () { - Get.toNamed('/liveRoom?roomid=${liveItem.roomid}'); - }, + onTap: () => Get.toNamed('/liveRoom?roomid=${liveItem.roomid}'), onLongPress: () => imageSaveDialog( title: liveItem.title?.map((item) => item['text']).join() ?? '', cover: liveItem.cover, diff --git a/lib/pages/search_panel/pgc/widgets/item.dart b/lib/pages/search_panel/pgc/widgets/item.dart index 18a062cad..896f8c0b5 100644 --- a/lib/pages/search_panel/pgc/widgets/item.dart +++ b/lib/pages/search_panel/pgc/widgets/item.dart @@ -20,9 +20,7 @@ class SearchPgcItem extends StatelessWidget { final ThemeData theme = Theme.of(context); const TextStyle style = TextStyle(fontSize: 13); return InkWell( - onTap: () { - PageUtils.viewBangumi(seasonId: item.seasonId); - }, + onTap: () => PageUtils.viewBangumi(seasonId: item.seasonId), onLongPress: () => imageSaveDialog( title: item.title?.map((item) => item['text']).join() ?? '', cover: item.cover, diff --git a/lib/pages/search_panel/user/view.dart b/lib/pages/search_panel/user/view.dart index 83b907a74..8d83aeea9 100644 --- a/lib/pages/search_panel/user/view.dart +++ b/lib/pages/search_panel/user/view.dart @@ -68,9 +68,7 @@ class _SearchUserPanelState extends CommonSearchPanelState controller.onShowFilterDialog(context), icon: Icon( Icons.filter_list_outlined, size: 18, diff --git a/lib/pages/search_trending/view.dart b/lib/pages/search_trending/view.dart index 10edf8f0e..2e6a3b5bf 100644 --- a/lib/pages/search_trending/view.dart +++ b/lib/pages/search_trending/view.dart @@ -148,14 +148,12 @@ class _SearchTrendingPageState extends State { final item = response[index]; return ListTile( dense: true, - onTap: () { - Get.toNamed( - '/searchResult', - parameters: { - 'keyword': item.keyword!, - }, - ); - }, + onTap: () => Get.toNamed( + '/searchResult', + parameters: { + 'keyword': item.keyword!, + }, + ), leading: index < _controller.topCount ? const Icon( size: 17, diff --git a/lib/pages/setting/widgets/normal_item.dart b/lib/pages/setting/widgets/normal_item.dart index a131709d0..7b8285543 100644 --- a/lib/pages/setting/widgets/normal_item.dart +++ b/lib/pages/setting/widgets/normal_item.dart @@ -41,11 +41,9 @@ class _NormalItemState extends State { Widget build(BuildContext context) { return ListTile( contentPadding: widget.contentPadding, - onTap: () { - widget.onTap?.call(() { - setState(() {}); - }); - }, + onTap: () => widget.onTap?.call(() { + setState(() {}); + }), title: Text(widget.title ?? widget.getTitle?.call(), style: widget.titleStyle ?? Theme.of(context).textTheme.titleMedium!), subtitle: widget.subtitle != null || widget.getSubtitle != null diff --git a/lib/pages/sponsor_block/view.dart b/lib/pages/sponsor_block/view.dart index 22e24f71b..f6a61c779 100644 --- a/lib/pages/sponsor_block/view.dart +++ b/lib/pages/sponsor_block/view.dart @@ -358,6 +358,54 @@ class _SponsorBlockPageState extends State { ), ); + void onSelectColor(int index) { + showDialog( + context: context, + builder: (context) => AlertDialog( + clipBehavior: Clip.hardEdge, + contentPadding: const EdgeInsets.symmetric(vertical: 16), + title: Text.rich( + TextSpan( + children: [ + const TextSpan( + text: 'Color Picker ', + style: TextStyle(fontSize: 15), + ), + WidgetSpan( + alignment: PlaceholderAlignment.middle, + child: Container( + height: 10, + width: 10, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: _blockColor[index], + ), + ), + style: const TextStyle(fontSize: 13, height: 1), + ), + TextSpan( + text: ' ${_blockSettings[index].first.title}', + style: const TextStyle(fontSize: 13, height: 1), + ), + ], + ), + ), + content: SlideColorPicker( + color: _blockColor[index], + callback: (Color? color) { + _blockColor[index] = color ?? _blockSettings[index].first.color; + setting.put( + SettingBoxKey.blockColor, + _blockColor + .map((item) => item.value.toRadixString(16).substring(2)) + .toList()); + setState(() {}); + }, + ), + ), + ); + } + @override Widget build(BuildContext context) { final theme = Theme.of(context); @@ -402,55 +450,7 @@ class _SponsorBlockPageState extends State { itemBuilder: (context, index) => ListTile( dense: true, enabled: _blockSettings[index].second != SkipType.disable, - onTap: () { - showDialog( - context: context, - builder: (context) => AlertDialog( - clipBehavior: Clip.hardEdge, - contentPadding: const EdgeInsets.symmetric(vertical: 16), - title: Text.rich( - TextSpan( - children: [ - const TextSpan( - text: 'Color Picker ', - style: TextStyle(fontSize: 15), - ), - WidgetSpan( - alignment: PlaceholderAlignment.middle, - child: Container( - height: 10, - width: 10, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: _blockColor[index], - ), - ), - style: const TextStyle(fontSize: 13, height: 1), - ), - TextSpan( - text: ' ${_blockSettings[index].first.title}', - style: const TextStyle(fontSize: 13, height: 1), - ), - ], - ), - ), - content: SlideColorPicker( - color: _blockColor[index], - callback: (Color? color) { - _blockColor[index] = - color ?? _blockSettings[index].first.color; - setting.put( - SettingBoxKey.blockColor, - _blockColor - .map((item) => - item.value.toRadixString(16).substring(2)) - .toList()); - setState(() {}); - }, - ), - ), - ); - }, + onTap: () => onSelectColor(index), title: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ diff --git a/lib/pages/subscription/controller.dart b/lib/pages/subscription/controller.dart index bfa12327b..9c49caf02 100644 --- a/lib/pages/subscription/controller.dart +++ b/lib/pages/subscription/controller.dart @@ -36,9 +36,7 @@ class SubController content: const Text('确定取消订阅吗?'), actions: [ TextButton( - onPressed: () { - Get.back(); - }, + onPressed: Get.back, child: Text( '取消', style: TextStyle(color: Theme.of(context).colorScheme.outline), diff --git a/lib/pages/video/controller.dart b/lib/pages/video/controller.dart index 305f24b0a..294e55785 100644 --- a/lib/pages/video/controller.dart +++ b/lib/pages/video/controller.dart @@ -380,9 +380,7 @@ class VideoDetailController extends GetxController getMediaList(isReverse: true); }, loadPrevious: Get.arguments['isContinuePlaying'] == true - ? () { - return getMediaList(isLoadPrevious: true); - } + ? () => getMediaList(isLoadPrevious: true) : null, onDelete: sourceType == 'watchLater' || (sourceType == 'fav' && Get.arguments?['isOwner'] == true) @@ -744,14 +742,14 @@ class VideoDetailController extends GetxController if (segmentModel.skipType == SkipType.alwaysSkip) { _lastPos = 0; plPlayerController.videoPlayerController!.stream.buffer.first - .then((_) { + .whenComplete(() { onSkip(segmentModel); }); } else if (segmentModel.skipType == SkipType.skipOnce) { _lastPos = 0; segmentModel.hasSkipped = true; plPlayerController.videoPlayerController!.stream.buffer.first - .then((_) { + .whenComplete(() { onSkip(segmentModel); }); } else if (segmentModel.skipType == SkipType.skipManually) { diff --git a/lib/pages/video/introduction/pgc/view.dart b/lib/pages/video/introduction/pgc/view.dart index d6e4626c5..2853c9df6 100644 --- a/lib/pages/video/introduction/pgc/view.dart +++ b/lib/pages/video/introduction/pgc/view.dart @@ -397,9 +397,7 @@ class _BangumiIntroPanelState extends State ), ActionRowItem( icon: const Icon(FontAwesomeIcons.comment), - onTap: () { - videoDetailCtr.tabCtr.animateTo(1); - }, + onTap: () => videoDetailCtr.tabCtr.animateTo(1), selectStatus: false, isLoading: false, text: bangumiItem.stat!['reply']!.toString(), diff --git a/lib/pages/video/introduction/ugc/controller.dart b/lib/pages/video/introduction/ugc/controller.dart index 2cac83d09..0c853f644 100644 --- a/lib/pages/video/introduction/ugc/controller.dart +++ b/lib/pages/video/introduction/ugc/controller.dart @@ -852,7 +852,7 @@ class VideoIntroController extends GetxController { relatedCtr = Get.find(tag: heroTag); } else { relatedCtr = Get.put(RelatedController(false), tag: heroTag) - ..queryData().then((_) { + ..queryData().whenComplete(() { playRelated(); }); return false; diff --git a/lib/pages/video/introduction/ugc/view.dart b/lib/pages/video/introduction/ugc/view.dart index c515d58cd..faf6300ae 100644 --- a/lib/pages/video/introduction/ugc/view.dart +++ b/lib/pages/video/introduction/ugc/view.dart @@ -437,21 +437,19 @@ class _VideoInfoState extends State { child: InkWell( customBorder: const CircleBorder(), - onTap: () { - RequestUtils - .actionRelationMod( - context: context, - mid: videoItem['staff'] - [index] - .mid, - isFollow: false, - callback: (val) { - videoIntroController - .staffRelations[ - '${videoItem['staff'][index].mid}'] = true; - }, - ); - }, + onTap: () => RequestUtils + .actionRelationMod( + context: context, + mid: videoItem['staff'] + [index] + .mid, + isFollow: false, + callback: (val) { + videoIntroController + .staffRelations[ + '${videoItem['staff'][index].mid}'] = true; + }, + ), child: Ink( padding: const EdgeInsets.all( @@ -674,10 +672,8 @@ class _VideoInfoState extends State { children: [ const SizedBox(height: 8), GestureDetector( - onTap: () { - Utils.copyText( - '${videoIntroController.videoDetail.value.bvid}'); - }, + onTap: () => Utils.copyText( + '${videoIntroController.videoDetail.value.bvid}'), child: Text( videoIntroController.videoDetail.value.bvid ?? '', style: TextStyle( @@ -988,9 +984,7 @@ class _VideoInfoState extends State { const SizedBox(width: 8), ActionRowItem( icon: const Icon(FontAwesomeIcons.comment), - onTap: () { - videoDetailCtr.tabCtr.animateTo(1); - }, + onTap: () => videoDetailCtr.tabCtr.animateTo(1), selectStatus: false, isLoading: widget.isLoading, text: !widget.isLoading ? videoDetail.stat!.reply!.toString() : '-', @@ -1034,9 +1028,7 @@ class _VideoInfoState extends State { text: matchStr, style: TextStyle(color: theme.colorScheme.primary), recognizer: TapGestureRecognizer() - ..onTap = () { - PiliScheme.videoPush(aid, null); - }, + ..onTap = () => PiliScheme.videoPush(aid, null), ), ); } catch (e) { @@ -1051,9 +1043,7 @@ class _VideoInfoState extends State { text: matchStr, style: TextStyle(color: theme.colorScheme.primary), recognizer: TapGestureRecognizer() - ..onTap = () { - PiliScheme.videoPush(null, matchStr); - }, + ..onTap = () => PiliScheme.videoPush(null, matchStr), ), ); } catch (e) { @@ -1090,12 +1080,10 @@ class _VideoInfoState extends State { text: '@${currentDesc.rawText}', style: TextStyle(color: colorSchemePrimary), recognizer: TapGestureRecognizer() - ..onTap = () { - Get.toNamed( - '/member?mid=${currentDesc.bizId}', - arguments: {'face': '', 'heroTag': heroTag}, - ); - }, + ..onTap = () => Get.toNamed( + '/member?mid=${currentDesc.bizId}', + arguments: {'face': '', 'heroTag': heroTag}, + ), ); default: return const TextSpan(); diff --git a/lib/pages/video/introduction/ugc/widgets/action_item.dart b/lib/pages/video/introduction/ugc/widgets/action_item.dart index 801ba3e4b..06eeca2b5 100644 --- a/lib/pages/video/introduction/ugc/widgets/action_item.dart +++ b/lib/pages/video/introduction/ugc/widgets/action_item.dart @@ -10,15 +10,15 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; class ActionItem extends StatefulWidget { final Icon icon; final Icon? selectIcon; - final Function? onTap; - final Function? onLongPress; + final VoidCallback? onTap; + final VoidCallback? onLongPress; final bool? isLoading; final String? text; final bool selectStatus; final String semanticsLabel; final bool needAnim; final bool hasTriple; - final Function? callBack; + final ValueChanged? callBack; final bool? expand; const ActionItem({ @@ -145,11 +145,7 @@ class ActionItemState extends State feedBack(); widget.onTap?.call(); }, - onLongPress: _isThumbsUp - ? null - : () { - widget.onLongPress?.call(); - }, + onLongPress: _isThumbsUp ? null : widget.onLongPress, onTapDown: (details) => _isThumbsUp ? _startLongPress() : null, onTapUp: (details) => _isThumbsUp ? _cancelLongPress() : null, onTapCancel: () => _isThumbsUp ? _cancelLongPress(true) : null, diff --git a/lib/pages/video/medialist/view.dart b/lib/pages/video/medialist/view.dart index a1dae0f94..18fe6f438 100644 --- a/lib/pages/video/medialist/view.dart +++ b/lib/pages/video/medialist/view.dart @@ -171,12 +171,10 @@ class _MediaListPanelState item.cid ?? await SearchHttp.ab2c(aid: aid, bvid: bvid); widget.changeMediaList?.call(bvid, cid, aid, cover); }, - onLongPress: () { - imageSaveDialog( - title: item.title, - cover: item.cover, - ); - }, + onLongPress: () => imageSaveDialog( + title: item.title, + cover: item.cover, + ), child: Stack( clipBehavior: Clip.none, children: [ @@ -271,13 +269,11 @@ class _MediaListPanelState bottom: -6, child: InkWell( customBorder: const CircleBorder(), - onTap: () { - showConfirmDialog( - context: context, - title: '确定移除该视频?', - onConfirm: () => widget.onDelete!(index), - ); - }, + onTap: () => showConfirmDialog( + context: context, + title: '确定移除该视频?', + onConfirm: () => widget.onDelete!(index), + ), onLongPress: () => widget.onDelete!(index), child: Padding( padding: const EdgeInsets.all(9), diff --git a/lib/pages/video/member/view.dart b/lib/pages/video/member/view.dart index 157887785..b46ba26c9 100644 --- a/lib/pages/video/member/view.dart +++ b/lib/pages/video/member/view.dart @@ -142,12 +142,10 @@ class _HorizontalMemberPageState extends State { SizedBox( height: 35, child: TextButton.icon( - onPressed: () { - _controller - ..lastAid = - widget.videoDetailController.oid.value.toString() - ..queryBySort(); - }, + onPressed: () => _controller + ..lastAid = + widget.videoDetailController.oid.value.toString() + ..queryBySort(), icon: Icon( Icons.sort, size: 16, @@ -249,9 +247,7 @@ class _HorizontalMemberPageState extends State { Row( children: [ GestureDetector( - onTap: () { - Utils.copyText(memberInfoModel.name ?? ''); - }, + onTap: () => Utils.copyText(memberInfoModel.name ?? ''), child: Text( memberInfoModel.name ?? '', style: TextStyle( @@ -366,9 +362,7 @@ class _HorizontalMemberPageState extends State { padding: EdgeInsets.zero, visualDensity: const VisualDensity(vertical: -2), ), - onPressed: () { - Get.toNamed('/member?mid=${widget.mid}'); - }, + onPressed: () => Get.toNamed('/member?mid=${widget.mid}'), child: const Text( '查看主页', maxLines: 1, diff --git a/lib/pages/video/note/view.dart b/lib/pages/video/note/view.dart index 6e7b081d6..31d89e08d 100644 --- a/lib/pages/video/note/view.dart +++ b/lib/pages/video/note/view.dart @@ -204,9 +204,7 @@ Widget _itemWidget(BuildContext context, ThemeData theme, dynamic item) { crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( - onTap: () { - Get.toNamed('/member?mid=${item['author']['mid']}'); - }, + onTap: () => Get.toNamed('/member?mid=${item['author']['mid']}'), child: NetworkImgLayer( height: 34, width: 34, @@ -221,9 +219,8 @@ Widget _itemWidget(BuildContext context, ThemeData theme, dynamic item) { crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( - onTap: () { - Get.toNamed('/member?mid=${item['author']['mid']}'); - }, + onTap: () => + Get.toNamed('/member?mid=${item['author']['mid']}'), child: Row( children: [ Text( diff --git a/lib/pages/video/pay_coins/view.dart b/lib/pages/video/pay_coins/view.dart index dcd584cf1..9664e236e 100644 --- a/lib/pages/video/pay_coins/view.dart +++ b/lib/pages/video/pay_coins/view.dart @@ -247,11 +247,7 @@ class _PayCoinsPageState extends State maintainAnimation: true, maintainState: true, child: GestureDetector( - onTap: _index == 0 - ? null - : () { - _onScroll(0); - }, + onTap: _index == 0 ? null : () => _onScroll(0), child: Padding( padding: const EdgeInsets.only(left: 12), child: Image.asset( @@ -337,11 +333,7 @@ class _PayCoinsPageState extends State maintainAnimation: true, maintainState: true, child: GestureDetector( - onTap: _index == 1 - ? null - : () { - _onScroll(1); - }, + onTap: _index == 1 ? null : () => _onScroll(1), child: Padding( padding: const EdgeInsets.only(right: 12), child: Image.asset( diff --git a/lib/pages/video/post_panel/view.dart b/lib/pages/video/post_panel/view.dart index 6b1176b01..720d26d32 100644 --- a/lib/pages/video/post_panel/view.dart +++ b/lib/pages/video/post_panel/view.dart @@ -375,32 +375,30 @@ class _PostPanelState extends CommonCollapseSlidePageState { bottom: 16 + MediaQuery.paddingOf(context).bottom, child: FloatingActionButton( tooltip: '提交', - onPressed: () { - showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Text('确定无误再提交'), - actions: [ - TextButton( - onPressed: Get.back, - child: Text( - '取消', - style: TextStyle( - color: theme.colorScheme.outline, - ), + onPressed: () => showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('确定无误再提交'), + actions: [ + TextButton( + onPressed: Get.back, + child: Text( + '取消', + style: TextStyle( + color: theme.colorScheme.outline, ), ), - TextButton( - onPressed: () { - Get.back(); - _onPost(); - }, - child: const Text('确定提交'), - ), - ], - ), - ); - }, + ), + TextButton( + onPressed: () { + Get.back(); + _onPost(); + }, + child: const Text('确定提交'), + ), + ], + ), + ), child: const Icon(Icons.check), ), ) diff --git a/lib/pages/video/reply/view.dart b/lib/pages/video/reply/view.dart index 79e1a500e..49beb3f1d 100644 --- a/lib/pages/video/reply/view.dart +++ b/lib/pages/video/reply/view.dart @@ -218,13 +218,11 @@ class _VideoReplyPanelState extends State replyItem: response[index], replyLevel: widget.replyLevel, replyReply: widget.replyReply, - onReply: () { - _videoReplyController.onReply( - context, - replyItem: response[index], - index: index, - ); - }, + onReply: () => _videoReplyController.onReply( + context, + replyItem: response[index], + index: index, + ), onDelete: (subIndex) => _videoReplyController.onRemove(index, subIndex), upMid: _videoReplyController.upMid, diff --git a/lib/pages/video/reply/widgets/reply_item_grpc.dart b/lib/pages/video/reply/widgets/reply_item_grpc.dart index 034a514a2..aea8b3f3b 100644 --- a/lib/pages/video/reply/widgets/reply_item_grpc.dart +++ b/lib/pages/video/reply/widgets/reply_item_grpc.dart @@ -92,9 +92,7 @@ class ReplyItemGrpc extends StatelessWidget { return morePanel( context: context, item: replyItem, - onDelete: () { - onDelete?.call(null); - }, + onDelete: () => onDelete?.call(null), isSubReply: false, ); }, @@ -454,9 +452,7 @@ class ReplyItemGrpc extends StatelessWidget { return morePanel( context: context, item: replyItem.replies[i], - onDelete: () { - onDelete?.call(i); - }, + onDelete: () => onDelete?.call(i), isSubReply: true, ); }, @@ -675,9 +671,7 @@ class ReplyItemGrpc extends StatelessWidget { color: theme.colorScheme.primary, ), recognizer: TapGestureRecognizer() - ..onTap = () { - Get.toNamed('/member?mid=$userId'); - }, + ..onTap = () => Get.toNamed('/member?mid=$userId'), ), ); } else if (_timeRegExp.hasMatch(matchStr)) { @@ -831,9 +825,7 @@ class ReplyItemGrpc extends StatelessWidget { color: theme.colorScheme.primary, ), recognizer: TapGestureRecognizer() - ..onTap = () { - PageUtils.handleWebview(matchStr); - }, + ..onTap = () => PageUtils.handleWebview(matchStr), ), ); } else { @@ -1046,9 +1038,7 @@ class ReplyItemGrpc extends StatelessWidget { ), actions: [ TextButton( - onPressed: () { - Get.back(result: false); - }, + onPressed: () => Get.back(result: false), child: Text( '取消', style: TextStyle( @@ -1057,9 +1047,7 @@ class ReplyItemGrpc extends StatelessWidget { ), ), TextButton( - onPressed: () { - Get.back(result: true); - }, + onPressed: () => Get.back(result: true), child: const Text('确定'), ), ], diff --git a/lib/pages/video/reply_new/view.dart b/lib/pages/video/reply_new/view.dart index c65136748..08caa4be6 100644 --- a/lib/pages/video/reply_new/view.dart +++ b/lib/pages/video/reply_new/view.dart @@ -210,9 +210,7 @@ class _ReplyPageState extends CommonPublishPageState { ? themeData.colorScheme.secondary : themeData.colorScheme.outline, ), - onPressed: () { - _syncToDynamic.value = !_syncToDynamic.value; - }, + onPressed: () => _syncToDynamic.value = !_syncToDynamic.value, icon: Icon( _syncToDynamic.value ? Icons.check_box diff --git a/lib/pages/video/reply_reply/view.dart b/lib/pages/video/reply_reply/view.dart index 0f1d979f6..b1b7a2942 100644 --- a/lib/pages/video/reply_reply/view.dart +++ b/lib/pages/video/reply_reply/view.dart @@ -180,9 +180,7 @@ class _VideoReplyReplyPanelState replyItem: firstFloor!, replyLevel: '2', needDivider: false, - onReply: () { - _onReply(firstFloor!, -1); - }, + onReply: () => _onReply(firstFloor!, -1), upMid: _videoReplyReplyController.upMid, onViewImage: widget.onViewImage, onDismissed: widget.onDismissed, @@ -428,26 +426,22 @@ class _VideoReplyReplyPanelState return ReplyItemGrpc( replyItem: replyItem, replyLevel: widget.isDialogue ? '3' : '2', - onReply: () { - _onReply(replyItem, index); - }, + onReply: () => _onReply(replyItem, index), onDelete: (subIndex) { _videoReplyReplyController.onRemove(index, null); }, upMid: _videoReplyReplyController.upMid, - showDialogue: () { - _key.currentState?.showBottomSheet( - backgroundColor: Colors.transparent, - (context) => VideoReplyReplyPanel( - oid: replyItem.oid.toInt(), - rpid: replyItem.root.toInt(), - dialog: replyItem.dialog.toInt(), - replyType: widget.replyType, - source: 'videoDetail', - isDialogue: true, - ), - ); - }, + showDialogue: () => _key.currentState?.showBottomSheet( + backgroundColor: Colors.transparent, + (context) => VideoReplyReplyPanel( + oid: replyItem.oid.toInt(), + rpid: replyItem.root.toInt(), + dialog: replyItem.dialog.toInt(), + replyType: widget.replyType, + source: 'videoDetail', + isDialogue: true, + ), + ), onViewImage: widget.onViewImage, onDismissed: widget.onDismissed, callback: _getImageCallback, diff --git a/lib/pages/video/send_danmaku/view.dart b/lib/pages/video/send_danmaku/view.dart index 68fe28242..0a259e58a 100644 --- a/lib/pages/video/send_danmaku/view.dart +++ b/lib/pages/video/send_danmaku/view.dart @@ -109,9 +109,7 @@ class _SendDanmakuPanelState extends CommonPublishPageState { itemBuilder: (context, index) { if (index == length - 1) { return GestureDetector( - onTap: () { - _showColorPicker(); - }, + onTap: _showColorPicker, child: Container( decoration: BoxDecoration( color: themeData.colorScheme.secondaryContainer, @@ -230,9 +228,7 @@ class _SendDanmakuPanelState extends CommonPublishPageState { Widget _buildColorItem(Color color) { return GestureDetector( - onTap: () { - _color.value = color; - }, + onTap: () => _color.value = color, child: Container( padding: const EdgeInsets.all(2), decoration: BoxDecoration( @@ -284,9 +280,7 @@ class _SendDanmakuPanelState extends CommonPublishPageState { return Obx( () => Expanded( child: GestureDetector( - onTap: () { - _mode.value = mode; - }, + onTap: () => _mode.value = mode, child: Container( alignment: Alignment.center, decoration: BoxDecoration( @@ -314,9 +308,7 @@ class _SendDanmakuPanelState extends CommonPublishPageState { return Obx( () => Expanded( child: GestureDetector( - onTap: () { - _fontsize.value = fontsize; - }, + onTap: () => _fontsize.value = fontsize, child: Container( alignment: Alignment.center, decoration: BoxDecoration( diff --git a/lib/pages/video/view.dart b/lib/pages/video/view.dart index cec165cba..ea2ad5a23 100644 --- a/lib/pages/video/view.dart +++ b/lib/pages/video/view.dart @@ -840,12 +840,11 @@ class _VideoDetailPageVState extends State .all(EdgeInsets .zero), ), - onPressed: () { - videoDetailController - .headerCtrKey - .currentState - ?.showSettingSheet(); - }, + onPressed: () => + videoDetailController + .headerCtrKey + .currentState + ?.showSettingSheet(), icon: Icon( Icons.more_vert_outlined, size: 19, @@ -1934,13 +1933,11 @@ class _VideoDetailPageVState extends State showTitle: false, isSupportReverse: videoDetailController.videoType != SearchType.media_bangumi, - onReverse: () { - onReversePlay( - bvid: videoDetailController.bvid, - aid: IdUtils.bv2av(videoDetailController.bvid), - isSeason: false, - ); - }, + onReverse: () => onReversePlay( + bvid: videoDetailController.bvid, + aid: IdUtils.bv2av(videoDetailController.bvid), + isSeason: false, + ), ), ), ), @@ -1991,13 +1988,11 @@ class _VideoDetailPageVState extends State showTitle: false, isSupportReverse: videoDetailController.videoType != SearchType.media_bangumi, - onReverse: () { - onReversePlay( - bvid: videoDetailController.bvid, - aid: IdUtils.bv2av(videoDetailController.bvid), - isSeason: true, - ); - }, + onReverse: () => onReversePlay( + bvid: videoDetailController.bvid, + aid: IdUtils.bv2av(videoDetailController.bvid), + isSeason: true, + ), ), ), ), diff --git a/lib/pages/video/widgets/header_control.dart b/lib/pages/video/widgets/header_control.dart index e5f601861..277591f76 100644 --- a/lib/pages/video/widgets/header_control.dart +++ b/lib/pages/video/widgets/header_control.dart @@ -286,10 +286,8 @@ class HeaderControlState extends State { 0 => Obx( () => ActionRowLineItem( iconData: Icons.flip, - onTap: () { - widget.controller.flipX.value = - !widget.controller.flipX.value; - }, + onTap: () => widget.controller.flipX.value = + !widget.controller.flipX.value, text: " 左右翻转 ", selectStatus: widget.controller.flipX.value, ), @@ -419,125 +417,105 @@ class HeaderControlState extends State { title: const Text("Resolution"), subtitle: Text( '${player.state.width}x${player.state.height}'), - onTap: () { - Utils.copyText( - 'Resolution\n${player.state.width}x${player.state.height}', - needToast: false, - ); - }, + onTap: () => Utils.copyText( + 'Resolution\n${player.state.width}x${player.state.height}', + needToast: false, + ), ), ListTile( dense: true, title: const Text("VideoParams"), subtitle: Text(player.state.videoParams.toString()), - onTap: () { - Utils.copyText( - 'VideoParams\n${player.state.videoParams}', - needToast: false, - ); - }, + onTap: () => Utils.copyText( + 'VideoParams\n${player.state.videoParams}', + needToast: false, + ), ), ListTile( dense: true, title: const Text("AudioParams"), subtitle: Text(player.state.audioParams.toString()), - onTap: () { - Utils.copyText( - 'AudioParams\n${player.state.audioParams}', - needToast: false, - ); - }, + onTap: () => Utils.copyText( + 'AudioParams\n${player.state.audioParams}', + needToast: false, + ), ), ListTile( dense: true, title: const Text("Media"), subtitle: Text(player.state.playlist.toString()), - onTap: () { - Utils.copyText( - 'Media\n${player.state.playlist}', - needToast: false, - ); - }, + onTap: () => Utils.copyText( + 'Media\n${player.state.playlist}', + needToast: false, + ), ), ListTile( dense: true, title: const Text("AudioTrack"), subtitle: Text(player.state.track.audio.toString()), - onTap: () { - Utils.copyText( - 'AudioTrack\n${player.state.track.audio}', - needToast: false, - ); - }, + onTap: () => Utils.copyText( + 'AudioTrack\n${player.state.track.audio}', + needToast: false, + ), ), ListTile( dense: true, title: const Text("VideoTrack"), subtitle: Text(player.state.track.video.toString()), - onTap: () { - Utils.copyText( - 'VideoTrack\n${player.state.track.audio}', - needToast: false, - ); - }, + onTap: () => Utils.copyText( + 'VideoTrack\n${player.state.track.audio}', + needToast: false, + ), ), ListTile( - dense: true, - title: const Text("pitch"), - subtitle: - Text(player.state.pitch.toString()), - onTap: () { - Utils.copyText( - 'pitch\n${player.state.pitch}', - needToast: false, - ); - }), + dense: true, + title: const Text("pitch"), + subtitle: Text(player.state.pitch.toString()), + onTap: () => Utils.copyText( + 'pitch\n${player.state.pitch}', + needToast: false, + ), + ), ListTile( - dense: true, - title: const Text("rate"), - subtitle: - Text(player.state.rate.toString()), - onTap: () { - Utils.copyText( - 'rate\n${player.state.rate}', - needToast: false, - ); - }), + dense: true, + title: const Text("rate"), + subtitle: Text(player.state.rate.toString()), + onTap: () => Utils.copyText( + 'rate\n${player.state.rate}', + needToast: false, + ), + ), ListTile( dense: true, title: const Text("AudioBitrate"), subtitle: Text( player.state.audioBitrate.toString()), - onTap: () { - Utils.copyText( - 'AudioBitrate\n${player.state.audioBitrate}', - needToast: false, - ); - }, + onTap: () => Utils.copyText( + 'AudioBitrate\n${player.state.audioBitrate}', + needToast: false, + ), ), ListTile( dense: true, title: const Text("Volume"), subtitle: Text(player.state.volume.toString()), - onTap: () { - Utils.copyText( - 'Volume\n${player.state.volume}', - needToast: false, - ); - }, + onTap: () => Utils.copyText( + 'Volume\n${player.state.volume}', + needToast: false, + ), ), ], ), ), actions: [ TextButton( - onPressed: () => Get.back(), + onPressed: Get.back, child: Text( '确定', style: @@ -610,10 +588,8 @@ class HeaderControlState extends State { SizedBox( height: 45, child: GestureDetector( - onTap: () { - SmartDialog.showToast( - '标灰画质需要bilibili会员(已是会员?请关闭无痕模式);4k和杜比视界播放效果可能不佳'); - }, + onTap: () => SmartDialog.showToast( + '标灰画质需要bilibili会员(已是会员?请关闭无痕模式);4k和杜比视界播放效果可能不佳'), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ diff --git a/lib/pages/whisper/view.dart b/lib/pages/whisper/view.dart index e03de5fa3..be43b8213 100644 --- a/lib/pages/whisper/view.dart +++ b/lib/pages/whisper/view.dart @@ -32,12 +32,10 @@ class _WhisperPageState extends State { children: _controller.outsideItem.value!.map((e) { return IconButton( tooltip: e.hasTitle() ? e.title : null, - onPressed: () { - e.type.action( - context: context, - controller: _controller, - ); - }, + onPressed: () => e.type.action( + context: context, + controller: _controller, + ), icon: e.type.icon, ); }).toList()); @@ -50,12 +48,10 @@ class _WhisperPageState extends State { itemBuilder: (context) { return _controller.threeDotItems.value! .map((e) => PopupMenuItem( - onTap: () { - e.type.action( - context: context, - controller: _controller, - ); - }, + onTap: () => e.type.action( + context: context, + controller: _controller, + ), child: Row( children: [ e.type.icon, diff --git a/lib/pages/whisper/widgets/item.dart b/lib/pages/whisper/widgets/item.dart index b2edb59a8..edc1319bb 100644 --- a/lib/pages/whisper/widgets/item.dart +++ b/lib/pages/whisper/widgets/item.dart @@ -38,51 +38,49 @@ class WhisperSessionItem extends StatelessWidget { ? theme.colorScheme.onInverseSurface .withValues(alpha: Get.isDarkMode ? 0.4 : 0.8) : null, - onLongPress: () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - clipBehavior: Clip.hardEdge, - contentPadding: const EdgeInsets.symmetric(vertical: 12), - content: DefaultTextStyle( - style: const TextStyle(fontSize: 14), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ + onLongPress: () => showDialog( + context: context, + builder: (context) { + return AlertDialog( + clipBehavior: Clip.hardEdge, + contentPadding: const EdgeInsets.symmetric(vertical: 12), + content: DefaultTextStyle( + style: const TextStyle(fontSize: 14), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + dense: true, + onTap: () { + Get.back(); + onSetTop(item.isPinned, item.id); + }, + title: Text(item.isPinned ? '移除置顶' : '置顶'), + ), + if (item.id.privateId.hasTalkerUid()) ListTile( dense: true, onTap: () { Get.back(); - onSetTop(item.isPinned, item.id); + onSetMute(item.isMuted, item.id.privateId.talkerUid); }, - title: Text(item.isPinned ? '移除置顶' : '置顶'), + title: Text('${item.isMuted ? '关闭' : '开启'}免打扰'), ), - if (item.id.privateId.hasTalkerUid()) - ListTile( - dense: true, - onTap: () { - Get.back(); - onSetMute(item.isMuted, item.id.privateId.talkerUid); - }, - title: Text('${item.isMuted ? '关闭' : '开启'}免打扰'), - ), - if (item.id.privateId.hasTalkerUid()) - ListTile( - dense: true, - onTap: () { - Get.back(); - onRemove(item.id.privateId.talkerUid.toInt()); - }, - title: const Text('删除'), - ), - ], - ), + if (item.id.privateId.hasTalkerUid()) + ListTile( + dense: true, + onTap: () { + Get.back(); + onRemove(item.id.privateId.talkerUid.toInt()); + }, + title: const Text('删除'), + ), + ], ), - ); - }, - ); - }, + ), + ); + }, + ), onTap: () { if (item.hasUnread()) { item.clearUnread(); @@ -169,11 +167,9 @@ class WhisperSessionItem extends StatelessWidget { return GestureDetector( onTap: item.sessionInfo.avatar.hasMid() - ? () { - Get.toNamed( + ? () => Get.toNamed( '/member?mid=${item.sessionInfo.avatar.mid}', - ); - } + ) : null, child: item.hasUnread() && item.unread.style != UnreadStyle.UNREAD_STYLE_NONE diff --git a/lib/pages/whisper_block/view.dart b/lib/pages/whisper_block/view.dart index 058ab06de..ccea8a029 100644 --- a/lib/pages/whisper_block/view.dart +++ b/lib/pages/whisper_block/view.dart @@ -79,9 +79,7 @@ class _WhisperBlockPageState extends State { context: context, title: '删除屏蔽词?', content: '该屏蔽词将不再生效', - onConfirm: () { - _controller.onRemove(e); - }, + onConfirm: () => _controller.onRemove(e), ); }, )) diff --git a/lib/pages/whisper_detail/view.dart b/lib/pages/whisper_detail/view.dart index 5e9201217..f6d0ec8ed 100644 --- a/lib/pages/whisper_detail/view.dart +++ b/lib/pages/whisper_detail/view.dart @@ -98,11 +98,9 @@ class _WhisperDetailPageState ), actions: [ IconButton( - onPressed: () { - Get.to(WhisperLinkSettingPage( - talkerUid: _whisperDetailController.talkerId, - )); - }, + onPressed: () => Get.to(WhisperLinkSettingPage( + talkerUid: _whisperDetailController.talkerId, + )), icon: Icon( size: 20, Icons.settings, @@ -162,42 +160,10 @@ class _WhisperDetailPageState return ChatItem( item: item, eInfos: _whisperDetailController.eInfos, - onLongPress: item.senderUid == - _whisperDetailController.ownerMid - ? () { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - clipBehavior: Clip.hardEdge, - contentPadding: - const EdgeInsets.symmetric(vertical: 12), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - ListTile( - onTap: () { - Get.back(); - _whisperDetailController.sendMsg( - message: '${item.msgKey}', - onClearText: editController.clear, - msgType: 5, - index: index, - ); - }, - dense: true, - title: const Text( - '撤回', - style: TextStyle(fontSize: 14), - ), - ), - ], - ), - ); - }, - ); - } - : null, + onLongPress: + item.senderUid == _whisperDetailController.ownerMid + ? () => onLongPress(index, item) + : null, ); }, separatorBuilder: (BuildContext context, int index) => @@ -213,6 +179,39 @@ class _WhisperDetailPageState }; } + void onLongPress(int index, Msg item) { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + clipBehavior: Clip.hardEdge, + contentPadding: const EdgeInsets.symmetric(vertical: 12), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + onTap: () { + Get.back(); + _whisperDetailController.sendMsg( + message: '${item.msgKey}', + onClearText: editController.clear, + msgType: 5, + index: index, + ); + }, + dense: true, + title: const Text( + '撤回', + style: TextStyle(fontSize: 14), + ), + ), + ], + ), + ); + }, + ); + } + Widget _buildInputView(theme) { return Container( padding: const EdgeInsets.symmetric(vertical: 8), @@ -227,13 +226,11 @@ class _WhisperDetailPageState crossAxisAlignment: CrossAxisAlignment.end, children: [ IconButton( - onPressed: () { - updatePanelType( - PanelType.emoji == currentPanelType - ? PanelType.keyboard - : PanelType.emoji, - ); - }, + onPressed: () => updatePanelType( + PanelType.emoji == currentPanelType + ? PanelType.keyboard + : PanelType.emoji, + ), icon: const Icon(Icons.emoji_emotions), tooltip: '表情', ), diff --git a/lib/pages/whisper_detail/widget/chat_item.dart b/lib/pages/whisper_detail/widget/chat_item.dart index 4e42711a8..0475c6ed4 100644 --- a/lib/pages/whisper_detail/widget/chat_item.dart +++ b/lib/pages/whisper_detail/widget/chat_item.dart @@ -171,9 +171,7 @@ class ChatItem extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ GestureDetector( - onTap: () { - Get.toNamed('/liveRoom?roomid=${content['sourceID']}'); - }, + onTap: () => Get.toNamed('/liveRoom?roomid=${content['sourceID']}'), child: NetworkImgLayer( width: 220, height: 220 * 9 / 16, @@ -209,15 +207,13 @@ class ChatItem extends StatelessWidget { Widget msgTypeArticleCard_12(content, Color textColor) { return GestureDetector( - onTap: () { - Get.toNamed( - '/articlePage', - parameters: { - 'id': '${content['rid']}', - 'type': "read", - }, - ); - }, + onTap: () => Get.toNamed( + '/articlePage', + parameters: { + 'id': '${content['rid']}', + 'type': "read", + }, + ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -292,12 +288,13 @@ class ChatItem extends StatelessWidget { try { SmartDialog.showLoading(); final int cid = await SearchHttp.ab2c(bvid: bvid); - SmartDialog.dismiss().then( - (e) => PageUtils.toVideoPage('bvid=$bvid&cid=$cid', - arguments: { - 'pic': i['cover_url'], - 'heroTag': Utils.makeHeroTag(bvid), - }), + SmartDialog.dismiss(); + PageUtils.toVideoPage( + 'bvid=$bvid&cid=$cid', + arguments: { + 'pic': i['cover_url'], + 'heroTag': Utils.makeHeroTag(bvid), + }, ); } catch (err) { SmartDialog.dismiss(); @@ -370,14 +367,13 @@ class ChatItem extends StatelessWidget { SmartDialog.showLoading(); var bvid = content["bvid"]; final int cid = await SearchHttp.ab2c(bvid: bvid); - SmartDialog.dismiss().then( - (_) => PageUtils.toVideoPage( - 'bvid=$bvid&cid=$cid', - arguments: { - 'pic': content['thumb'], - 'heroTag': Utils.makeHeroTag(bvid), - }, - ), + SmartDialog.dismiss(); + PageUtils.toVideoPage( + 'bvid=$bvid&cid=$cid', + arguments: { + 'pic': content['thumb'], + 'heroTag': Utils.makeHeroTag(bvid), + }, ); } catch (err) { SmartDialog.dismiss(); @@ -421,9 +417,7 @@ class ChatItem extends StatelessWidget { // album case 2: type = '相簿'; - onTap = () { - PageUtils.pushDynFromId(rid: content['id']); - }; + onTap = () => PageUtils.pushDynFromId(rid: content['id']); break; // video @@ -441,14 +435,13 @@ class ChatItem extends StatelessWidget { bvid ??= IdUtils.av2bv(aid); SmartDialog.showLoading(); final int cid = await SearchHttp.ab2c(bvid: bvid); - SmartDialog.dismiss().then( - (e) => PageUtils.toVideoPage( - 'bvid=$bvid&cid=$cid', - arguments: { - 'pic': content['thumb'], - 'heroTag': Utils.makeHeroTag(bvid), - }, - ), + SmartDialog.dismiss(); + PageUtils.toVideoPage( + 'bvid=$bvid&cid=$cid', + arguments: { + 'pic': content['thumb'], + 'heroTag': Utils.makeHeroTag(bvid), + }, ); }; break; @@ -456,37 +449,29 @@ class ChatItem extends StatelessWidget { // article case 6: type = '专栏'; - onTap = () { - Get.toNamed( - '/articlePage', - parameters: { - 'id': '${content['id']}', - 'type': 'read', - }, - ); - }; + onTap = () => Get.toNamed( + '/articlePage', + parameters: { + 'id': '${content['id']}', + 'type': 'read', + }, + ); break; // dynamic case 11: type = '动态'; - onTap = () { - PageUtils.pushDynFromId(id: content['id']); - }; + onTap = () => PageUtils.pushDynFromId(id: content['id']); break; // pgc case 16: - onTap = () { - PageUtils.viewBangumi(epId: content['id']); - }; + onTap = () => PageUtils.viewBangumi(epId: content['id']); break; default: - onTap = () { - SmartDialog.showToast( - 'unsupported source type: ${content['source']}'); - }; + onTap = () => SmartDialog.showToast( + 'unsupported source type: ${content['source']}'); } return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -540,9 +525,8 @@ class ChatItem extends StatelessWidget { Widget msgTypePic_2(BuildContext context, content) { return GestureDetector( - onTap: () { - context.imageView(imgList: [SourceModel(url: content['url'])]); - }, + onTap: () => + context.imageView(imgList: [SourceModel(url: content['url'])]), child: Hero( tag: content['url'], child: NetworkImgLayer( @@ -666,9 +650,7 @@ class ChatItem extends StatelessWidget { Divider(color: theme.colorScheme.primary.withValues(alpha: 0.05)), GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - PiliScheme.routePushFromUrl(content['jump_uri']); - }, + onTap: () => PiliScheme.routePushFromUrl(content['jump_uri']), child: SizedBox( width: double.infinity, child: Text(content['jump_text']), @@ -680,9 +662,7 @@ class ChatItem extends StatelessWidget { Divider(color: theme.colorScheme.primary.withValues(alpha: 0.05)), GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - PiliScheme.routePushFromUrl(content['jump_uri_2']); - }, + onTap: () => PiliScheme.routePushFromUrl(content['jump_uri_2']), child: SizedBox( width: double.infinity, child: Text(content['jump_text_2']), @@ -694,9 +674,7 @@ class ChatItem extends StatelessWidget { Divider(color: theme.colorScheme.primary.withValues(alpha: 0.05)), GestureDetector( behavior: HitTestBehavior.opaque, - onTap: () { - PiliScheme.routePushFromUrl(content['jump_uri_3']); - }, + onTap: () => PiliScheme.routePushFromUrl(content['jump_uri_3']), child: SizedBox( width: double.infinity, child: Text(content['jump_text_3']), @@ -718,9 +696,7 @@ class ChatItem extends StatelessWidget { child: GestureDetector( onTap: content['jump_url'] == null ? null - : () { - PiliScheme.routePushFromUrl(content['jump_url']); - }, + : () => PiliScheme.routePushFromUrl(content['jump_url']), child: CachedNetworkImage( imageUrl: Utils.thumbnailImgUrl(content['pic_url']), ), diff --git a/lib/pages/whisper_link_setting/view.dart b/lib/pages/whisper_link_setting/view.dart index 8e3d2b639..8199205eb 100644 --- a/lib/pages/whisper_link_setting/view.dart +++ b/lib/pages/whisper_link_setting/view.dart @@ -110,9 +110,7 @@ class _WhisperLinkSettingPageState extends State { builder: (context) { final ImUserInfosData item = response!.first; return ListTile( - onTap: () { - Get.toNamed('/member?mid=${item.mid}'); - }, + onTap: () => Get.toNamed('/member?mid=${item.mid}'), leading: PendantAvatar( avatar: item.face, size: 42, diff --git a/lib/pages/whisper_secondary/view.dart b/lib/pages/whisper_secondary/view.dart index 5967ae78b..fa46d2e09 100644 --- a/lib/pages/whisper_secondary/view.dart +++ b/lib/pages/whisper_secondary/view.dart @@ -41,12 +41,10 @@ class _WhisperSecPageState extends State { itemBuilder: (context) { return _controller.threeDotItems.value! .map((e) => PopupMenuItem( - onTap: () { - e.type.action( - context: context, - controller: _controller, - ); - }, + onTap: () => e.type.action( + context: context, + controller: _controller, + ), child: Row( children: [ e.type.icon, diff --git a/lib/pages/whisper_settings/view.dart b/lib/pages/whisper_settings/view.dart index 6821ef382..35e2c1a11 100644 --- a/lib/pages/whisper_settings/view.dart +++ b/lib/pages/whisper_settings/view.dart @@ -41,6 +41,108 @@ class _WhisperSettingsPageState extends State { ); } + Future onSet( + int key, PbMap response, Setting item) async { + PbMap settings = PbMap( + response.keyFieldType, + response.valueFieldType, + )..[key] = item; + final res = await _controller.onSet(settings); + if (res) { + widget.onUpdate?.call(settings); + } + return res; + } + + void onRedirect( + ThemeData theme, int key, PbMap response, Setting item) { + if (item.redirect.settingPage.hasParentSettingType()) { + Get.to( + WhisperSettingsPage( + imSettingType: item.redirect.settingPage.parentSettingType, + onUpdate: (value) { + _controller.loadingState + ..value.data[key]?.redirect.settingPage.subSettings.addAll(value) + ..refresh(); + }, + ), + preventDuplicates: false, + ); + } else if (item.redirect.hasWindowSelect()) { + String? selected; + showDialog( + context: context, + builder: (context) { + return AlertDialog( + clipBehavior: Clip.hardEdge, + contentPadding: const EdgeInsets.symmetric(vertical: 12), + content: Column( + mainAxisSize: MainAxisSize.min, + children: item.redirect.windowSelect.item.map( + (e) { + if (e.selected) { + selected ??= e.text; + } + return ListTile( + dense: true, + onTap: () async { + if (!e.selected) { + Get.back(); + for (var j in item.redirect.windowSelect.item) { + j.selected = false; + } + item.redirect.selectedSummary = e.text; + e.selected = true; + _controller.loadingState.refresh(); + PbMap settings = PbMap( + response.keyFieldType, + response.valueFieldType, + )..[key] = item; + final res = await _controller.onSet(settings); + if (!res) { + for (var j in item.redirect.windowSelect.item) { + j.selected = j.text == selected; + } + item.redirect.selectedSummary = selected!; + _controller.loadingState.refresh(); + } + } + }, + title: Text( + e.text, + style: TextStyle( + fontSize: 14, + color: e.selected ? theme.colorScheme.primary : null, + ), + ), + ); + }, + ).toList(), + ), + ); + }, + ); + } else if (item.redirect.otherPage.hasUrl()) { + if (item.redirect.title == '黑名单') { + Get.toNamed('/blackListPage'); + } else if (item.redirect.otherPage.url.startsWith('http')) { + Get.toNamed('/webview', + parameters: {'url': item.redirect.otherPage.url}); + } else { + SmartDialog.showToast(item.redirect.otherPage.url); + } + } else if (item.redirect.settingPage.hasUrl()) { + if (item.redirect.title == '消息屏蔽词') { + Get.to(const WhisperBlockPage()); + } else if (item.redirect.settingPage.url.startsWith('http')) { + Get.toNamed('/webview', + parameters: {'url': item.redirect.settingPage.url}); + } else { + SmartDialog.showToast(item.redirect.settingPage.url); + } + } + } + Widget _buildBody( ThemeData theme, LoadingState> loadingState) { return switch (loadingState) { @@ -57,119 +159,8 @@ class _WhisperSettingsPageState extends State { final item = response[key]!; return ImSettingsItem( item: item, - onSet: () async { - PbMap settings = PbMap( - response.keyFieldType, - response.valueFieldType, - )..[key] = item; - final res = await _controller.onSet(settings); - if (res) { - widget.onUpdate?.call(settings); - } - return res; - }, - onRedirect: () { - if (item.redirect.settingPage.hasParentSettingType()) { - Get.to( - WhisperSettingsPage( - imSettingType: - item.redirect.settingPage.parentSettingType, - onUpdate: (value) { - _controller.loadingState - ..value - .data[key] - ?.redirect - .settingPage - .subSettings - .addAll(value) - ..refresh(); - }, - ), - preventDuplicates: false, - ); - } else if (item.redirect.hasWindowSelect()) { - String? selected; - showDialog( - context: context, - builder: (context) { - return AlertDialog( - clipBehavior: Clip.hardEdge, - contentPadding: - const EdgeInsets.symmetric(vertical: 12), - content: Column( - mainAxisSize: MainAxisSize.min, - children: item.redirect.windowSelect.item.map( - (e) { - if (e.selected) { - selected ??= e.text; - } - return ListTile( - dense: true, - onTap: () async { - if (!e.selected) { - Get.back(); - for (var j - in item.redirect.windowSelect.item) { - j.selected = false; - } - item.redirect.selectedSummary = e.text; - e.selected = true; - _controller.loadingState.refresh(); - PbMap settings = - PbMap( - response.keyFieldType, - response.valueFieldType, - )..[key] = item; - final res = - await _controller.onSet(settings); - if (!res) { - for (var j in item - .redirect.windowSelect.item) { - j.selected = j.text == selected; - } - item.redirect.selectedSummary = - selected!; - _controller.loadingState.refresh(); - } - } - }, - title: Text( - e.text, - style: TextStyle( - fontSize: 14, - color: e.selected - ? theme.colorScheme.primary - : null, - ), - ), - ); - }, - ).toList(), - ), - ); - }, - ); - } else if (item.redirect.otherPage.hasUrl()) { - if (item.redirect.title == '黑名单') { - Get.toNamed('/blackListPage'); - } else if (item.redirect.otherPage.url.startsWith('http')) { - Get.toNamed('/webview', - parameters: {'url': item.redirect.otherPage.url}); - } else { - SmartDialog.showToast(item.redirect.otherPage.url); - } - } else if (item.redirect.settingPage.hasUrl()) { - if (item.redirect.title == '消息屏蔽词') { - Get.to(const WhisperBlockPage()); - } else if (item.redirect.settingPage.url - .startsWith('http')) { - Get.toNamed('/webview', - parameters: {'url': item.redirect.settingPage.url}); - } else { - SmartDialog.showToast(item.redirect.settingPage.url); - } - } - }, + onSet: () => onSet(key, response, item), + onRedirect: () => onRedirect(theme, key, response, item), ); }, separatorBuilder: (context, index) => Divider( diff --git a/lib/plugin/pl_player/view.dart b/lib/plugin/pl_player/view.dart index 5e8e78e48..fa596a8a7 100644 --- a/lib/plugin/pl_player/view.dart +++ b/lib/plugin/pl_player/view.dart @@ -394,10 +394,8 @@ class _PLVideoPlayerState extends State ), ], ), - onTap: () { - plPlayerController.showDmTreandChart.value = - !plPlayerController.showDmTreandChart.value; - }, + onTap: () => plPlayerController.showDmTreandChart.value = + !plPlayerController.showDmTreandChart.value, ), )), @@ -419,9 +417,7 @@ class _PLVideoPlayerState extends State height: 35, padding: const EdgeInsets.only(left: 30), value: type, - onTap: () { - plPlayerController.setShader(type.index); - }, + onTap: () => plPlayerController.setShader(type.index), child: Text( type.title, style: @@ -539,9 +535,7 @@ class _PLVideoPlayerState extends State height: 35, padding: const EdgeInsets.only(left: 30), value: boxFit, - onTap: () { - plPlayerController.toggleVideoFit(boxFit); - }, + onTap: () => plPlayerController.toggleVideoFit(boxFit), child: Text( boxFit.desc, style: const TextStyle(color: Colors.white, fontSize: 13), @@ -572,9 +566,8 @@ class _PLVideoPlayerState extends State return [ PopupMenuItem( value: 0, - onTap: () { - widget.videoDetailController!.setSubtitle(0); - }, + onTap: () => + widget.videoDetailController!.setSubtitle(0), child: const Text( "关闭字幕", style: TextStyle(color: Colors.white), @@ -586,10 +579,8 @@ class _PLVideoPlayerState extends State .map((entry) { return PopupMenuItem( value: entry.key + 1, - onTap: () { - widget.videoDetailController! - .setSubtitle(entry.key + 1); - }, + onTap: () => widget.videoDetailController! + .setSubtitle(entry.key + 1), child: Text( "${entry.value['lan_doc']}", style: const TextStyle(color: Colors.white), @@ -630,9 +621,7 @@ class _PLVideoPlayerState extends State height: 35, padding: const EdgeInsets.only(left: 30), value: speed, - onTap: () { - plPlayerController.setPlaybackSpeed(speed); - }, + onTap: () => plPlayerController.setPlaybackSpeed(speed), child: Text( "${speed}X", style: const TextStyle(color: Colors.white, fontSize: 13), @@ -1633,9 +1622,7 @@ class _PLVideoPlayerState extends State plPlayerController.isBuffering.value) { return Center( child: GestureDetector( - onTap: () { - plPlayerController.refreshPlayer(); - }, + onTap: plPlayerController.refreshPlayer, child: Container( padding: const EdgeInsets.all(30), decoration: const BoxDecoration( diff --git a/lib/plugin/pl_player/widgets/play_pause_btn.dart b/lib/plugin/pl_player/widgets/play_pause_btn.dart index 3625bc644..64ef3c7c4 100644 --- a/lib/plugin/pl_player/widgets/play_pause_btn.dart +++ b/lib/plugin/pl_player/widgets/play_pause_btn.dart @@ -46,11 +46,9 @@ class PlayOrPauseButtonState extends State super.didChangeDependencies(); subscription ??= player.stream.playing.listen((event) { if (event) { - animation.forward().then((value) => { - isOpacity = true, - }); + animation.forward().whenComplete(() => {isOpacity = true}); } else { - animation.reverse().then((value) => {isOpacity = false}); + animation.reverse().whenComplete(() => {isOpacity = false}); } setState(() {}); }); diff --git a/lib/services/shutdown_timer_service.dart b/lib/services/shutdown_timer_service.dart index d7a2371cd..40c77342b 100644 --- a/lib/services/shutdown_timer_service.dart +++ b/lib/services/shutdown_timer_service.dart @@ -97,7 +97,7 @@ class ShutdownTimerService with WidgetsBindingObserver { ], ); }, - ).then((_) { + ).whenComplete(() { // Cleanup when the dialog is dismissed _autoCloseDialogTimer?.cancel(); }); diff --git a/lib/utils/accounts/account_manager/account_mgr.dart b/lib/utils/accounts/account_manager/account_mgr.dart index bbe4d5d25..e6f292b9c 100644 --- a/lib/utils/accounts/account_manager/account_mgr.dart +++ b/lib/utils/accounts/account_manager/account_mgr.dart @@ -156,7 +156,9 @@ class AccountManager extends Interceptor { if (path.startsWith(HttpString.appBaseUrl) || _skipCookie(path)) { return handler.next(response); } else { - _saveCookies(response).then((_) => handler.next(response)).catchError( + _saveCookies(response) + .whenComplete(() => handler.next(response)) + .catchError( (dynamic e, StackTrace s) { final error = DioException( requestOptions: response.requestOptions, @@ -176,7 +178,9 @@ class AccountManager extends Interceptor { } if (err.response != null && !err.response!.requestOptions.path.startsWith(HttpString.appBaseUrl)) { - _saveCookies(err.response!).then((_) => handler.next(err)).catchError( + _saveCookies(err.response!) + .whenComplete(() => handler.next(err)) + .catchError( (dynamic e, StackTrace s) { final error = DioException( requestOptions: err.response!.requestOptions, diff --git a/lib/utils/app_scheme.dart b/lib/utils/app_scheme.dart index 34b7773a7..6dc7f31e4 100644 --- a/lib/utils/app_scheme.dart +++ b/lib/utils/app_scheme.dart @@ -384,9 +384,7 @@ class PiliScheme { actions: [ IconButton( tooltip: '前往', - onPressed: () { - _onPushDynDetail(path, off); - }, + onPressed: () => _onPushDynDetail(path, off), icon: const Icon(Icons.open_in_new), ), ], diff --git a/lib/utils/download.dart b/lib/utils/download.dart index 35a9d1f3e..5a6758167 100644 --- a/lib/utils/download.dart +++ b/lib/utils/download.dart @@ -53,15 +53,13 @@ class DownloadUtils { showDialog( context: context, builder: (context) { - return AlertDialog( - title: const Text('提示'), - content: const Text('存储权限未授权'), + return const AlertDialog( + title: Text('提示'), + content: Text('存储权限未授权'), actions: [ TextButton( - onPressed: () { - openAppSettings(); - }, - child: const Text('去授权'), + onPressed: openAppSettings, + child: Text('去授权'), ) ], ); @@ -178,9 +176,7 @@ class DownloadUtils { SmartDialog.showLoading( msg: '正在下载原图', clickMaskDismiss: true, - onDismiss: () { - cancelToken.cancel(); - }, + onDismiss: cancelToken.cancel, ); try { final isAndroid = Platform.isAndroid; diff --git a/lib/utils/page_utils.dart b/lib/utils/page_utils.dart index 11ac71210..714202da5 100644 --- a/lib/utils/page_utils.dart +++ b/lib/utils/page_utils.dart @@ -87,6 +87,53 @@ class PageUtils { isFullScreen: () => isFullScreen, child: StatefulBuilder( builder: (_, setState) { + void onTap(int choice) { + if (choice == -1) { + showDialog( + context: context, + builder: (context) { + final ThemeData theme = Theme.of(context); + String duration = ''; + return AlertDialog( + title: const Text('自定义时长'), + content: TextField( + autofocus: true, + onChanged: (value) => duration = value, + keyboardType: TextInputType.number, + inputFormatters: [ + FilteringTextInputFormatter.allow(RegExp(r'\d+')), + ], + decoration: const InputDecoration(suffixText: 'min'), + ), + actions: [ + TextButton( + onPressed: Get.back, + child: Text( + '取消', + style: TextStyle(color: theme.colorScheme.outline), + ), + ), + TextButton( + onPressed: () { + Get.back(); + int choice = int.tryParse(duration) ?? 0; + shutdownTimerService.scheduledExitInMinutes = choice; + shutdownTimerService.startShutdownTimer(); + setState(() {}); + }, + child: const Text('确定'), + ), + ], + ); + }, + ); + } else { + Get.back(); + shutdownTimerService.scheduledExitInMinutes = choice; + shutdownTimerService.startShutdownTimer(); + } + } + final ThemeData theme = Theme.of(context); return Theme( data: theme, @@ -120,58 +167,7 @@ class PageUtils { ].map( (choice) => ListTile( dense: true, - onTap: () { - if (choice == -1) { - showDialog( - context: context, - builder: (context) { - String duration = ''; - return AlertDialog( - title: const Text('自定义时长'), - content: TextField( - autofocus: true, - onChanged: (value) => duration = value, - keyboardType: TextInputType.number, - inputFormatters: [ - FilteringTextInputFormatter.allow( - RegExp(r'\d+')), - ], - decoration: const InputDecoration( - suffixText: 'min'), - ), - actions: [ - TextButton( - onPressed: Get.back, - child: Text( - '取消', - style: TextStyle( - color: theme.colorScheme.outline), - ), - ), - TextButton( - onPressed: () { - Get.back(); - int choice = - int.tryParse(duration) ?? 0; - shutdownTimerService - .scheduledExitInMinutes = choice; - shutdownTimerService - .startShutdownTimer(); - setState(() {}); - }, - child: const Text('确定'), - ), - ], - ); - }, - ); - } else { - Get.back(); - shutdownTimerService.scheduledExitInMinutes = - choice; - shutdownTimerService.startShutdownTimer(); - } - }, + onTap: () => onTap(choice), contentPadding: EdgeInsets.zero, title: Text(choice == -1 ? '自定义' diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 2bf8f9310..bccd702b8 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -536,10 +536,8 @@ class Utils { const SizedBox(height: 8), Text('${res.data[0]['body']}'), TextButton( - onPressed: () { - PageUtils.launchURL( - 'https://github.com/bggRGjQaUbCoE/PiliPlus/commits/main'); - }, + onPressed: () => PageUtils.launchURL( + 'https://github.com/bggRGjQaUbCoE/PiliPlus/commits/main'), child: Text( "点此查看完整更新(即commit)内容", style: TextStyle( @@ -574,9 +572,7 @@ class Utils { ), ), TextButton( - onPressed: () { - onDownload(res.data[0]); - }, + onPressed: () => onDownload(res.data[0]), child: const Text('Github'), ), ],