Skip to content

Fixed updating of start stop button based on the actions on files in process tile #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 39 additions & 11 deletions lib/screens/dashboard/components/process_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,17 +81,44 @@ class _ProcessTileState extends State<ProcessTile> {
),
IconButton(
onPressed: () {
context.read<DashboardBloc>().add(
FileRemoved(widget.file),
);
try {
context.read<ProcessBloc>().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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for rebuilding the StartStopButton widget

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should work if DashboardState or ProcessState change tho

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on what you are trying to say, I am not able to get you

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StartStopButton rebuilds on DashboardBloc and ProcessBloc updates. https://github.com/CCExtractor/ccextractorfluttergui/pull/48/files#diff-1bd4c76f5c4b0d8d3bd1f7757702ba2711e87599cdbd057b4ecc901013279726R19.

Also unsure how calling StartStopButton() rebuilds the original button 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had checked it is not working without StartStopButton();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any changes needed to be done👀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I need to test this myself, not really free atm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating any of the following should rebuild it automatically (unless there's some error in the login in StartStopButton.

  • ProcessState
  • DashboardState
  • SettingsState

context
.read<DashboardBloc>()
.add(
FileRemoved(widget.file),
);
try {
context
.read<ProcessBloc>()
.add(
ProcessKill(
widget.file),
);
} catch (e) {
print(
'processing for this file never started');
}
Navigator.pop(context);
},
child: Text('Yes'),
),
],
));
},
icon: Icon(
Icons.delete_outline,
Expand Down
20 changes: 17 additions & 3 deletions lib/screens/dashboard/components/start_stop_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<StartStopButton> createState() => _StartStopButtonState();
}

class _StartStopButtonState extends State<StartStopButton> {
@override
Widget build(BuildContext context) {
return BlocBuilder<ProcessBloc, ProcessState>(
Expand All @@ -18,6 +23,11 @@ class StartStopButton extends StatelessWidget {
return BlocBuilder<SettingsBloc, SettingsState>(
builder: (context, settingsState) {
if (settingsState is CurrentSettingsState) {
if (dashboardState.files.isEmpty && processState.started) {
context.read<ProcessBloc>().add(
StopAllProcess(),
);
}
return MaterialButton(
onPressed: () {
dashboardState.files.isEmpty
Expand Down Expand Up @@ -52,15 +62,19 @@ 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,
),
),
SizedBox(
width: 5,
),
processState.started
dashboardState.files.isNotEmpty &&
processState.started
? Icon(Icons.stop,
color: Colors.redAccent, size: 30)
: Icon(
Expand Down