showColorPickerDialog function

void showColorPickerDialog(
  1. BuildContext context, {
  2. required String title,
  3. required Color selectedColor,
  4. required void onColorChanged(
    1. Color color
    ),
})

Implementation

void showColorPickerDialog(
  BuildContext context, {
  required String title,
  required Color selectedColor,
  required void Function(Color color) onColorChanged,
}) async {
  final l10n = context.l10n;

  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        titlePadding: const EdgeInsets.only(
          left: 8.0,
          right: 8.0,
          top: 12.0,
        ),
        title: Center(
          child: Text(title),
        ),
        contentPadding: const EdgeInsets.only(
          left: 8.0,
          right: 8.0,
          bottom: 0.0,
        ),
        content: SingleChildScrollView(
          child: Column(
            children: [
              const Divider(),
              Padding(
                padding: const EdgeInsets.only(
                  left: 8.0,
                  right: 8.0,
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: splitTextToFitWidth(
                    l10n.colorPickerPrompt,
                    maxWidth: 250,
                    style: Theme.of(context).textTheme.bodyMedium,
                  ),
                ),
              ),
              const Divider(),
              Padding(
                padding: const EdgeInsets.only(left: 8.0),
                child: MaterialPicker(
                  pickerColor: selectedColor,
                  onColorChanged: onColorChanged,
                  enableLabel: false,
                  portraitOnly: true,
                ),
              ),
              const Divider(),
            ],
          ),
        ),
        actionsPadding: const EdgeInsets.only(
          left: 8.0,
          right: 8.0,
          bottom: 8.0,
        ),
        actionsAlignment: MainAxisAlignment.center,
        actions: <Widget>[
          TextButton(
            onPressed: () => Navigator.pop(context, 'OK'),
            child: const Text('OK'),
          ),
        ],
      );
    },
  );
}