59 lines
1.8 KiB
Dart
59 lines
1.8 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
|
||
|
class TimePicker extends StatefulWidget {
|
||
|
final TimeOfDay _initialTime;
|
||
|
const TimePicker(this._initialTime, {super.key});
|
||
|
|
||
|
@override
|
||
|
State<StatefulWidget> createState() => _TimePickerState();
|
||
|
}
|
||
|
|
||
|
class _TimePickerState extends State<TimePicker> {
|
||
|
TimeOfDay time = const TimeOfDay(hour: 12, minute: 0);
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
time = widget._initialTime;
|
||
|
final hours = time.hour.toString().padLeft(2, '0');
|
||
|
final minutes = time.minute.toString().padLeft(2, '0');
|
||
|
|
||
|
return Center(
|
||
|
child: Column(children: [
|
||
|
const Text(
|
||
|
'Das ist die Zeit',
|
||
|
style: TextStyle(fontSize: 18),
|
||
|
),
|
||
|
const SizedBox(height: 16),
|
||
|
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||
|
Text(
|
||
|
'${time.hour}:${time.minute}',
|
||
|
style: const TextStyle(fontSize: 32),
|
||
|
),
|
||
|
const SizedBox(width: 16),
|
||
|
ElevatedButton(
|
||
|
onPressed: () async {
|
||
|
//TODO auslagern
|
||
|
TimeOfDay? newTime = await showTimePicker(
|
||
|
context: context,
|
||
|
initialTime: time,
|
||
|
builder: (context, child) {
|
||
|
return MediaQuery(
|
||
|
data: MediaQuery.of(context)
|
||
|
.copyWith(alwaysUse24HourFormat: true),
|
||
|
child: child!,
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
if (newTime == null) return;
|
||
|
setState(() {
|
||
|
time = newTime;
|
||
|
print('Zeit geändert $newTime, Zeit aktualisiert?: $time');
|
||
|
});
|
||
|
},
|
||
|
child: const Text('Zeit einstellen'))
|
||
|
])
|
||
|
]),
|
||
|
);
|
||
|
}
|
||
|
}
|