80 lines
2.0 KiB
Dart
80 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
class AbbauDat extends StatefulWidget {
|
|
final DateTime? initAbbauDat;
|
|
final Function(DateTime) onDateChanged;
|
|
|
|
const AbbauDat({super.key, required this.initAbbauDat, required this.onDateChanged});
|
|
|
|
@override
|
|
State<AbbauDat> createState() => _AbbauDatState();
|
|
}
|
|
|
|
class _AbbauDatState extends State<AbbauDat> {
|
|
DateTime? abbauDat;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
abbauDat = widget.initAbbauDat;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
children: [
|
|
Column(children: [
|
|
SizedBox(
|
|
width: 140,
|
|
child: ElevatedButton(
|
|
onPressed: () async {
|
|
final date = await pickDate();
|
|
if (date == null) return;
|
|
setState(() => abbauDat = date);
|
|
widget.onDateChanged(date);
|
|
},
|
|
child: Text(AppLocalizations.of(context)!.pickabbaudat)),
|
|
),
|
|
Row(
|
|
children: [
|
|
const SizedBox(
|
|
width: 10,
|
|
),
|
|
Builder(builder: (context) {
|
|
if (abbauDat != null) {
|
|
return Text(
|
|
'${abbauDat?.day}. ${abbauDat?.month}. ${abbauDat?.year}');
|
|
} else {
|
|
return Text(AppLocalizations.of(context)!.nichts);
|
|
}
|
|
}),
|
|
const SizedBox(
|
|
width: 10,
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
setState(() {
|
|
abbauDat = null;
|
|
});
|
|
},
|
|
child: const Text("X"))
|
|
]),
|
|
],
|
|
)
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<DateTime?> pickDate() async {
|
|
final date = await showDatePicker(
|
|
context: context,
|
|
initialDate: DateTime.now(),
|
|
firstDate: DateTime(2000),
|
|
lastDate: DateTime(5000));
|
|
if (date == null) return null;
|
|
|
|
return date;
|
|
}
|
|
}
|