cpd_2022_zi/lib/widgets/timepicker.dart

42 lines
1.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:smoke_cess_app/providers/input_provider.dart';
import 'package:provider/provider.dart';
class TimePicker extends StatelessWidget {
final SleepTimes keyMap;
const TimePicker(this.keyMap, {super.key});
@override
Widget build(BuildContext context) {
InputProvider inputModel = context.watch<InputProvider>();
return Center(
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
'${inputModel.getTimeEntry(keyMap).hour.toString().padLeft(2, '0')}:${inputModel.getTimeEntry(keyMap).minute.toString().padLeft(2, '0')}',
style: const TextStyle(fontSize: 22),
),
const SizedBox(width: 16),
ElevatedButton(
onPressed: () async {
TimeOfDay? newTime = await showTimePicker(
context: context,
initialTime: inputModel.getTimeEntry(keyMap),
builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context)
.copyWith(alwaysUse24HourFormat: true),
child: child!,
);
},
);
if (newTime == null) return;
inputModel.setTime(keyMap, newTime);
},
child: const Text('Zeit einstellen'))
]),
);
}
}