Skip to content

Commit

Permalink
Move clearCacheButton from settings_screen to resources_screen
Browse files Browse the repository at this point in the history
  • Loading branch information
anhappdev committed Nov 11, 2024
1 parent f411947 commit 8e8f8df
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 39 deletions.
3 changes: 2 additions & 1 deletion flutter/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"settingsTaskConfigError": "Path to config is invalid:",
"settingsTaskDataFolderTitle": "Data folder",
"settingsClearCache": "Clear cache",
"settingsClearCacheConfirm": "All loaded resources will be deleted and downloaded again. Continue?",
"settingsClearCacheConfirm": "All downloaded resources will be deleted. Continue?",
"settingsClearCacheFinished": "Cache cleared.",
"settingsUnableSpecifyConfiguration": "Could not specify until benchmarks is running or content is loading",

"dialogTitleWarning": "Warning",
Expand Down
99 changes: 87 additions & 12 deletions flutter/lib/ui/settings/resources_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:mlperfbench/benchmark/benchmark.dart';

import 'package:provider/provider.dart';

Expand Down Expand Up @@ -34,20 +35,94 @@ class _ResourcesScreen extends State<ResourcesScreen> {
state = context.watch<BenchmarkState>();
l10n = AppLocalizations.of(context)!;

final loadingProgressText =
'Loading progress: ${(state.loadingProgress * 100).round()}%';

final children = <Widget>[];

for (var benchmark in state.benchmarks) {
children.add(_listTile(benchmark));
children.add(const Divider(height: 20));
}
children.add(Text(loadingProgressText));
children.add(const Divider(height: 20));
children.add(_clearCacheButton());

return Scaffold(
appBar: AppBar(title: Text(l10n.menuResources)),
body: SafeArea(
child: ListView(
padding: const EdgeInsets.only(top: 20),
children: [
_mainSection(),
const Divider(),
const SizedBox(height: 20)
],
)));
appBar: AppBar(title: Text(l10n.menuResources)),
body: SafeArea(
child: Container(
color: Colors.white,
child: ListView(
padding: const EdgeInsets.fromLTRB(0, 20, 0, 20),
children: children,
),
),
),
);
}

Widget _listTile(Benchmark benchmark) {
final leadingWidth = 0.10 * MediaQuery.of(context).size.width;
final subtitleWidth = 0.70 * MediaQuery.of(context).size.width;
final trailingWidth = 0.20 * MediaQuery.of(context).size.width;
return ListTile(
leading: SizedBox(
width: leadingWidth,
height: leadingWidth,
child: Padding(
padding: const EdgeInsets.all(4),
child: benchmark.info.icon,
)),
title: Text(benchmark.info.taskName),
subtitle: SizedBox(
width: subtitleWidth,
child: const Text('Download progress...'),
),
trailing: SizedBox(
width: trailingWidth,
child: _downloadButton(benchmark),
),
);
}

Widget _downloadButton(Benchmark benchmark) {
return ElevatedButton(
onPressed: () {
print('download files for ${benchmark.info.taskName}');
print(benchmark.taskConfig.datasets.lite.inputPath);
print(benchmark.taskConfig.datasets.lite.groundtruthPath);
},
child: FittedBox(
fit: BoxFit.scaleDown,
child: const Text('Download'),
),
);
}

Widget _mainSection() {
return const Text('data');
Widget _clearCacheButton() {
return TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
),
onPressed: () async {
final dialogAction =
await showConfirmDialog(context, l10n.settingsClearCacheConfirm);
switch (dialogAction) {
case ConfirmDialogAction.ok:
await state.clearCache();
BotToast.showSimpleNotification(
title: l10n.settingsClearCacheFinished,
hideCloseButton: true,
);
break;
case ConfirmDialogAction.cancel:
break;
default:
break;
}
},
child: Text(l10n.settingsClearCache),
);
}
}
26 changes: 0 additions & 26 deletions flutter/lib/ui/settings/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class _SettingsScreen extends State<SettingsScreen> {
Widget keepLogSwitch = _keepLogSwitch();
Widget cooldownSwitch = _cooldownSwitch();
Widget cooldownSlider = _cooldownSlider();
Widget clearCacheButton = _clearCacheButton(context);
Widget versionText = _versionText();
Widget taskConfig = _taskConfig(context);

Expand All @@ -61,7 +60,6 @@ class _SettingsScreen extends State<SettingsScreen> {
crashlyticsSwitch,
taskConfig,
const Divider(),
clearCacheButton,
const Divider(),
versionText,
const SizedBox(height: 20)
Expand Down Expand Up @@ -92,30 +90,6 @@ class _SettingsScreen extends State<SettingsScreen> {
);
}

Widget _clearCacheButton(BuildContext context) {
return TextButton(
style: TextButton.styleFrom(
textStyle: const TextStyle(fontSize: 20),
),
onPressed: () async {
final dialogAction =
await showConfirmDialog(context, l10n.settingsClearCacheConfirm);
switch (dialogAction) {
case ConfirmDialogAction.ok:
await state.clearCache();
if (!context.mounted) return;
Navigator.pop(context);
break;
case ConfirmDialogAction.cancel:
break;
default:
break;
}
},
child: Text(l10n.settingsClearCache),
);
}

Widget _cooldownSlider() {
return Slider(
value: store.cooldownDuration.toDouble(),
Expand Down

0 comments on commit 8e8f8df

Please sign in to comment.