import 'package:flutter/material.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/res/dimens.dart'; class DialogPicker extends StatefulWidget { final String title; final T selectedValue; final List values; final String Function(BuildContext context, T value) titleAdapter; const DialogPicker({ required this.title, required this.selectedValue, required this.values, required this.titleAdapter, super.key, }); @override State> createState() => _DialogPickerState(); } class _DialogPickerState extends State> { late T _selected = widget.selectedValue; @override Widget build(BuildContext context) { return AlertDialog( titlePadding: const EdgeInsets.fromLTRB( Dimens.paddingL, Dimens.paddingL, Dimens.paddingL, Dimens.paddingM, ), title: Text(widget.title), contentPadding: EdgeInsets.zero, content: Column( mainAxisSize: MainAxisSize.min, children: widget.values .map( (e) => RadioListTile( value: e, groupValue: _selected, title: Text(widget.titleAdapter(context, e)), onChanged: (T? value) { if (value != null) { setState(() { _selected = value; }); } }, ), ) .toList(), ), actionsPadding: const EdgeInsets.fromLTRB( Dimens.paddingL, Dimens.paddingM, Dimens.paddingL, Dimens.paddingL, ), actions: [ TextButton( onPressed: Navigator.of(context).pop, child: Text(S.of(context).cancel), ), TextButton( onPressed: () => Navigator.of(context).pop(_selected), child: Text(S.of(context).select), ), ], ); } }