From 7016e79652ec14605a7385556cb993ce1e302d20 Mon Sep 17 00:00:00 2001 From: Anh Date: Tue, 20 Feb 2024 13:50:57 +0700 Subject: [PATCH 1/9] Remove InfiniteProgressCircle --- flutter/lib/ui/home/benchmark_running_screen.dart | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/flutter/lib/ui/home/benchmark_running_screen.dart b/flutter/lib/ui/home/benchmark_running_screen.dart index 05b590ca8..88bfc78b6 100644 --- a/flutter/lib/ui/home/benchmark_running_screen.dart +++ b/flutter/lib/ui/home/benchmark_running_screen.dart @@ -114,10 +114,10 @@ class _BenchmarkRunningScreenState extends State { ), ), ), - InfiniteProgressCircle( - size: containerWidth + 20, - strokeWidth: 6.0, - ), + // InfiniteProgressCircle( + // size: containerWidth + 20, + // strokeWidth: 6.0, + // ), ], ); } @@ -201,10 +201,7 @@ class _BenchmarkRunningScreenState extends State { const trailingWidth = 24.0; Widget? doneIcon; if (progress.currentBenchmark?.taskName == benchmarkInfo.taskName) { - doneIcon = const InfiniteProgressCircle( - size: trailingWidth, - strokeWidth: 2, - ); + doneIcon = null; } else if (progress.completedBenchmarks.contains(benchmarkInfo)) { doneIcon = const Icon( Icons.check_circle, From 1ffdb59e229c7d1289e07a6fdcedf6ee5a58a031 Mon Sep 17 00:00:00 2001 From: Anh Date: Thu, 8 Feb 2024 15:31:34 +0700 Subject: [PATCH 2/9] Use GitHub vars for --num-flaky-test-attempts flag --- .github/workflows/android-build-test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/android-build-test.yml b/.github/workflows/android-build-test.yml index 8ced2cd29..ccf84647c 100644 --- a/.github/workflows/android-build-test.yml +++ b/.github/workflows/android-build-test.yml @@ -204,7 +204,7 @@ jobs: --app $GCLOUD_BUCKET_PATH/test-main-tflite.apk \ --test $GCLOUD_BUCKET_PATH/test-helper-tflite.apk \ --timeout 30m \ - --num-flaky-test-attempts 2 \ + --num-flaky-test-attempts ${{ vars.NUM_FLAKY_TEST_ATTEMPTS }} \ --device model=redfin,version=30,locale=en,orientation=portrait \ --client-details=buildNumber=${{ github.run_number }} @@ -229,7 +229,7 @@ jobs: --app $GCLOUD_BUCKET_PATH/test-main-pixel.apk \ --test $GCLOUD_BUCKET_PATH/test-helper-pixel.apk \ --timeout 30m \ - --num-flaky-test-attempts 2 \ + --num-flaky-test-attempts ${{ vars.NUM_FLAKY_TEST_ATTEMPTS }} \ --device model=oriole,version=32,locale=en,orientation=portrait \ --client-details=buildNumber=${{ github.run_number }} @@ -254,7 +254,7 @@ jobs: --app $GCLOUD_BUCKET_PATH/test-main-qti.apk \ --test $GCLOUD_BUCKET_PATH/test-helper-qti.apk \ --timeout 30m \ - --num-flaky-test-attempts 2 \ + --num-flaky-test-attempts ${{ vars.NUM_FLAKY_TEST_ATTEMPTS }} \ --device model=b0q,version=33,locale=en,orientation=portrait \ --client-details=buildNumber=${{ github.run_number }} @@ -279,6 +279,6 @@ jobs: --app $GCLOUD_BUCKET_PATH/test-main-mtk.apk \ --test $GCLOUD_BUCKET_PATH/test-helper-mtk.apk \ --timeout 30m \ - --num-flaky-test-attempts 2 \ + --num-flaky-test-attempts ${{ vars.NUM_FLAKY_TEST_ATTEMPTS }} \ --device model=OP515BL1,version=33,locale=en,orientation=portrait \ --client-details=buildNumber=${{ github.run_number }} From c8fcb6b91ae2232aaba7d3efb2d8746902d2374c Mon Sep 17 00:00:00 2001 From: Anh Date: Thu, 22 Feb 2024 12:15:18 +0700 Subject: [PATCH 3/9] Format Dart code --- flutter/lib/ui/home/benchmark_running_screen.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/flutter/lib/ui/home/benchmark_running_screen.dart b/flutter/lib/ui/home/benchmark_running_screen.dart index 88bfc78b6..b489952a3 100644 --- a/flutter/lib/ui/home/benchmark_running_screen.dart +++ b/flutter/lib/ui/home/benchmark_running_screen.dart @@ -13,7 +13,6 @@ import 'package:mlperfbench/localizations/app_localizations.dart'; import 'package:mlperfbench/state/task_runner.dart'; import 'package:mlperfbench/ui/app_styles.dart'; import 'package:mlperfbench/ui/formatter.dart'; -import 'package:mlperfbench/ui/home/progress_circles.dart'; import 'package:mlperfbench/ui/icons.dart'; class BenchmarkRunningScreen extends StatefulWidget { From ef1c42795fe563ee87d2146a1eb177840c144912 Mon Sep 17 00:00:00 2001 From: Anh Date: Thu, 22 Feb 2024 12:33:39 +0700 Subject: [PATCH 4/9] Add DottedProgressCircle --- .../lib/ui/home/benchmark_running_screen.dart | 14 ++- .../lib/ui/home/dotted_progress_circle.dart | 103 ++++++++++++++++++ 2 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 flutter/lib/ui/home/dotted_progress_circle.dart diff --git a/flutter/lib/ui/home/benchmark_running_screen.dart b/flutter/lib/ui/home/benchmark_running_screen.dart index b489952a3..4994622dd 100644 --- a/flutter/lib/ui/home/benchmark_running_screen.dart +++ b/flutter/lib/ui/home/benchmark_running_screen.dart @@ -4,6 +4,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:collection/collection.dart'; +import 'package:mlperfbench/ui/home/dotted_progress_circle.dart'; import 'package:provider/provider.dart'; import 'package:mlperfbench/benchmark/info.dart'; @@ -113,10 +114,10 @@ class _BenchmarkRunningScreenState extends State { ), ), ), - // InfiniteProgressCircle( - // size: containerWidth + 20, - // strokeWidth: 6.0, - // ), + DottedProgressCircle( + circleSize: containerWidth + 20, + dotSize: 10, + ), ], ); } @@ -200,7 +201,10 @@ class _BenchmarkRunningScreenState extends State { const trailingWidth = 24.0; Widget? doneIcon; if (progress.currentBenchmark?.taskName == benchmarkInfo.taskName) { - doneIcon = null; + doneIcon = const DottedProgressCircle( + circleSize: trailingWidth + 20, + dotSize: 2, + ); } else if (progress.completedBenchmarks.contains(benchmarkInfo)) { doneIcon = const Icon( Icons.check_circle, diff --git a/flutter/lib/ui/home/dotted_progress_circle.dart b/flutter/lib/ui/home/dotted_progress_circle.dart new file mode 100644 index 000000000..581f021c4 --- /dev/null +++ b/flutter/lib/ui/home/dotted_progress_circle.dart @@ -0,0 +1,103 @@ +import 'dart:async'; +import 'dart:math'; + +import 'package:flutter/material.dart'; + +class DottedProgressCircle extends StatefulWidget { + final double circleSize; + final double dotSize; + + const DottedProgressCircle( + {required this.circleSize, required this.dotSize, Key? key}) + : super(key: key); + + @override + State createState() => _DottedProgressCircleState(); +} + +class _DottedProgressCircleState extends State { + static const circlesCount = 10; + + late final Timer _timer; + + bool _increase = true; + int _startCircleNumber = 0; + int _endCircleNumber = 1; + + void _updateState() { + if (_increase) { + if (_startCircleNumber == circlesCount) { + _startCircleNumber = 0; + _endCircleNumber = 1; + } else { + _endCircleNumber++; + } + + if (_endCircleNumber == circlesCount) { + _increase = false; + } + } else { + _startCircleNumber++; + + if (_startCircleNumber == circlesCount) { + _increase = true; + } + } + } + + @override + void initState() { + _timer = Timer.periodic( + const Duration(seconds: 1), + (_) => setState(_updateState), + ); + super.initState(); + } + + @override + void dispose() { + _timer.cancel(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return CustomPaint( + size: Size(widget.circleSize, widget.circleSize), + painter: _ProgressCirclesPaint( + _startCircleNumber, + _endCircleNumber, + widget.dotSize, + )); + } +} + +class _ProgressCirclesPaint extends CustomPainter { + final int _startCircleNumber; + final int _endCircleNumber; + final double _circleRadius; + + _ProgressCirclesPaint( + this._startCircleNumber, this._endCircleNumber, this._circleRadius); + + final Paint _paintLine = Paint() + ..color = Colors.white + ..style = PaintingStyle.fill; + final double pi = 3.1415926535897932; + + @override + void paint(Canvas canvas, Size size) { + for (var i = _startCircleNumber; i < _endCircleNumber; i++) { + final currentDegree = + 2 * pi * ((i) / _DottedProgressCircleState.circlesCount) + pi / 2; + final x = (size.width + size.height * cos(currentDegree)) / 2; + final y = (size.height + size.width * sin(currentDegree)) / 2; + canvas.drawCircle(Offset(x, y), _circleRadius, _paintLine); + } + } // paint + + @override + bool shouldRepaint(_ProgressCirclesPaint old) => + old._endCircleNumber != _endCircleNumber || + old._startCircleNumber != _startCircleNumber; +} From c14cc6309b5cb4d4e75b2d1e5a899cb385a5ef82 Mon Sep 17 00:00:00 2001 From: Anh Date: Thu, 22 Feb 2024 12:56:41 +0700 Subject: [PATCH 5/9] Add setting for progress animation style --- flutter/lib/store.dart | 9 ++++ .../lib/ui/home/benchmark_running_screen.dart | 42 +++++++++++++++---- ...les.dart => infinite_progress_circle.dart} | 8 ++-- flutter/lib/ui/settings/settings_screen.dart | 23 ++++++++++ 4 files changed, 69 insertions(+), 13 deletions(-) rename flutter/lib/ui/home/{progress_circles.dart => infinite_progress_circle.dart} (85%) diff --git a/flutter/lib/store.dart b/flutter/lib/store.dart index 93139dcc3..b54ffa83e 100644 --- a/flutter/lib/store.dart +++ b/flutter/lib/store.dart @@ -29,6 +29,14 @@ class Store extends ChangeNotifier { return value ?? ''; } + int get progressAnimationMode => + _getInt(StoreConstants.progressAnimationMode, 0); + + set progressAnimationMode(int value) { + _storeFromDisk.setInt(StoreConstants.progressAnimationMode, value); + notifyListeners(); + } + BenchmarkRunModeEnum get selectedBenchmarkRunMode { String name = _getString(StoreConstants.selectedBenchmarkRunMode); if (name == '') name = BenchmarkRunModeEnum.performanceOnly.name; @@ -142,6 +150,7 @@ class Store extends ChangeNotifier { } class StoreConstants { + static const progressAnimationMode = 'progressAnimationMode'; static const selectedBenchmarkRunMode = 'selectedBenchmarkRunMode'; static const artificialCPULoadEnabled = 'artificial cpu load enabled'; static const offlineMode = 'offline mode'; diff --git a/flutter/lib/ui/home/benchmark_running_screen.dart b/flutter/lib/ui/home/benchmark_running_screen.dart index 4994622dd..3a90bf901 100644 --- a/flutter/lib/ui/home/benchmark_running_screen.dart +++ b/flutter/lib/ui/home/benchmark_running_screen.dart @@ -4,7 +4,6 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:collection/collection.dart'; -import 'package:mlperfbench/ui/home/dotted_progress_circle.dart'; import 'package:provider/provider.dart'; import 'package:mlperfbench/benchmark/info.dart'; @@ -12,8 +11,11 @@ import 'package:mlperfbench/benchmark/run_mode.dart'; import 'package:mlperfbench/benchmark/state.dart'; import 'package:mlperfbench/localizations/app_localizations.dart'; import 'package:mlperfbench/state/task_runner.dart'; +import 'package:mlperfbench/store.dart'; import 'package:mlperfbench/ui/app_styles.dart'; import 'package:mlperfbench/ui/formatter.dart'; +import 'package:mlperfbench/ui/home/dotted_progress_circle.dart'; +import 'package:mlperfbench/ui/home/infinite_progress_circle.dart'; import 'package:mlperfbench/ui/icons.dart'; class BenchmarkRunningScreen extends StatefulWidget { @@ -30,11 +32,13 @@ class _BenchmarkRunningScreenState extends State { late BenchmarkState state; late AppLocalizations l10n; late ProgressInfo progress; + late Store store; @override Widget build(BuildContext context) { state = context.watch(); l10n = AppLocalizations.of(context); + store = context.watch(); progress = state.taskRunner.progressInfo; final backgroundGradient = BoxDecoration( @@ -90,6 +94,20 @@ class _BenchmarkRunningScreenState extends State { var containerWidth = 0.50 * MediaQuery.of(context).size.width; containerWidth = max(containerWidth, 160); containerWidth = min(containerWidth, 240); + Widget animation; + if (store.progressAnimationMode == 1) { + animation = DottedProgressCircle( + circleSize: containerWidth + 40, + dotSize: 10, + ); + } else if (store.progressAnimationMode == 2) { + animation = GradientProgressCircle( + size: containerWidth + 20, + strokeWidth: 6.0, + ); + } else { + animation = const SizedBox(height: 0); + } return Stack( alignment: AlignmentDirectional.center, children: [ @@ -114,10 +132,7 @@ class _BenchmarkRunningScreenState extends State { ), ), ), - DottedProgressCircle( - circleSize: containerWidth + 20, - dotSize: 10, - ), + animation, ], ); } @@ -201,10 +216,19 @@ class _BenchmarkRunningScreenState extends State { const trailingWidth = 24.0; Widget? doneIcon; if (progress.currentBenchmark?.taskName == benchmarkInfo.taskName) { - doneIcon = const DottedProgressCircle( - circleSize: trailingWidth + 20, - dotSize: 2, - ); + if (store.progressAnimationMode == 1) { + doneIcon = const DottedProgressCircle( + circleSize: trailingWidth, + dotSize: 2.0, + ); + } else if (store.progressAnimationMode == 2) { + doneIcon = const GradientProgressCircle( + size: trailingWidth, + strokeWidth: 2.0, + ); + } else { + doneIcon = const SizedBox(height: 0); + } } else if (progress.completedBenchmarks.contains(benchmarkInfo)) { doneIcon = const Icon( Icons.check_circle, diff --git a/flutter/lib/ui/home/progress_circles.dart b/flutter/lib/ui/home/infinite_progress_circle.dart similarity index 85% rename from flutter/lib/ui/home/progress_circles.dart rename to flutter/lib/ui/home/infinite_progress_circle.dart index b22a86d7b..fbcdc73db 100644 --- a/flutter/lib/ui/home/progress_circles.dart +++ b/flutter/lib/ui/home/infinite_progress_circle.dart @@ -2,19 +2,19 @@ import 'package:flutter/material.dart'; import 'package:mlperfbench/ui/home/gradient_circular_progress_indicator.dart'; -class InfiniteProgressCircle extends StatefulWidget { +class GradientProgressCircle extends StatefulWidget { final double size; final double strokeWidth; - const InfiniteProgressCircle( + const GradientProgressCircle( {Key? key, required this.size, required this.strokeWidth}) : super(key: key); @override - State createState() => _InfiniteProgressCircleState(); + State createState() => _GradientProgressCircleState(); } -class _InfiniteProgressCircleState extends State +class _GradientProgressCircleState extends State with SingleTickerProviderStateMixin { late AnimationController _controller; diff --git a/flutter/lib/ui/settings/settings_screen.dart b/flutter/lib/ui/settings/settings_screen.dart index 48559e60f..633c5b31b 100644 --- a/flutter/lib/ui/settings/settings_screen.dart +++ b/flutter/lib/ui/settings/settings_screen.dart @@ -34,6 +34,7 @@ class _SettingsScreen extends State { state = context.watch(); l10n = AppLocalizations.of(context); + Widget progressAnimationDropdown = _progressAnimationDropdown(); Widget artificialLoadSwitch = _artificialLoadSwitch(); Widget crashlyticsSwitch = _crashlyticsSwitch(); Widget runModeDropdown = _runModeDropdown(); @@ -51,6 +52,7 @@ class _SettingsScreen extends State { child: ListView( padding: const EdgeInsets.only(top: 20), children: [ + progressAnimationDropdown, runModeDropdown, offlineModeSwitch, keepLogSwitch, @@ -180,6 +182,27 @@ class _SettingsScreen extends State { ); } + Widget _progressAnimationDropdown() { + return ListTile( + title: const Padding( + padding: EdgeInsets.only(bottom: 5), + child: Text('Progress Animation'), + ), + subtitle: const Text('Progress animation during a benchmark run'), + trailing: DropdownButton( + borderRadius: BorderRadius.circular(WidgetSizes.borderRadius), + value: store.progressAnimationMode, + items: const [ + DropdownMenuItem(value: 0, child: Text('No animation')), + DropdownMenuItem(value: 1, child: Text('Dotted Circle')), + DropdownMenuItem(value: 2, child: Text('Gradient Circle')), + ], + onChanged: (value) => setState(() { + store.progressAnimationMode = value!; + })), + ); + } + Widget _runModeDropdown() { return ListTile( title: Padding( From 5847a4916cde50cc652e5bb5bf60800dbd99333a Mon Sep 17 00:00:00 2001 From: Anh Date: Tue, 27 Feb 2024 15:37:02 +0700 Subject: [PATCH 6/9] Revert "Add setting for progress animation style" This reverts commit c14cc6309b5cb4d4e75b2d1e5a899cb385a5ef82. --- flutter/lib/store.dart | 9 ---- .../lib/ui/home/benchmark_running_screen.dart | 42 ++++--------------- ...ress_circle.dart => progress_circles.dart} | 8 ++-- flutter/lib/ui/settings/settings_screen.dart | 23 ---------- 4 files changed, 13 insertions(+), 69 deletions(-) rename flutter/lib/ui/home/{infinite_progress_circle.dart => progress_circles.dart} (85%) diff --git a/flutter/lib/store.dart b/flutter/lib/store.dart index b54ffa83e..93139dcc3 100644 --- a/flutter/lib/store.dart +++ b/flutter/lib/store.dart @@ -29,14 +29,6 @@ class Store extends ChangeNotifier { return value ?? ''; } - int get progressAnimationMode => - _getInt(StoreConstants.progressAnimationMode, 0); - - set progressAnimationMode(int value) { - _storeFromDisk.setInt(StoreConstants.progressAnimationMode, value); - notifyListeners(); - } - BenchmarkRunModeEnum get selectedBenchmarkRunMode { String name = _getString(StoreConstants.selectedBenchmarkRunMode); if (name == '') name = BenchmarkRunModeEnum.performanceOnly.name; @@ -150,7 +142,6 @@ class Store extends ChangeNotifier { } class StoreConstants { - static const progressAnimationMode = 'progressAnimationMode'; static const selectedBenchmarkRunMode = 'selectedBenchmarkRunMode'; static const artificialCPULoadEnabled = 'artificial cpu load enabled'; static const offlineMode = 'offline mode'; diff --git a/flutter/lib/ui/home/benchmark_running_screen.dart b/flutter/lib/ui/home/benchmark_running_screen.dart index 3a90bf901..4994622dd 100644 --- a/flutter/lib/ui/home/benchmark_running_screen.dart +++ b/flutter/lib/ui/home/benchmark_running_screen.dart @@ -4,6 +4,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:collection/collection.dart'; +import 'package:mlperfbench/ui/home/dotted_progress_circle.dart'; import 'package:provider/provider.dart'; import 'package:mlperfbench/benchmark/info.dart'; @@ -11,11 +12,8 @@ import 'package:mlperfbench/benchmark/run_mode.dart'; import 'package:mlperfbench/benchmark/state.dart'; import 'package:mlperfbench/localizations/app_localizations.dart'; import 'package:mlperfbench/state/task_runner.dart'; -import 'package:mlperfbench/store.dart'; import 'package:mlperfbench/ui/app_styles.dart'; import 'package:mlperfbench/ui/formatter.dart'; -import 'package:mlperfbench/ui/home/dotted_progress_circle.dart'; -import 'package:mlperfbench/ui/home/infinite_progress_circle.dart'; import 'package:mlperfbench/ui/icons.dart'; class BenchmarkRunningScreen extends StatefulWidget { @@ -32,13 +30,11 @@ class _BenchmarkRunningScreenState extends State { late BenchmarkState state; late AppLocalizations l10n; late ProgressInfo progress; - late Store store; @override Widget build(BuildContext context) { state = context.watch(); l10n = AppLocalizations.of(context); - store = context.watch(); progress = state.taskRunner.progressInfo; final backgroundGradient = BoxDecoration( @@ -94,20 +90,6 @@ class _BenchmarkRunningScreenState extends State { var containerWidth = 0.50 * MediaQuery.of(context).size.width; containerWidth = max(containerWidth, 160); containerWidth = min(containerWidth, 240); - Widget animation; - if (store.progressAnimationMode == 1) { - animation = DottedProgressCircle( - circleSize: containerWidth + 40, - dotSize: 10, - ); - } else if (store.progressAnimationMode == 2) { - animation = GradientProgressCircle( - size: containerWidth + 20, - strokeWidth: 6.0, - ); - } else { - animation = const SizedBox(height: 0); - } return Stack( alignment: AlignmentDirectional.center, children: [ @@ -132,7 +114,10 @@ class _BenchmarkRunningScreenState extends State { ), ), ), - animation, + DottedProgressCircle( + circleSize: containerWidth + 20, + dotSize: 10, + ), ], ); } @@ -216,19 +201,10 @@ class _BenchmarkRunningScreenState extends State { const trailingWidth = 24.0; Widget? doneIcon; if (progress.currentBenchmark?.taskName == benchmarkInfo.taskName) { - if (store.progressAnimationMode == 1) { - doneIcon = const DottedProgressCircle( - circleSize: trailingWidth, - dotSize: 2.0, - ); - } else if (store.progressAnimationMode == 2) { - doneIcon = const GradientProgressCircle( - size: trailingWidth, - strokeWidth: 2.0, - ); - } else { - doneIcon = const SizedBox(height: 0); - } + doneIcon = const DottedProgressCircle( + circleSize: trailingWidth + 20, + dotSize: 2, + ); } else if (progress.completedBenchmarks.contains(benchmarkInfo)) { doneIcon = const Icon( Icons.check_circle, diff --git a/flutter/lib/ui/home/infinite_progress_circle.dart b/flutter/lib/ui/home/progress_circles.dart similarity index 85% rename from flutter/lib/ui/home/infinite_progress_circle.dart rename to flutter/lib/ui/home/progress_circles.dart index fbcdc73db..b22a86d7b 100644 --- a/flutter/lib/ui/home/infinite_progress_circle.dart +++ b/flutter/lib/ui/home/progress_circles.dart @@ -2,19 +2,19 @@ import 'package:flutter/material.dart'; import 'package:mlperfbench/ui/home/gradient_circular_progress_indicator.dart'; -class GradientProgressCircle extends StatefulWidget { +class InfiniteProgressCircle extends StatefulWidget { final double size; final double strokeWidth; - const GradientProgressCircle( + const InfiniteProgressCircle( {Key? key, required this.size, required this.strokeWidth}) : super(key: key); @override - State createState() => _GradientProgressCircleState(); + State createState() => _InfiniteProgressCircleState(); } -class _GradientProgressCircleState extends State +class _InfiniteProgressCircleState extends State with SingleTickerProviderStateMixin { late AnimationController _controller; diff --git a/flutter/lib/ui/settings/settings_screen.dart b/flutter/lib/ui/settings/settings_screen.dart index 633c5b31b..48559e60f 100644 --- a/flutter/lib/ui/settings/settings_screen.dart +++ b/flutter/lib/ui/settings/settings_screen.dart @@ -34,7 +34,6 @@ class _SettingsScreen extends State { state = context.watch(); l10n = AppLocalizations.of(context); - Widget progressAnimationDropdown = _progressAnimationDropdown(); Widget artificialLoadSwitch = _artificialLoadSwitch(); Widget crashlyticsSwitch = _crashlyticsSwitch(); Widget runModeDropdown = _runModeDropdown(); @@ -52,7 +51,6 @@ class _SettingsScreen extends State { child: ListView( padding: const EdgeInsets.only(top: 20), children: [ - progressAnimationDropdown, runModeDropdown, offlineModeSwitch, keepLogSwitch, @@ -182,27 +180,6 @@ class _SettingsScreen extends State { ); } - Widget _progressAnimationDropdown() { - return ListTile( - title: const Padding( - padding: EdgeInsets.only(bottom: 5), - child: Text('Progress Animation'), - ), - subtitle: const Text('Progress animation during a benchmark run'), - trailing: DropdownButton( - borderRadius: BorderRadius.circular(WidgetSizes.borderRadius), - value: store.progressAnimationMode, - items: const [ - DropdownMenuItem(value: 0, child: Text('No animation')), - DropdownMenuItem(value: 1, child: Text('Dotted Circle')), - DropdownMenuItem(value: 2, child: Text('Gradient Circle')), - ], - onChanged: (value) => setState(() { - store.progressAnimationMode = value!; - })), - ); - } - Widget _runModeDropdown() { return ListTile( title: Padding( From 1f64e6e48c398c8f3ef018009cc647cf192ca2c9 Mon Sep 17 00:00:00 2001 From: Anh Date: Tue, 27 Feb 2024 15:37:07 +0700 Subject: [PATCH 7/9] Revert "Add DottedProgressCircle" This reverts commit ef1c42795fe563ee87d2146a1eb177840c144912. --- .../lib/ui/home/benchmark_running_screen.dart | 14 +-- .../lib/ui/home/dotted_progress_circle.dart | 103 ------------------ 2 files changed, 5 insertions(+), 112 deletions(-) delete mode 100644 flutter/lib/ui/home/dotted_progress_circle.dart diff --git a/flutter/lib/ui/home/benchmark_running_screen.dart b/flutter/lib/ui/home/benchmark_running_screen.dart index 4994622dd..b489952a3 100644 --- a/flutter/lib/ui/home/benchmark_running_screen.dart +++ b/flutter/lib/ui/home/benchmark_running_screen.dart @@ -4,7 +4,6 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:collection/collection.dart'; -import 'package:mlperfbench/ui/home/dotted_progress_circle.dart'; import 'package:provider/provider.dart'; import 'package:mlperfbench/benchmark/info.dart'; @@ -114,10 +113,10 @@ class _BenchmarkRunningScreenState extends State { ), ), ), - DottedProgressCircle( - circleSize: containerWidth + 20, - dotSize: 10, - ), + // InfiniteProgressCircle( + // size: containerWidth + 20, + // strokeWidth: 6.0, + // ), ], ); } @@ -201,10 +200,7 @@ class _BenchmarkRunningScreenState extends State { const trailingWidth = 24.0; Widget? doneIcon; if (progress.currentBenchmark?.taskName == benchmarkInfo.taskName) { - doneIcon = const DottedProgressCircle( - circleSize: trailingWidth + 20, - dotSize: 2, - ); + doneIcon = null; } else if (progress.completedBenchmarks.contains(benchmarkInfo)) { doneIcon = const Icon( Icons.check_circle, diff --git a/flutter/lib/ui/home/dotted_progress_circle.dart b/flutter/lib/ui/home/dotted_progress_circle.dart deleted file mode 100644 index 581f021c4..000000000 --- a/flutter/lib/ui/home/dotted_progress_circle.dart +++ /dev/null @@ -1,103 +0,0 @@ -import 'dart:async'; -import 'dart:math'; - -import 'package:flutter/material.dart'; - -class DottedProgressCircle extends StatefulWidget { - final double circleSize; - final double dotSize; - - const DottedProgressCircle( - {required this.circleSize, required this.dotSize, Key? key}) - : super(key: key); - - @override - State createState() => _DottedProgressCircleState(); -} - -class _DottedProgressCircleState extends State { - static const circlesCount = 10; - - late final Timer _timer; - - bool _increase = true; - int _startCircleNumber = 0; - int _endCircleNumber = 1; - - void _updateState() { - if (_increase) { - if (_startCircleNumber == circlesCount) { - _startCircleNumber = 0; - _endCircleNumber = 1; - } else { - _endCircleNumber++; - } - - if (_endCircleNumber == circlesCount) { - _increase = false; - } - } else { - _startCircleNumber++; - - if (_startCircleNumber == circlesCount) { - _increase = true; - } - } - } - - @override - void initState() { - _timer = Timer.periodic( - const Duration(seconds: 1), - (_) => setState(_updateState), - ); - super.initState(); - } - - @override - void dispose() { - _timer.cancel(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return CustomPaint( - size: Size(widget.circleSize, widget.circleSize), - painter: _ProgressCirclesPaint( - _startCircleNumber, - _endCircleNumber, - widget.dotSize, - )); - } -} - -class _ProgressCirclesPaint extends CustomPainter { - final int _startCircleNumber; - final int _endCircleNumber; - final double _circleRadius; - - _ProgressCirclesPaint( - this._startCircleNumber, this._endCircleNumber, this._circleRadius); - - final Paint _paintLine = Paint() - ..color = Colors.white - ..style = PaintingStyle.fill; - final double pi = 3.1415926535897932; - - @override - void paint(Canvas canvas, Size size) { - for (var i = _startCircleNumber; i < _endCircleNumber; i++) { - final currentDegree = - 2 * pi * ((i) / _DottedProgressCircleState.circlesCount) + pi / 2; - final x = (size.width + size.height * cos(currentDegree)) / 2; - final y = (size.height + size.width * sin(currentDegree)) / 2; - canvas.drawCircle(Offset(x, y), _circleRadius, _paintLine); - } - } // paint - - @override - bool shouldRepaint(_ProgressCirclesPaint old) => - old._endCircleNumber != _endCircleNumber || - old._startCircleNumber != _startCircleNumber; -} From 71255cf0e85309f2b018beb32c6139a42226e0d5 Mon Sep 17 00:00:00 2001 From: Anh Date: Tue, 27 Feb 2024 16:26:10 +0700 Subject: [PATCH 8/9] Use ProgressCircle with no animation --- .../lib/ui/home/benchmark_running_screen.dart | 16 ++- .../gradient_circular_progress_indicator.dart | 106 ------------------ flutter/lib/ui/home/progress_circle.dart | 63 +++++++++++ flutter/lib/ui/home/progress_circles.dart | 54 --------- 4 files changed, 73 insertions(+), 166 deletions(-) delete mode 100644 flutter/lib/ui/home/gradient_circular_progress_indicator.dart create mode 100644 flutter/lib/ui/home/progress_circle.dart delete mode 100644 flutter/lib/ui/home/progress_circles.dart diff --git a/flutter/lib/ui/home/benchmark_running_screen.dart b/flutter/lib/ui/home/benchmark_running_screen.dart index b489952a3..3113e918f 100644 --- a/flutter/lib/ui/home/benchmark_running_screen.dart +++ b/flutter/lib/ui/home/benchmark_running_screen.dart @@ -13,6 +13,7 @@ import 'package:mlperfbench/localizations/app_localizations.dart'; import 'package:mlperfbench/state/task_runner.dart'; import 'package:mlperfbench/ui/app_styles.dart'; import 'package:mlperfbench/ui/formatter.dart'; +import 'package:mlperfbench/ui/home/progress_circle.dart'; import 'package:mlperfbench/ui/icons.dart'; class BenchmarkRunningScreen extends StatefulWidget { @@ -113,10 +114,10 @@ class _BenchmarkRunningScreenState extends State { ), ), ), - // InfiniteProgressCircle( - // size: containerWidth + 20, - // strokeWidth: 6.0, - // ), + ProgressCircle( + strokeWidth: 6, + size: containerWidth + 20, + ), ], ); } @@ -200,7 +201,10 @@ class _BenchmarkRunningScreenState extends State { const trailingWidth = 24.0; Widget? doneIcon; if (progress.currentBenchmark?.taskName == benchmarkInfo.taskName) { - doneIcon = null; + doneIcon = const ProgressCircle( + strokeWidth: 2, + size: trailingWidth - 4, + ); } else if (progress.completedBenchmarks.contains(benchmarkInfo)) { doneIcon = const Icon( Icons.check_circle, @@ -234,7 +238,7 @@ class _BenchmarkRunningScreenState extends State { trailing: SizedBox( width: trailingWidth, height: trailingWidth, - child: doneIcon, + child: Center(child: doneIcon), ), ); } diff --git a/flutter/lib/ui/home/gradient_circular_progress_indicator.dart b/flutter/lib/ui/home/gradient_circular_progress_indicator.dart deleted file mode 100644 index 9fa879ce4..000000000 --- a/flutter/lib/ui/home/gradient_circular_progress_indicator.dart +++ /dev/null @@ -1,106 +0,0 @@ -// Source: https://github.com/mryadavdilip/gradient_circular_progress_indicator/blob/e3621c0744bd1b88b00ae4e6a6068c8197789ef6/lib/gradient_circular_progress_indicator.dart - -import 'dart:math'; - -import 'package:flutter/material.dart'; - -class GradientCircularProgressIndicator extends StatelessWidget { - /// progress value between or equal to 0 and 1 (0 <= progress <= 1) - final double progress; - final Gradient gradient; - - /// default background Colors.transparent - final Color? backgroundColor; - - /// default stroke is (size of child divided by 10) - final double? stroke; - - /// default size is size of child - final double? size; - final Widget? child; - - const GradientCircularProgressIndicator({ - super.key, - required this.progress, - required this.gradient, - this.backgroundColor, - this.stroke, - this.size, - this.child, - }); - - @override - Widget build(BuildContext context) { - return CustomPaint( - size: size != null ? Size(size!, size!) : MediaQuery.of(context).size, - painter: _GradientCircularProgressPainter( - progress: progress, - gradient: gradient, - backgroundColor: backgroundColor ?? Colors.transparent, - stroke: stroke), - child: SizedBox( - height: size, - width: size, - child: child, - ), - ); - } -} - -class _GradientCircularProgressPainter extends CustomPainter { - final double progress; - final Gradient gradient; - final Color backgroundColor; // New parameter for background color - final double? stroke; - - _GradientCircularProgressPainter({ - required this.progress, - required this.gradient, - required this.backgroundColor, - this.stroke, - }); - - @override - void paint(Canvas canvas, Size size) { - final center = Offset(size.width / 2, size.height / 2); - final radius = size.width / 2; - const startAngle = -pi / 2; - const fullSweepAngle = 2 * pi; - final progressSweepAngle = 2 * pi * progress; - - final backgroundPaint = Paint() - ..color = backgroundColor // Set the background color - ..style = PaintingStyle.stroke - ..strokeWidth = stroke ?? size.width / 10; - - final gradientPaint = Paint() - ..shader = - gradient.createShader(Rect.fromCircle(center: center, radius: radius)) - ..strokeCap = StrokeCap.round - ..style = PaintingStyle.stroke - ..strokeWidth = stroke ?? size.width / 10; - - // Draw the background arc - canvas.drawArc( - Rect.fromCircle(center: center, radius: radius), - startAngle + progressSweepAngle, - fullSweepAngle - progressSweepAngle, - false, - backgroundPaint, - ); - - // Draw the gradient arc - canvas.drawArc( - Rect.fromCircle(center: center, radius: radius), - startAngle, - progressSweepAngle, - false, - gradientPaint, - ); - } - - @override - bool shouldRepaint(covariant CustomPainter oldDelegate) { - return true; - } -} diff --git a/flutter/lib/ui/home/progress_circle.dart b/flutter/lib/ui/home/progress_circle.dart new file mode 100644 index 000000000..498413980 --- /dev/null +++ b/flutter/lib/ui/home/progress_circle.dart @@ -0,0 +1,63 @@ +import 'package:flutter/material.dart'; + +class ProgressCircle extends StatelessWidget { + final double strokeWidth; + final double size; + + const ProgressCircle({ + super.key, + required this.size, + required this.strokeWidth, + }); + + @override + Widget build(BuildContext context) { + return _BorderedCircle( + strokeWidth: strokeWidth, + radius: size / 2, + color: Colors.white.withOpacity(0.88), + ); + } +} + +class _BorderedCircle extends StatelessWidget { + final double strokeWidth; + final double radius; + final Color color; + + const _BorderedCircle({ + super.key, + required this.strokeWidth, + required this.radius, + required this.color, + }); + + @override + Widget build(BuildContext context) { + return CustomPaint( + painter: DrawCircle(strokeWidth, radius, color), + ); + } +} + +class DrawCircle extends CustomPainter { + final double strokeWidth; + final double radius; + final Color color; + + DrawCircle(this.strokeWidth, this.radius, this.color); + + @override + void paint(Canvas canvas, Size size) { + final paint = Paint() + ..color = color + ..strokeWidth = strokeWidth + ..style = PaintingStyle.stroke; + canvas.drawCircle(const Offset(0.0, 0.0), radius, paint); + } + + @override + bool shouldRepaint(CustomPainter oldDelegate) { + return false; + } +} diff --git a/flutter/lib/ui/home/progress_circles.dart b/flutter/lib/ui/home/progress_circles.dart deleted file mode 100644 index b22a86d7b..000000000 --- a/flutter/lib/ui/home/progress_circles.dart +++ /dev/null @@ -1,54 +0,0 @@ -import 'package:flutter/material.dart'; - -import 'package:mlperfbench/ui/home/gradient_circular_progress_indicator.dart'; - -class InfiniteProgressCircle extends StatefulWidget { - final double size; - final double strokeWidth; - - const InfiniteProgressCircle( - {Key? key, required this.size, required this.strokeWidth}) - : super(key: key); - - @override - State createState() => _InfiniteProgressCircleState(); -} - -class _InfiniteProgressCircleState extends State - with SingleTickerProviderStateMixin { - late AnimationController _controller; - - @override - void initState() { - _controller = - AnimationController(vsync: this, duration: const Duration(seconds: 2)); - _controller.addListener(() => setState(() {})); - _controller.repeat(); - super.initState(); - } - - @override - void dispose() { - _controller.dispose(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return RotationTransition( - turns: Tween(begin: 0.0, end: 1.0).animate(_controller), - child: GradientCircularProgressIndicator( - progress: 1.0, - // Specify the progress value between 0 and 1 - gradient: const LinearGradient( - colors: [Colors.white, Colors.white, Colors.white10, Colors.white10], - begin: Alignment.topLeft, - end: Alignment.bottomRight, - ), - backgroundColor: Colors.transparent, - stroke: widget.strokeWidth, - size: widget.size, - ), - ); - } -} From 4415c863b1d67ec5e7cf3818d80f98f85301c731 Mon Sep 17 00:00:00 2001 From: Anh Date: Tue, 27 Feb 2024 16:34:31 +0700 Subject: [PATCH 9/9] Format Dart code --- flutter/lib/ui/home/progress_circle.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/flutter/lib/ui/home/progress_circle.dart b/flutter/lib/ui/home/progress_circle.dart index 498413980..1762bada0 100644 --- a/flutter/lib/ui/home/progress_circle.dart +++ b/flutter/lib/ui/home/progress_circle.dart @@ -26,7 +26,6 @@ class _BorderedCircle extends StatelessWidget { final Color color; const _BorderedCircle({ - super.key, required this.strokeWidth, required this.radius, required this.color,