diff --git a/lib/screens/dashboard/components/process_tile.dart b/lib/screens/dashboard/components/process_tile.dart index 1b61c69..ee0bec0 100644 --- a/lib/screens/dashboard/components/process_tile.dart +++ b/lib/screens/dashboard/components/process_tile.dart @@ -5,6 +5,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 +81,44 @@ 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\nfile 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'), + ), + ], + )); }, 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..c63b90f 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,6 +23,11 @@ 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: () { dashboardState.files.isEmpty @@ -52,7 +62,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 +73,8 @@ class StartStopButton extends StatelessWidget { SizedBox( width: 5, ), - processState.started + dashboardState.files.isNotEmpty && + processState.started ? Icon(Icons.stop, color: Colors.redAccent, size: 30) : Icon(