bissl weiter
This commit is contained in:
60
lib/screens/sharedWidgets/datum.dart
Normal file
60
lib/screens/sharedWidgets/datum.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
|
||||
class Datum extends StatefulWidget {
|
||||
final DateTime? initDatum;
|
||||
final Function(DateTime) onDateChanged;
|
||||
|
||||
const Datum({super.key, required this.initDatum, required this.onDateChanged});
|
||||
|
||||
@override
|
||||
State<Datum> createState() => _DatumState();
|
||||
}
|
||||
|
||||
class _DatumState extends State<Datum> {
|
||||
DateTime? datum;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
datum = widget.initDatum;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Row(children: [
|
||||
SizedBox(
|
||||
width: 140,
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
final date = await pickDate();
|
||||
if (date == null) return;
|
||||
setState(() => datum = date);
|
||||
widget.onDateChanged(date);
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.pickDate)),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(
|
||||
'${datum?.day}. ${datum?.month}. ${datum?.year}',
|
||||
),
|
||||
]),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<DateTime?> pickDate() async {
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: datum!,
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(5000));
|
||||
|
||||
return date;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user