From e7e8f1e14acd226e73d6932dcfd52a66ff2f3e37 Mon Sep 17 00:00:00 2001 From: 3003h Date: Thu, 19 Dec 2024 18:29:43 +0800 Subject: [PATCH] clean up code --- lib/common/controller/log_controller.dart | 1 + lib/main.dart | 2 +- .../setting/block/block_rule_edit_page.dart | 30 +++++++++---------- lib/pages/setting/download_setting_page.dart | 26 ++++++++-------- lib/pages/setting/log_page.dart | 24 ++++++++------- 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/lib/common/controller/log_controller.dart b/lib/common/controller/log_controller.dart index 2bd353153..148e6b0c5 100644 --- a/lib/common/controller/log_controller.dart +++ b/lib/common/controller/log_controller.dart @@ -52,6 +52,7 @@ class LogService extends GetxController { isLoading = true; logFiles.value = await compute(loadFilesIsolate, logPath); isLoading = false; + logger.d('loadFiles'); } Future refreshFiles() async { diff --git a/lib/main.dart b/lib/main.dart index 027ee976a..92a1e25f1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -79,7 +79,7 @@ Future main() async { appRunner: () => runApp(const MyApp()), ); } else { - runApp(MyApp()); + runApp(const MyApp()); } if (GetPlatform.isDesktop) { diff --git a/lib/pages/setting/block/block_rule_edit_page.dart b/lib/pages/setting/block/block_rule_edit_page.dart index e4a716221..9b3e40df9 100644 --- a/lib/pages/setting/block/block_rule_edit_page.dart +++ b/lib/pages/setting/block/block_rule_edit_page.dart @@ -11,12 +11,12 @@ class BlockRuleEditPage extends GetView { @override Widget build(BuildContext context) { - final String _title = L10n.of(context).edit_block_rule; + final String title = L10n.of(context).edit_block_rule; - final BlockRule? _blockRuleFromArg = + final BlockRule? blockRuleFromArg = Get.arguments is BlockRule ? Get.arguments as BlockRule : null; - BlockRule _blockRule = _blockRuleFromArg ?? + BlockRule blockRule = blockRuleFromArg ?? BlockRule( ruleText: '', blockType: controller.latestBlockType?.name ?? BlockType.title.name, @@ -24,13 +24,13 @@ class BlockRuleEditPage extends GetView { enableRegex: controller.latestEnableRegex ?? false, ); - controller.blockRuleTextEditingController.text = _blockRule.ruleText ?? ''; - controller.currentEnableRegex = _blockRule.enableRegex ?? false; + controller.blockRuleTextEditingController.text = blockRule.ruleText ?? ''; + controller.currentEnableRegex = blockRule.enableRegex ?? false; return CupertinoPageScaffold( backgroundColor: CupertinoColors.systemGroupedBackground, navigationBar: CupertinoNavigationBar( - middle: Text(_title), + middle: Text(title), trailing: CupertinoButton( padding: const EdgeInsets.all(0), minSize: 40, @@ -38,10 +38,10 @@ class BlockRuleEditPage extends GetView { ? null : () async { FocusScope.of(context).requestFocus(FocusNode()); - logger.d('_blockRule ${_blockRule.toJson()}'); + logger.d('blockRule ${blockRule.toJson()}'); Get.back( id: isLayoutLarge ? 2 : null, - result: _blockRule, + result: blockRule, ); }, child: const Icon( @@ -60,9 +60,9 @@ class BlockRuleEditPage extends GetView { title: Text(L10n.of(context).enable), trailing: StatefulBuilder(builder: (context, setState) { return CupertinoSwitch( - value: _blockRule.enabled ?? true, + value: blockRule.enabled ?? true, onChanged: (val) { - _blockRule = _blockRule.copyWith(enabled: val.oN); + blockRule = blockRule.copyWith(enabled: val.oN); setState(() {}); }, ); @@ -74,9 +74,9 @@ class BlockRuleEditPage extends GetView { title: Text(L10n.of(context).regex), trailing: StatefulBuilder(builder: (context, setState) { return CupertinoSwitch( - value: _blockRule.enableRegex ?? false, + value: blockRule.enableRegex ?? false, onChanged: (val) { - _blockRule = _blockRule.copyWith(enableRegex: val.oN); + blockRule = blockRule.copyWith(enableRegex: val.oN); controller.currentEnableRegex = val; setState(() {}); }, @@ -85,10 +85,10 @@ class BlockRuleEditPage extends GetView { ), _BlockTypeSelector( initValue: BlockType.values - .byName(_blockRule.blockType ?? BlockType.title.name), + .byName(blockRule.blockType ?? BlockType.title.name), onChanged: (BlockType value) { controller.latestBlockType = value; - _blockRule = _blockRule.copyWith(blockType: value.name.oN); + blockRule = blockRule.copyWith(blockType: value.name.oN); }, ), ]), @@ -115,7 +115,7 @@ class BlockRuleEditPage extends GetView { keyboardType: TextInputType.text, onChanged: (value) { logger.t('value $value'); - _blockRule = _blockRule.copyWith( + blockRule = blockRule.copyWith( ruleText: value.replaceAll('\n', ' ').oN); }, ), diff --git a/lib/pages/setting/download_setting_page.dart b/lib/pages/setting/download_setting_page.dart index 01337b430..0b23d140c 100644 --- a/lib/pages/setting/download_setting_page.dart +++ b/lib/pages/setting/download_setting_page.dart @@ -137,7 +137,7 @@ class DownloadSetting extends StatelessWidget { /// 下载原图 Widget _buildDownloadOrigImageItem(BuildContext context) { - final String _title = L10n.of(context).download_ori_image; + final String title = L10n.of(context).download_ori_image; final EhSettingService ehSettingService = Get.find(); final Map modeMap = @@ -148,7 +148,7 @@ Widget _buildDownloadOrigImageItem(BuildContext context) { }; return Obx(() { return SelectorCupertinoListTile( - title: _title, + title: title, actionMap: modeMap, initVal: ehSettingService.downloadOrigType, onValueChanged: (val) => ehSettingService.downloadOrigType = val, @@ -158,7 +158,7 @@ Widget _buildDownloadOrigImageItem(BuildContext context) { /// 预载图片数量 Widget _buildPreloadImageItem(BuildContext context) { - final String _title = L10n.of(context).preload_image; + final String title = L10n.of(context).preload_image; final EhSettingService ehSettingService = Get.find(); List _getModeList(BuildContext context) { @@ -190,13 +190,13 @@ Widget _buildPreloadImageItem(BuildContext context) { } return Obx(() => EhCupertinoListTile( - title: Text(_title), + title: Text(title), trailing: const CupertinoListTileChevron(), additionalInfo: Text(ehSettingService.preloadImage.toString()), onTap: () async { - final int? _result = await _showActionSheet(context); - if (_result != null) { - ehSettingService.preloadImage(_result); + final int? result = await _showActionSheet(context); + if (result != null) { + ehSettingService.preloadImage(result); } }, )); @@ -204,7 +204,7 @@ Widget _buildPreloadImageItem(BuildContext context) { /// 同时下载图片数量 Widget _buildMultiDownloadItem(BuildContext context) { - final String _title = L10n.of(context).multi_download; + final String title = L10n.of(context).multi_download; final EhSettingService ehSettingService = Get.find(); List _getModeList(BuildContext context) { @@ -236,14 +236,14 @@ Widget _buildMultiDownloadItem(BuildContext context) { } return Obx(() => EhCupertinoListTile( - title: Text(_title), + title: Text(title), trailing: const CupertinoListTileChevron(), additionalInfo: Text(ehSettingService.multiDownload.toString()), onTap: () async { - final int? _result = await _showActionSheet(context); - if (_result != null) { - if (ehSettingService.multiDownload != _result) { - ehSettingService.multiDownload = _result; + final int? result = await _showActionSheet(context); + if (result != null) { + if (ehSettingService.multiDownload != result) { + ehSettingService.multiDownload = result; Get.find().resetConcurrency(); } } diff --git a/lib/pages/setting/log_page.dart b/lib/pages/setting/log_page.dart index d08b8b442..ee236348b 100644 --- a/lib/pages/setting/log_page.dart +++ b/lib/pages/setting/log_page.dart @@ -26,17 +26,19 @@ class LogPage extends GetView { ), ), ), - child: CustomScrollView(slivers: [ - SliverSafeArea( - bottom: false, - sliver: - CupertinoSliverRefreshControl(onRefresh: controller.refreshFiles), - ), - const SliverSafeArea( - top: false, - sliver: LogListView(), - ), - ]), + child: CustomScrollView( + slivers: [ + SliverSafeArea( + bottom: false, + sliver: CupertinoSliverRefreshControl( + onRefresh: controller.refreshFiles), + ), + const SliverSafeArea( + top: false, + sliver: LogListView(), + ), + ], + ), ); } }