Skip to content

Commit

Permalink
fix(colorPicker): dialog cancel button to restore previous color (#1300)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeshuaro authored Jul 22, 2024
1 parent f5c2164 commit d2a4bbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/services/widget_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'package:flex_color_picker/flex_color_picker.dart';
import 'package:flutter/material.dart';

class WidgetService {
static Future<void> showColorPicker({
static Future<bool> showColorPicker({
required BuildContext context,
required Color color,
required ValueChanged<Color> onColorChanged,
bool enableOpacity = true,
}) async {
ColorPicker(
return ColorPicker(
key: const Key('widgetService_showColorPicker'),
color: color,
borderRadius: 4,
Expand Down
21 changes: 14 additions & 7 deletions lib/widgets/list_tiles/color_list_tile.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:appainter/services/services.dart';
import 'package:flex_color_picker/flex_color_picker.dart';
import 'package:flutter/material.dart';
import 'package:appainter/services/services.dart';

import 'list_tile.dart';

Expand Down Expand Up @@ -32,12 +32,19 @@ class ColorListTile extends StatelessWidget {
borderRadius: 4,
color: color,
onSelectFocus: false,
onSelect: () => WidgetService.showColorPicker(
context: context,
color: color,
onColorChanged: onColorChanged,
enableOpacity: enableOpacity,
),
onSelect: () async {
final prevColor = color;
final colorChanged = await WidgetService.showColorPicker(
context: context,
color: color,
onColorChanged: onColorChanged,
enableOpacity: enableOpacity,
);

if (!colorChanged) {
onColorChanged(prevColor);
}
},
),
);
}
Expand Down

0 comments on commit d2a4bbf

Please sign in to comment.