cpd_2022_zi/lib/widgets/timepicker.dart

50 lines
1.4 KiB
Dart
Raw Normal View History

2023-02-17 11:35:05 +01:00
import 'package:flutter/material.dart';
class TimePicker extends StatefulWidget {
2023-02-20 23:23:37 +01:00
TimeOfDay _initialTime;
2023-02-20 23:59:40 +01:00
TimePicker(this._initialTime, {Key? key});
2023-02-20 23:23:37 +01:00
TimeOfDay get getCurrentTime => _initialTime;
2023-02-17 11:35:05 +01:00
@override
2023-02-20 23:23:37 +01:00
State<StatefulWidget> createState() => TimePickerState();
2023-02-17 11:35:05 +01:00
}
2023-02-21 00:14:31 +01:00
2023-02-20 23:23:37 +01:00
class TimePickerState extends State<TimePicker> {
TimePickerState();
2023-02-17 11:35:05 +01:00
@override
Widget build(BuildContext context) {
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-20 23:59:40 +01:00
'${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}',
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 {
//TODO auslagern
TimeOfDay? newTime = await showTimePicker(
context: context,
initialTime: widget._initialTime,
builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context)
.copyWith(alwaysUse24HourFormat: true),
child: child!,
);
},
);
if (newTime == null) return;
setState(() {
widget._initialTime = newTime;
});
},
child: const Text('Zeit einstellen'))
2023-02-17 11:35:05 +01:00
]),
);
}
}