63 lines
1.5 KiB
Dart
63 lines
1.5 KiB
Dart
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;
|
|
}
|
|
}
|