Skip to content

Commit

Permalink
Show resource download status
Browse files Browse the repository at this point in the history
  • Loading branch information
anhappdev committed Nov 11, 2024
1 parent 8e8f8df commit 79d2ee3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
9 changes: 9 additions & 0 deletions flutter/lib/resources/validation_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ class ValidationHelper {
.mapIndexed((i, element) => '\n${i + 1}) $element')
.join();
}

Future<bool> validateResourcesExist(Benchmark benchmark) async {
final resources = benchmarkStore.listResources(
modes: [BenchmarkRunMode.performance, BenchmarkRunMode.accuracy],
benchmarks: [benchmark],
);
final missing = await resourceManager.validateResourcesExist(resources);
return missing.isEmpty;
}
}
23 changes: 20 additions & 3 deletions flutter/lib/ui/settings/resources_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:io';

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

Expand Down Expand Up @@ -41,7 +43,7 @@ class _ResourcesScreen extends State<ResourcesScreen> {
final children = <Widget>[];

for (var benchmark in state.benchmarks) {
children.add(_listTile(benchmark));
children.add(_listTileBuilder(benchmark));
children.add(const Divider(height: 20));
}
children.add(Text(loadingProgressText));
Expand All @@ -62,10 +64,11 @@ class _ResourcesScreen extends State<ResourcesScreen> {
);
}

Widget _listTile(Benchmark benchmark) {
Widget _listTile(Benchmark benchmark, bool downloaded) {
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;
final status = downloaded ? 'downloaded' : 'not downloaded';
return ListTile(
leading: SizedBox(
width: leadingWidth,
Expand All @@ -77,7 +80,7 @@ class _ResourcesScreen extends State<ResourcesScreen> {
title: Text(benchmark.info.taskName),
subtitle: SizedBox(
width: subtitleWidth,
child: const Text('Download progress...'),
child: Text(status),
),
trailing: SizedBox(
width: trailingWidth,
Expand All @@ -86,6 +89,20 @@ class _ResourcesScreen extends State<ResourcesScreen> {
);
}

Widget _listTileBuilder(Benchmark benchmark) {
return FutureBuilder<bool>(
future: state.validator.validateResourcesExist(benchmark),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
if (snapshot.hasData && snapshot.data != null) {
final downloaded = snapshot.data!;
return _listTile(benchmark, downloaded);
} else {
return const Text('Checking download status');
}
},
);
}

Widget _downloadButton(Benchmark benchmark) {
return ElevatedButton(
onPressed: () {
Expand Down

0 comments on commit 79d2ee3

Please sign in to comment.