outsourced add cam main widgets and cleaned karte widget up
time
This commit is contained in:
79
lib/screens/addCam/widgets/abbau_dat.dart
Normal file
79
lib/screens/addCam/widgets/abbau_dat.dart
Normal file
@@ -0,0 +1,79 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user