106 lines
3.1 KiB
Dart
106 lines
3.1 KiB
Dart
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
|
|
import '../utils/utils.dart';
|
|
|
|
class CalendarWidget extends StatefulWidget {
|
|
CalendarWidget({Key? key, required this.callback, this.enabled, required this.value}) : super(key: key);
|
|
|
|
// This widget is the home page of your application. It is stateful, meaning
|
|
// that it has a State object (defined below) that contains fields that affect
|
|
// how it looks.
|
|
|
|
// This class is the configuration for the state. It holds the values (in this
|
|
// case the title) provided by the parent (in this case the App widget) and
|
|
// used by the build method of the State. Fields in a Widget subclass are
|
|
// always marked "final".
|
|
|
|
final String value;
|
|
final ValueChanged callback;
|
|
final bool? enabled;
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _PageState();
|
|
}
|
|
|
|
class _PageState extends State<CalendarWidget> {
|
|
String date = "";
|
|
DateTime selectedDate = DateTime.now();
|
|
|
|
Future<void> _selectDate(BuildContext context) async {
|
|
final DateTime? picked = await showDatePicker(
|
|
context: context,
|
|
initialDate: selectedDate,
|
|
firstDate: DateTime(1900, 8),
|
|
lastDate: DateTime(2101),
|
|
locale: Locale(context.locale.toString()),
|
|
// builder: (context, child) {
|
|
// return Transform.scale(
|
|
// scale: 1.40,
|
|
// child: child,
|
|
// );
|
|
// },
|
|
);
|
|
if (picked != null && picked != selectedDate) {
|
|
widget.callback.call(picked);
|
|
setState(() {
|
|
selectedDate = picked;
|
|
date = Utils.convertDateToPost(selectedDate, context.locale.toString());
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
setState(() {
|
|
if (widget.value.isEmpty) {
|
|
date = Utils.getDateDisplay(context.locale.toString());
|
|
} else {
|
|
date = Utils.convertDateToDay(widget.value, context);
|
|
}
|
|
});
|
|
});
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// This method is rerun every time setState is called, for instance as done
|
|
// by the _incrementCounter method above.
|
|
//
|
|
// The Flutter framework has been optimized to make rerunning build methods
|
|
// fast, so that you can just rebuild anything that needs updating rather
|
|
// than having to individually change instances of widgets.
|
|
return Container(
|
|
height: 60,
|
|
width: double.infinity,
|
|
padding: EdgeInsets.all(10),
|
|
// decoration: shapeDecoration(ColorCustom.greyBG, ColorCustom.greyText),
|
|
child: InkWell(
|
|
onTap: () {
|
|
_selectDate(context);
|
|
},
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
date,
|
|
textAlign: TextAlign.right,
|
|
style: GoogleFonts.kanit(
|
|
color: Color(0xff565656),
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w300,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|