showLumenTimePicker function
Future<TimeOfDay?>
showLumenTimePicker({
- required BuildContext context,
- required TimeOfDay initialTime,
- Color? accentColor,
- String? helpText,
- bool? use24HourFormat,
- TimePickerEntryMode initialEntryMode = TimePickerEntryMode.dial,
Opens the Material time picker with Lumen colors and corner radii.
The palette and radii come from context. The picker uses the Material
theme and media settings resolved inside the route as its base.
initialTime and initialEntryMode set the starting time and input mode.
accentColor overrides the primary palette color and helpText is
forwarded to showTimePicker. Returns the selected time or null on
dismissal.
use24HourFormat forces 24-hour formatting when true and uses the
locale's format when false. A null value preserves the inherited setting.
Implementation
Future<TimeOfDay?> showLumenTimePicker({
required BuildContext context,
required TimeOfDay initialTime,
Color? accentColor,
String? helpText,
bool? use24HourFormat,
TimePickerEntryMode initialEntryMode = TimePickerEntryMode.dial,
}) {
final p = LumenThemeExt.of(context).palette;
final s = LumenStyle.of(context);
final accent = accentColor ?? p.primary;
return showTimePicker(
context: context,
initialTime: initialTime,
helpText: helpText,
initialEntryMode: initialEntryMode,
builder: (ctx, child) {
final base = Theme.of(ctx);
Widget picker = Theme(
data: base.copyWith(
colorScheme: base.colorScheme.copyWith(
primary: accent,
onPrimary: p.textPrimary,
surface: p.surface,
onSurface: p.textPrimary,
onSurfaceVariant: p.textSecondary,
primaryContainer: accent.withValues(alpha: 0.22),
onPrimaryContainer: accent,
tertiaryContainer: accent.withValues(alpha: 0.22),
onTertiaryContainer: accent,
surfaceContainerHighest: p.backgroundSoft,
outline: p.surfaceOutline,
),
timePickerTheme: TimePickerThemeData(
backgroundColor: p.backgroundMid,
dialBackgroundColor: p.surface,
dialHandColor: accent,
entryModeIconColor: accent,
shape: RoundedRectangleBorder(borderRadius: s.radius(24)),
hourMinuteShape: RoundedRectangleBorder(borderRadius: s.radius(12)),
dayPeriodShape: RoundedRectangleBorder(borderRadius: s.radius(10)),
dayPeriodBorderSide: BorderSide(color: accent.withValues(alpha: 0.45)),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(foregroundColor: accent),
),
),
child: child ?? const SizedBox.shrink(),
);
if (use24HourFormat != null) {
picker = MediaQuery(
data: MediaQuery.of(ctx).copyWith(alwaysUse24HourFormat: use24HourFormat),
child: picker,
);
}
return picker;
},
);
}