cpd_2022_zi/lib/widgets/timepicker.dart

42 lines
1.4 KiB
Dart
Raw Normal View History

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