Skip to content

Commit 8c10943

Browse files
committed
Toast: close button, action color and corner radius
ShowToastAction gains showCloseButton, actionColor and cornerRadius, all left out of the JSON at their defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012anUJ6o6K6kjUXur8Ak8XX
1 parent 6151ff0 commit 8c10943

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎lib/src/api/models/action/show_toast_action.dart‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ class ShowToastAction extends ActionModel with Equatable, SerializableMixin {
9191
/// [ToastPosition.bottom].
9292
final double bottomOffset;
9393

94+
/// Whether the toast shows a close (×) button that dismisses it.
95+
final bool showCloseButton;
96+
97+
/// Color of the button's label. Null takes the message color.
98+
final ColorRGBA? actionColor;
99+
100+
/// Corner radius. Null is a pill without a button, the theme's button
101+
/// radius with one.
102+
final double? cornerRadius;
103+
94104
/// Creates a new [ShowToastAction].
95105
ShowToastAction({
96106
required this.message,
@@ -103,6 +113,9 @@ class ShowToastAction extends ActionModel with Equatable, SerializableMixin {
103113
List<ActionModel>? actions,
104114
this.icon,
105115
this.bottomOffset = 104,
116+
this.showCloseButton = false,
117+
this.actionColor,
118+
this.cornerRadius,
106119
super.nonBlocking,
107120
super.enabled,
108121
}) : actions = actions ?? [],
@@ -123,6 +136,9 @@ class ShowToastAction extends ActionModel with Equatable, SerializableMixin {
123136
actions,
124137
icon,
125138
bottomOffset,
139+
showCloseButton,
140+
actionColor,
141+
cornerRadius,
126142
];
127143

128144
/// Duplicates this [ShowToastAction] with given data overrides.
@@ -140,6 +156,11 @@ class ShowToastAction extends ActionModel with Equatable, SerializableMixin {
140156
MultiSourceIconModel? icon,
141157
bool clearIcon = false,
142158
double? bottomOffset,
159+
bool? showCloseButton,
160+
ColorRGBA? actionColor,
161+
bool clearActionColor = false,
162+
double? cornerRadius,
163+
bool clearCornerRadius = false,
143164
}) => ShowToastAction(
144165
message: message ?? this.message,
145166
duration: duration ?? this.duration,
@@ -153,6 +174,9 @@ class ShowToastAction extends ActionModel with Equatable, SerializableMixin {
153174
actions: actions ?? this.actions,
154175
icon: clearIcon ? null : icon ?? this.icon,
155176
bottomOffset: bottomOffset ?? this.bottomOffset,
177+
showCloseButton: showCloseButton ?? this.showCloseButton,
178+
actionColor: clearActionColor ? null : actionColor ?? this.actionColor,
179+
cornerRadius: clearCornerRadius ? null : cornerRadius ?? this.cornerRadius,
156180
nonBlocking: nonBlocking,
157181
enabled: enabled,
158182
);

‎lib/src/api/models/action/show_toast_action.g.dart‎

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/show_toast_action_test.dart‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,28 @@ void main() {
7575

7676
expect(toast.copyWith(clearBackgroundColor: true).backgroundColor, isNull);
7777
});
78+
79+
test('close button, action color and corner radius round-trip', () {
80+
final ShowToastAction plain = ShowToastAction(message: 'Saved');
81+
final Map plainJson = plain.toJson();
82+
expect(plainJson.containsKey('showCloseButton'), isFalse);
83+
expect(plainJson.containsKey('actionColor'), isFalse);
84+
expect(plainJson.containsKey('cornerRadius'), isFalse);
85+
86+
final ShowToastAction toast = ShowToastAction(
87+
message: '#025 deleted',
88+
actionLabel: 'Undo',
89+
showCloseButton: true,
90+
actionColor: ColorRGBA.fromHex('#FF6A13'),
91+
cornerRadius: 10,
92+
);
93+
final Map json = toast.toJson();
94+
expect(json['showCloseButton'], isTrue);
95+
expect(json['cornerRadius'], 10);
96+
final ShowToastAction decoded =
97+
ActionModel.fromJson(json) as ShowToastAction;
98+
expect(decoded, toast);
99+
expect(decoded.actionColor, ColorRGBA.fromHex('#FF6A13'));
100+
expect(decoded.copyWith(clearCornerRadius: true).cornerRadius, isNull);
101+
});
78102
}

0 commit comments

Comments
 (0)