From 7c9492c539373d52993b727d9a29f263e9ca3d45 Mon Sep 17 00:00:00 2001 From: Manoj Date: Sat, 25 Feb 2023 00:12:20 +0530 Subject: [PATCH 1/4] fixed the updating of start_stop_button widget based on the process_tile widget --- .../dashboard/components/process_tile.dart | 53 +++++++++++++++---- .../components/start_stop_button.dart | 22 ++++++-- 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/lib/screens/dashboard/components/process_tile.dart b/lib/screens/dashboard/components/process_tile.dart index 1b61c69..11dcc8b 100644 --- a/lib/screens/dashboard/components/process_tile.dart +++ b/lib/screens/dashboard/components/process_tile.dart @@ -1,3 +1,4 @@ +import 'package:ccxgui/screens/dashboard/components/start_stop_button.dart'; import 'package:flutter/material.dart'; import 'package:file_selector/file_selector.dart'; @@ -5,6 +6,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:ccxgui/bloc/dashboard_bloc/dashboard_bloc.dart'; import 'package:ccxgui/bloc/process_bloc/process_bloc.dart'; +import 'package:ccxgui/screens/dashboard/components/start_stop_button.dart'; class ProcessTile extends StatefulWidget { final XFile file; @@ -80,17 +82,46 @@ class _ProcessTileState extends State { ), IconButton( onPressed: () { - context.read().add( - FileRemoved(widget.file), - ); - try { - context.read().add( - ProcessKill(widget.file), - ); - } catch (e) { - print( - 'processing for this file never started'); - } + showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text('Warning'), + content: Text( + 'Are you sure you want to remove the selected\nfiles and cancel any files that is running?', + ), + actions: [ + TextButton( + onPressed: () => + Navigator.pop(context), + child: Text('No'), + ), + TextButton( + onPressed: () { + StartStopButton(); + context + .read() + .add( + FileRemoved(widget.file), + ); + try { + context + .read() + .add( + ProcessKill( + widget.file), + ); + } catch (e) { + print( + 'processing for this file never started'); + } + Navigator.pop(context); + }, + child: Text('Yes'), + ), + ], + )); + print("process_tile"); + print(state.progress); }, icon: Icon( Icons.delete_outline, diff --git a/lib/screens/dashboard/components/start_stop_button.dart b/lib/screens/dashboard/components/start_stop_button.dart index edc9d9a..a219b2b 100644 --- a/lib/screens/dashboard/components/start_stop_button.dart +++ b/lib/screens/dashboard/components/start_stop_button.dart @@ -8,7 +8,12 @@ import 'package:ccxgui/bloc/settings_bloc/settings_bloc.dart'; import 'package:ccxgui/screens/dashboard/components/custom_snackbar.dart'; //TODO: this file can probably be improved -class StartStopButton extends StatelessWidget { +class StartStopButton extends StatefulWidget { + @override + State createState() => _StartStopButtonState(); +} + +class _StartStopButtonState extends State { @override Widget build(BuildContext context) { return BlocBuilder( @@ -18,8 +23,15 @@ class StartStopButton extends StatelessWidget { return BlocBuilder( builder: (context, settingsState) { if (settingsState is CurrentSettingsState) { + if (dashboardState.files.isEmpty && processState.started) { + context.read().add( + StopAllProcess(), + ); + } return MaterialButton( onPressed: () { + print("start_stop"); + print(processState); dashboardState.files.isEmpty ? null : processState.started @@ -52,7 +64,10 @@ class StartStopButton extends StatelessWidget { child: Row( children: [ Text( - processState.started ? 'Stop all' : 'Start all', + dashboardState.files.isNotEmpty && + processState.started + ? 'Stop all' + : 'Start all', style: TextStyle( fontSize: 20, ), @@ -60,7 +75,8 @@ class StartStopButton extends StatelessWidget { SizedBox( width: 5, ), - processState.started + dashboardState.files.isNotEmpty && + processState.started ? Icon(Icons.stop, color: Colors.redAccent, size: 30) : Icon( From dd48e79d83a559b6a0b67d43a6281b9842cb0b2a Mon Sep 17 00:00:00 2001 From: Manoj Date: Sat, 25 Feb 2023 00:15:05 +0530 Subject: [PATCH 2/4] fixed typo --- lib/screens/dashboard/components/process_tile.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/screens/dashboard/components/process_tile.dart b/lib/screens/dashboard/components/process_tile.dart index 11dcc8b..7c28ee2 100644 --- a/lib/screens/dashboard/components/process_tile.dart +++ b/lib/screens/dashboard/components/process_tile.dart @@ -87,7 +87,7 @@ class _ProcessTileState extends State { builder: (context) => AlertDialog( title: Text('Warning'), content: Text( - 'Are you sure you want to remove the selected\nfiles and cancel any files that is running?', + 'Are you sure you want to remove the selected\nfile and cancel any files that is running?', ), actions: [ TextButton( From b05591b5f2126e70fee6e97e599a456e21536b80 Mon Sep 17 00:00:00 2001 From: Manoj Date: Sat, 25 Feb 2023 00:24:39 +0530 Subject: [PATCH 3/4] sorted imports --- lib/screens/dashboard/components/process_tile.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/screens/dashboard/components/process_tile.dart b/lib/screens/dashboard/components/process_tile.dart index 7c28ee2..998cb00 100644 --- a/lib/screens/dashboard/components/process_tile.dart +++ b/lib/screens/dashboard/components/process_tile.dart @@ -1,4 +1,3 @@ -import 'package:ccxgui/screens/dashboard/components/start_stop_button.dart'; import 'package:flutter/material.dart'; import 'package:file_selector/file_selector.dart'; From 775e82e7f82d740147719de2384bdec2ebc37e14 Mon Sep 17 00:00:00 2001 From: Manoj Date: Sat, 25 Feb 2023 00:27:53 +0530 Subject: [PATCH 4/4] removed unwanted print statements --- lib/screens/dashboard/components/process_tile.dart | 2 -- lib/screens/dashboard/components/start_stop_button.dart | 2 -- 2 files changed, 4 deletions(-) diff --git a/lib/screens/dashboard/components/process_tile.dart b/lib/screens/dashboard/components/process_tile.dart index 998cb00..ee0bec0 100644 --- a/lib/screens/dashboard/components/process_tile.dart +++ b/lib/screens/dashboard/components/process_tile.dart @@ -119,8 +119,6 @@ class _ProcessTileState extends State { ), ], )); - print("process_tile"); - print(state.progress); }, icon: Icon( Icons.delete_outline, diff --git a/lib/screens/dashboard/components/start_stop_button.dart b/lib/screens/dashboard/components/start_stop_button.dart index a219b2b..c63b90f 100644 --- a/lib/screens/dashboard/components/start_stop_button.dart +++ b/lib/screens/dashboard/components/start_stop_button.dart @@ -30,8 +30,6 @@ class _StartStopButtonState extends State { } return MaterialButton( onPressed: () { - print("start_stop"); - print(processState); dashboardState.files.isEmpty ? null : processState.started