Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from lunofono/button-image
Browse files Browse the repository at this point in the history
Add image to buttons
  • Loading branch information
llucax authored Feb 16, 2021
2 parents 446d0dc + ac582b3 commit 521720f
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 201 deletions.
4 changes: 2 additions & 2 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final bundle = Bundle(
rows: 1,
columns: 1,
buttons: [
ColoredButton(
StyledButton(
PlayContentAction(
MultiMedium(
AudibleMultiMediumTrack(
Expand All @@ -26,7 +26,7 @@ final bundle = Bundle(
),
),
),
Colors.amber,
backgroundColor: Colors.amber,
),
],
),
Expand Down
49 changes: 32 additions & 17 deletions lib/src/bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,43 @@ abstract class Button {
const Button(this.action) : assert(action != null);
}

/// A [Button] represented by a [Color].
class ColoredButton extends Button with EquatableMixin {
/// Button's color.
final Color color;

/// Creates a button represented by a [color].
const ColoredButton(Action action, this.color)
: assert(color != null),
super(action);
/// A [Button] with a customizable style.
class StyledButton extends Button with EquatableMixin {
/// Color to display as this button's background.
///
/// If null, the player can automatically choose one or a global default might
/// be used.
final Color backgroundColor;

/// The image to display in this button foreground.
///
/// If null, no foreground image is displayed.
final Uri foregroundImage;

/// Creates a button represented by a [backgroundColor].
const StyledButton(Action action,
{this.backgroundColor, this.foregroundImage})
: super(action);
@override
List<Object> get props => [action, color];
List<Object> get props => [action, backgroundColor];

/// Creates a new [ColoredButton] based on this one, overriding some values.
/// Creates a new [StyledButton] based on this one, overriding some values.
///
/// Values not specified as arguments will be copied from this
/// [ColoredButton].
ColoredButton copyWith({
/// [StyledButton].
///
/// Note that this won't work to make a copy with some values set to null. If
/// you need to do that you'll have to do the copy manually by calling the
/// constructor explicitly.
StyledButton copyWith({
Action action,
Color color,
Color backgroundColor,
Uri foregroundImage,
}) {
return ColoredButton(
return StyledButton(
action ?? this.action,
color ?? this.color,
backgroundColor: backgroundColor ?? this.backgroundColor,
foregroundImage: foregroundImage ?? this.foregroundImage,
);
}

Expand All @@ -208,7 +222,8 @@ class ColoredButton extends Button with EquatableMixin {
String toString() {
return '$runtimeType('
'action: $action, '
'color: $color'
'backgroundColor: $backgroundColor, '
'foregroundImage: $foregroundImage'
')';
}
}
Expand Down
Loading

0 comments on commit 521720f

Please sign in to comment.