Skip to content

Commit

Permalink
clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
3003h committed Dec 19, 2024
1 parent 5b183dc commit e7e8f1e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
1 change: 1 addition & 0 deletions lib/common/controller/log_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class LogService extends GetxController {
isLoading = true;
logFiles.value = await compute(loadFilesIsolate, logPath);
isLoading = false;
logger.d('loadFiles');
}

Future<void> refreshFiles() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Future<void> main() async {
appRunner: () => runApp(const MyApp()),
);
} else {
runApp(MyApp());
runApp(const MyApp());
}

if (GetPlatform.isDesktop) {
Expand Down
30 changes: 15 additions & 15 deletions lib/pages/setting/block/block_rule_edit_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@ class BlockRuleEditPage extends GetView<BlockController> {

@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,
enabled: true,
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,
onPressed: controller.isRegexFormatError
? null
: () async {
FocusScope.of(context).requestFocus(FocusNode());
logger.d('_blockRule ${_blockRule.toJson()}');
logger.d('blockRule ${blockRule.toJson()}');
Get.back<BlockRule>(
id: isLayoutLarge ? 2 : null,
result: _blockRule,
result: blockRule,
);
},
child: const Icon(
Expand All @@ -60,9 +60,9 @@ class BlockRuleEditPage extends GetView<BlockController> {
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(() {});
},
);
Expand All @@ -74,9 +74,9 @@ class BlockRuleEditPage extends GetView<BlockController> {
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(() {});
},
Expand All @@ -85,10 +85,10 @@ class BlockRuleEditPage extends GetView<BlockController> {
),
_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);
},
),
]),
Expand All @@ -115,7 +115,7 @@ class BlockRuleEditPage extends GetView<BlockController> {
keyboardType: TextInputType.text,
onChanged: (value) {
logger.t('value $value');
_blockRule = _blockRule.copyWith(
blockRule = blockRule.copyWith(
ruleText: value.replaceAll('\n', ' ').oN);
},
),
Expand Down
26 changes: 13 additions & 13 deletions lib/pages/setting/download_setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<DownloadOrigImageType, String> modeMap =
Expand All @@ -148,7 +148,7 @@ Widget _buildDownloadOrigImageItem(BuildContext context) {
};
return Obx(() {
return SelectorCupertinoListTile<DownloadOrigImageType>(
title: _title,
title: title,
actionMap: modeMap,
initVal: ehSettingService.downloadOrigType,
onValueChanged: (val) => ehSettingService.downloadOrigType = val,
Expand All @@ -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<Widget> _getModeList(BuildContext context) {
Expand Down Expand Up @@ -190,21 +190,21 @@ 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);
}
},
));
}

/// 同时下载图片数量
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<Widget> _getModeList(BuildContext context) {
Expand Down Expand Up @@ -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<DownloadController>().resetConcurrency();
}
}
Expand Down
24 changes: 13 additions & 11 deletions lib/pages/setting/log_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ class LogPage extends GetView<LogService> {
),
),
),
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(),
),
],
),
);
}
}
Expand Down

0 comments on commit e7e8f1e

Please sign in to comment.