diff --git a/lib/pages/setting/models/extra_settings.dart b/lib/pages/setting/models/extra_settings.dart index 98891467a..ef3461cce 100644 --- a/lib/pages/setting/models/extra_settings.dart +++ b/lib/pages/setting/models/extra_settings.dart @@ -700,9 +700,7 @@ Future audioNormalization( onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: ColorScheme.of(context).outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( @@ -798,9 +796,7 @@ void _showDynDialog(BuildContext context) { onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( @@ -840,21 +836,20 @@ void _showReplyLengthDialog(BuildContext context, VoidCallback setState) { onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( onPressed: () async { - Get.back(); - int length = int.tryParse(replyLengthLimit) ?? 6; - ReplyItemGrpc.replyLengthLimit = length == 0 ? null : length; - await GStorage.setting.put( - SettingBoxKey.replyLengthLimit, - length, - ); - setState(); + try { + final val = int.parse(replyLengthLimit); + Get.back(); + ReplyItemGrpc.replyLengthLimit = val == 0 ? null : val; + await GStorage.setting.put(SettingBoxKey.replyLengthLimit, val); + setState(); + } catch (e) { + SmartDialog.showToast(e.toString()); + } }, child: const Text('确定'), ), @@ -883,22 +878,22 @@ void _showDmHeightDialog(BuildContext context, VoidCallback setState) { onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( onPressed: () async { - Get.back(); - await GStorage.setting.put( - SettingBoxKey.danmakuLineHeight, - max( + try { + final val = max( 1.0, - double.tryParse(danmakuLineHeight)?.toPrecision(1) ?? 1.6, - ), - ); - setState(); + double.parse(danmakuLineHeight).toPrecision(1), + ); + Get.back(); + await GStorage.setting.put(SettingBoxKey.danmakuLineHeight, val); + setState(); + } catch (e) { + SmartDialog.showToast(e.toString()); + } }, child: const Text('确定'), ), @@ -927,9 +922,7 @@ void _showTouchSlopDialog(BuildContext context, VoidCallback setState) { onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( @@ -1210,9 +1203,7 @@ void _showProxyDialog(BuildContext context) { onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( @@ -1254,20 +1245,22 @@ void _showCacheDialog(BuildContext context, VoidCallback setState) { onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( onPressed: () async { - Get.back(); - num value = num.tryParse(valueStr) ?? 0; - await GStorage.setting.put( - SettingBoxKey.maxCacheSize, - value * 1024 * 1024, - ); - setState(); + try { + final val = num.parse(valueStr); + Get.back(); + await GStorage.setting.put( + SettingBoxKey.maxCacheSize, + val * 1024 * 1024, + ); + setState(); + } catch (e) { + SmartDialog.showToast(e.toString()); + } }, child: const Text('确定'), ), diff --git a/lib/pages/setting/models/model.dart b/lib/pages/setting/models/model.dart index 169afcb25..540406935 100644 --- a/lib/pages/setting/models/model.dart +++ b/lib/pages/setting/models/model.dart @@ -148,9 +148,7 @@ SettingsModel getBanWordModel({ onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( @@ -228,15 +226,17 @@ SettingsModel getVideoFilterSelectModel({ onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( onPressed: () { - Get.back(); - result = int.tryParse(valueStr) ?? 0; + try { + result = int.parse(valueStr); + Get.back(); + } catch (e) { + SmartDialog.showToast(e.toString()); + } }, child: const Text('确定'), ), diff --git a/lib/pages/setting/models/play_settings.dart b/lib/pages/setting/models/play_settings.dart index 1bf6dc201..badd0c3e6 100644 --- a/lib/pages/setting/models/play_settings.dart +++ b/lib/pages/setting/models/play_settings.dart @@ -249,9 +249,8 @@ List get playSettings => [ leading: const Icon(Icons.volume_up_outlined), setKey: SettingBoxKey.enableBackgroundPlay, defaultVal: true, - onChanged: (value) { - videoPlayerServiceHandler!.enableBackgroundPlay = value; - }, + onChanged: (value) => + videoPlayerServiceHandler!.enableBackgroundPlay = value, ), const SwitchModel( title: '播放器设置仅对当前生效', diff --git a/lib/pages/setting/models/recommend_settings.dart b/lib/pages/setting/models/recommend_settings.dart index db70d0220..256d27468 100644 --- a/lib/pages/setting/models/recommend_settings.dart +++ b/lib/pages/setting/models/recommend_settings.dart @@ -90,9 +90,7 @@ List get recommendSettings => [ leading: const Icon(Icons.favorite_border_outlined), setKey: SettingBoxKey.exemptFilterForFollowed, defaultVal: true, - onChanged: (value) { - RecommendFilter.exemptFilterForFollowed = value; - }, + onChanged: (value) => RecommendFilter.exemptFilterForFollowed = value, ), SwitchModel( title: '过滤器也应用于相关视频', @@ -100,8 +98,6 @@ List get recommendSettings => [ leading: const Icon(Icons.explore_outlined), setKey: SettingBoxKey.applyFilterToRelatedVideos, defaultVal: true, - onChanged: (value) { - RecommendFilter.applyFilterToRelatedVideos = value; - }, + onChanged: (value) => RecommendFilter.applyFilterToRelatedVideos = value, ), ]; diff --git a/lib/pages/setting/models/style_settings.dart b/lib/pages/setting/models/style_settings.dart index c5ab45830..0fd710ab5 100644 --- a/lib/pages/setting/models/style_settings.dart +++ b/lib/pages/setting/models/style_settings.dart @@ -1,5 +1,4 @@ import 'dart:io'; -import 'dart:math'; import 'package:PiliPlus/common/widgets/color_palette.dart'; import 'package:PiliPlus/common/widgets/custom_toast.dart'; @@ -83,9 +82,7 @@ List get styleSettings => [ setKey: SettingBoxKey.appFontWeight, defaultVal: false, leading: const Icon(Icons.text_fields), - onChanged: (value) { - Get.forceAppUpdate(); - }, + onChanged: (value) => Get.forceAppUpdate(), onTap: _showFontWeightDialog, ), NormalModel( @@ -357,9 +354,7 @@ List get styleSettings => [ leading: const Icon(Icons.exit_to_app_outlined), setKey: SettingBoxKey.directExitOnBack, defaultVal: false, - onChanged: (value) { - Get.find().directExitOnBack = value; - }, + onChanged: (value) => Get.find().directExitOnBack = value, ), if (Platform.isAndroid) NormalModel( @@ -474,9 +469,7 @@ void _showUiScaleDialog( onPressed: () => Navigator.pop(context), child: Text( '取消', - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( @@ -516,7 +509,7 @@ void _showSpringDurationDialog(BuildContext context) { onPressed: Get.back, child: Text( '取消', - style: TextStyle(color: Theme.of(context).colorScheme.outline), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( @@ -602,7 +595,7 @@ void _showSpringDialog(BuildContext context, _) { onPressed: Get.back, child: Text( '取消', - style: TextStyle(color: Theme.of(context).colorScheme.outline), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( @@ -794,12 +787,8 @@ void _showScrollDialog(BuildContext context) { content: TextFormField( autofocus: true, initialValue: scrollThreshold, - keyboardType: const TextInputType.numberWithOptions( - decimal: true, - ), - onChanged: (value) { - scrollThreshold = value; - }, + keyboardType: const .numberWithOptions(decimal: true), + onChanged: (value) => scrollThreshold = value, inputFormatters: [ FilteringTextInputFormatter.allow(RegExp(r'[\d\.]+')), ], @@ -810,22 +799,19 @@ void _showScrollDialog(BuildContext context) { onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: Theme.of(context).colorScheme.outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( onPressed: () { - Get.back(); - GStorage.setting.put( - SettingBoxKey.scrollThreshold, - max( - 10.0, - double.tryParse(scrollThreshold) ?? 50.0, - ), - ); - SmartDialog.showToast('重启生效'); + try { + final val = double.parse(scrollThreshold); + Get.back(); + GStorage.setting.put(SettingBoxKey.scrollThreshold, val); + SmartDialog.showToast('重启生效'); + } catch (e) { + SmartDialog.showToast(e.toString()); + } }, child: const Text('确定'), ), diff --git a/lib/pages/setting/models/video_settings.dart b/lib/pages/setting/models/video_settings.dart index b54e22c00..7e761e65f 100644 --- a/lib/pages/setting/models/video_settings.dart +++ b/lib/pages/setting/models/video_settings.dart @@ -195,9 +195,7 @@ Future _showLiveCDNDialog( onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: ColorScheme.of(context).outline, - ), + style: TextStyle(color: ColorScheme.of(context).outline), ), ), TextButton( diff --git a/lib/pages/setting/pages/play_speed_set.dart b/lib/pages/setting/pages/play_speed_set.dart index 4b9336fb1..cf2277076 100644 --- a/lib/pages/setting/pages/play_speed_set.dart +++ b/lib/pages/setting/pages/play_speed_set.dart @@ -56,7 +56,7 @@ class _PlaySpeedPageState extends State { // 添加自定义倍速 void onAddSpeed() { - double? customSpeed; + String initialValue = ''; showDialog( context: context, builder: (context) => AlertDialog( @@ -65,20 +65,15 @@ class _PlaySpeedPageState extends State { mainAxisSize: MainAxisSize.min, children: [ const SizedBox(height: 12), - TextField( + TextFormField( autofocus: true, - keyboardType: const TextInputType.numberWithOptions( - decimal: true, - ), + initialValue: initialValue, + keyboardType: const .numberWithOptions(decimal: true), decoration: const InputDecoration( labelText: '自定义倍速', - border: OutlineInputBorder( - borderRadius: BorderRadius.all(Radius.circular(6)), - ), + border: OutlineInputBorder(borderRadius: .all(.circular(6))), ), - onChanged: (value) { - customSpeed = double.tryParse(value); - }, + onChanged: (value) => initialValue = value, inputFormatters: [ FilteringTextInputFormatter.allow(RegExp(r'[\d\.]+')), ], @@ -95,17 +90,20 @@ class _PlaySpeedPageState extends State { ), TextButton( onPressed: () { - if (customSpeed == null) { - SmartDialog.showToast('输入倍数不合法'); - } else if (speedList.contains(customSpeed)) { - SmartDialog.showToast('该倍速已存在'); - } else { - Get.back(); - speedList - ..add(customSpeed!) - ..sort(); - video.put(VideoBoxKey.speedsList, speedList); - setState(() {}); + try { + final val = double.parse(initialValue); + if (speedList.contains(val)) { + SmartDialog.showToast('该倍速已存在'); + } else { + Get.back(); + speedList + ..add(val) + ..sort(); + video.put(VideoBoxKey.speedsList, speedList); + setState(() {}); + } + } catch (e) { + SmartDialog.showToast(e.toString()); } }, child: const Text('确认'), @@ -267,6 +265,7 @@ class _PlaySpeedPageState extends State { children: List.generate( speedList.length, (index) => FilledButton.tonal( + style: FilledButton.styleFrom(tapTargetSize: .padded), onPressed: () => showBottomSheet(theme, index), child: Text(speedList[index].toString()), ), diff --git a/lib/pages/sponsor_block/view.dart b/lib/pages/sponsor_block/view.dart index f4ca874a5..d4ed379c9 100644 --- a/lib/pages/sponsor_block/view.dart +++ b/lib/pages/sponsor_block/view.dart @@ -1,5 +1,3 @@ -import 'dart:math'; - import 'package:PiliPlus/common/widgets/pair.dart'; import 'package:PiliPlus/http/constants.dart'; import 'package:PiliPlus/http/init.dart'; @@ -17,6 +15,7 @@ import 'package:PiliPlus/utils/utils.dart'; import 'package:crypto/crypto.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart' show FilteringTextInputFormatter; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:hive/hive.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; @@ -98,20 +97,19 @@ class _SponsorBlockPageState extends State { onPressed: Get.back, child: Text( '取消', - style: TextStyle( - color: theme.colorScheme.outline, - ), + style: TextStyle(color: theme.colorScheme.outline), ), ), TextButton( onPressed: () { - Get.back(); - _blockLimit = max( - 0.0, - double.tryParse(_textController.text) ?? 0.0, - ); - setting.put(SettingBoxKey.blockLimit, _blockLimit); - (context as Element).markNeedsBuild(); + try { + _blockLimit = double.parse(_textController.text); + Get.back(); + setting.put(SettingBoxKey.blockLimit, _blockLimit); + (context as Element).markNeedsBuild(); + } catch (e) { + SmartDialog.showToast(e.toString()); + } }, child: const Text('确定'), ), diff --git a/lib/utils/page_utils.dart b/lib/utils/page_utils.dart index 10f3ed3cf..1797e982b 100644 --- a/lib/utils/page_utils.dart +++ b/lib/utils/page_utils.dart @@ -154,12 +154,16 @@ abstract final class PageUtils { ), TextButton( onPressed: () { - Get.back(); - int choice = int.tryParse(duration) ?? 0; - shutdownTimerService - ..scheduledExitInMinutes = choice - ..startShutdownTimer(); - setState(() {}); + try { + final choice = int.parse(duration); + Get.back(); + shutdownTimerService + ..scheduledExitInMinutes = choice + ..startShutdownTimer(); + setState(() {}); + } catch (e) { + SmartDialog.showToast(e.toString()); + } }, child: const Text('确定'), ),