outsourced add cam main widgets and cleaned karte widget up
time
This commit is contained in:
62
lib/screens/addCam/widgets/kont_dat.dart
Normal file
62
lib/screens/addCam/widgets/kont_dat.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
class KontDat extends StatefulWidget {
|
||||
final DateTime? initKontDat;
|
||||
final Function(DateTime) onDateChanged;
|
||||
|
||||
const KontDat(
|
||||
{super.key, required this.initKontDat, required this.onDateChanged});
|
||||
|
||||
@override
|
||||
State<KontDat> createState() => _KontDatState();
|
||||
}
|
||||
|
||||
class _KontDatState extends State<KontDat> {
|
||||
DateTime? kontDat;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
kontDat = widget.initKontDat;
|
||||
}
|
||||
|
||||
@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(() {
|
||||
kontDat = date;
|
||||
});
|
||||
widget.onDateChanged(date);
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.pickkontdat)),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(
|
||||
'${kontDat?.day}. ${kontDat?.month}. ${kontDat?.year}',
|
||||
),
|
||||
]),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<DateTime?> pickDate() async {
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: kontDat ?? DateTime.now(),
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(5000));
|
||||
|
||||
return date;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user