cpd_2022_zi/lib/widgets/timepicker.dart

80 lines
2.6 KiB
Dart

import 'package:flutter/material.dart';
// ignore: must_be_immutable
class TimePicker extends StatefulWidget {
TimeOfDay _initialTime;
TimePicker(this._initialTime, {Key? key});
TimeOfDay get getCurrentTime => _initialTime;
@override
State<StatefulWidget> createState() => TimePickerState();
}
class TimePickerState extends State<TimePicker> {
TimePickerState();
@override
Widget build(BuildContext context) {
return Center(
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
'${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}',
style: const TextStyle(fontSize: 22),
),
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'))
widget.descriptionText,
style: const TextStyle(fontSize: 12),
),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
'${widget._initialTime.hour.toString().padLeft(2, '0')}:${widget._initialTime.minute.toString().padLeft(2, '0')}',
style: const TextStyle(fontSize: 22),
),
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'))
])
]),
);
}
}