Commit 7cfbad1
Changed files (2)
lib
components
screens
lib/components/color_picker.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:flutter/material.dart';
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class ColorPicker extends StatefulWidget {
const ColorPicker({super.key,
@@ -134,4 +135,30 @@ class _ColorPickerState extends State<ColorPicker> {
],
);
}
+}
+
+/// Shows a dialog with a ColorPicker and with an cancel button inside.
+///
+/// Returns the selected color or null when cancel is pressed.
+Future<Color?> showColorPickerDialog(BuildContext context, Color? initialColor) async {
+ return await showDialog(
+ context: context,
+ builder: (_) {
+ return AlertDialog(
+ contentPadding: const EdgeInsets.all(6.0),
+ content: ColorPicker(
+ initialColor: initialColor,
+ onColorSelected: (color) {
+ Navigator.of(context).pop(color);
+ }
+ ),
+ actions: [
+ TextButton(
+ onPressed: Navigator.of(context).pop,
+ child: Text(AppLocalizations.of(context)!.btnCancel),
+ ),
+ ],
+ );
+ },
+ );
}
\ No newline at end of file
lib/screens/add_measurement.dart
@@ -207,33 +207,7 @@ class _AddMeasurementPageState extends State<AddMeasurementPage> {
side: (_needlePin != null) ? BorderSide(color: _needlePin!.color) : null
),
onPressed: () async {
- final color = await showDialog(
- context: context,
- builder: (_) {
- return AlertDialog(
- contentPadding: const EdgeInsets.all(6.0),
- content: /* TODO
- MaterialColorPicker(
- circleSize: 53,
- onMainColorChange: (color) {
- Navigator.of(context).pop(color);
- },
- )*/
- ColorPicker(
- initialColor: _needlePin?.color,
- onColorSelected: (color) {
- Navigator.of(context).pop(color);
- }
- ),
- actions: [
- TextButton(
- onPressed: Navigator.of(context).pop,
- child: Text(localizations.btnCancel),
- ),
- ],
- );
- },
- );
+ final color = await showColorPickerDialog(context, _needlePin?.color);
setState(() {
if (color != null) {
_needlePin = (color == Colors.transparent) ? null : MeasurementNeedlePin(color);