Skip to content

Commit

Permalink
tabs/bmm: use sailbuttons for start and stop
Browse files Browse the repository at this point in the history
  • Loading branch information
octobocto authored and torkelrogstad committed Nov 2, 2023
1 parent 5eac023 commit 6346401
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
11 changes: 7 additions & 4 deletions lib/pages/tabs/bmm_tab_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_it/get_it.dart';
import 'package:sail_ui/sail_ui.dart';
import 'package:sail_ui/widgets/core/sail_snackbar.dart';
import 'package:sail_ui/widgets/core/sail_text.dart';
import 'package:sidesail/logger.dart';
import 'package:sidesail/rpc/rpc.dart';
Expand Down Expand Up @@ -56,16 +57,18 @@ class BlindMergedMiningTabPage extends StatelessWidget {
children: [
SailText.mediumPrimary20('BMM loop'),
const SizedBox(width: 10),
ElevatedButton.icon(
SailButton.icon(
onPressed: viewModel.running ? null : viewModel.toggleRunning,
disabled: viewModel.running,
icon: const Icon(Icons.play_arrow),
label: SailText.primary12('Start'),
label: 'Start',
),
const SizedBox(width: 10),
ElevatedButton.icon(
SailButton.icon(
onPressed: !viewModel.running ? null : viewModel.toggleRunning,
disabled: !viewModel.running,
icon: const Icon(Icons.stop),
label: SailText.primary12('Stop'),
label: 'Stop',
),
],
),
Expand Down
34 changes: 30 additions & 4 deletions packages/sail_ui/lib/widgets/buttons/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:sail_ui/widgets/loading_indicator.dart';
enum ButtonSize { small, regular, large }

class SailButton extends StatelessWidget {
final VoidCallback onPressed;
final VoidCallback? onPressed;
final bool disabled;
final bool loading;
final ButtonSize size;
Expand Down Expand Up @@ -40,6 +40,31 @@ class SailButton extends StatelessWidget {
);
}

static Widget icon({
required String label,
required Widget icon,
required VoidCallback? onPressed,
ButtonSize size = ButtonSize.regular,
bool loading = false,
bool disabled = false,
}) {
return SailButton._(
onPressed: onPressed,
disabled: disabled,
loading: loading,
size: size,
child: SailRow(
spacing: SailStyleValues.padding8,
children: [
icon,
size == ButtonSize.small || size == ButtonSize.regular
? SailText.mediumPrimary12(label)
: SailText.primary14(label),
],
),
);
}

@override
Widget build(BuildContext context) {
final colors = SailTheme.of(context).colors;
Expand Down Expand Up @@ -121,7 +146,7 @@ class SailRawButton extends StatefulWidget {
final bool loading;
final Color disabledColor;
final Color backgroundColor;
final VoidCallback onPressed;
final VoidCallback? onPressed;
final Widget child;
final EdgeInsets? padding;

Expand All @@ -144,12 +169,13 @@ class _SailRawButtonState extends State<SailRawButton> with SingleTickerProvider
@override
Widget build(BuildContext context) {
final theme = SailTheme.of(context);
final disabled = widget.disabled || widget.onPressed == null;

return Opacity(
opacity: widget.disabled ? 0.6 : 1,
opacity: disabled ? 0.6 : 1,
child: SailScaleButton(
onPressed: widget.onPressed,
disabled: widget.disabled,
disabled: disabled,
child: MaterialButton(
color: widget.backgroundColor,
disabledColor: widget.backgroundColor,
Expand Down

0 comments on commit 6346401

Please sign in to comment.