Files
fcs/lib/pages/widgets/input_date.dart

101 lines
3.4 KiB
Dart
Raw Normal View History

2020-10-08 03:32:52 +06:30
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class InputDate extends StatelessWidget {
2024-01-23 16:28:08 +06:30
final String? labelTextKey;
final IconData? iconData;
2020-10-08 03:32:52 +06:30
final TextEditingController controller;
2021-09-10 14:25:37 +06:30
final FormFieldValidator<String>? validator;
2020-10-08 03:32:52 +06:30
final int maxLines;
final bool withBorder;
2021-09-10 14:25:37 +06:30
final Color? borderColor;
final TextInputType? textInputType;
2020-10-08 03:32:52 +06:30
final bool autoFocus;
final String dateFormatString;
const InputDate(
2021-09-10 14:25:37 +06:30
{Key? key,
required this.labelTextKey,
required this.iconData,
required this.controller,
2020-10-08 03:32:52 +06:30
this.validator,
this.maxLines = 1,
this.withBorder = false,
this.borderColor,
this.autoFocus = false,
this.dateFormatString = "dd MMM yyyy",
this.textInputType})
: super(key: key);
@override
Widget build(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
return Padding(
padding: const EdgeInsets.only(top: 15.0, bottom: 5),
child: TextFormField(
readOnly: true,
onTap: () async {
var dateFormatter = new DateFormat(dateFormatString);
FocusScope.of(context).unfocus();
var initialDate = DateTime.now();
2024-01-23 16:28:08 +06:30
if (controller.text != "") {
2020-10-08 03:32:52 +06:30
try {
initialDate = dateFormatter.parse(controller.text);
} catch (e) {} // ignore error
}
var d = await showDatePicker(
context: context,
firstDate: DateTime(0),
lastDate: DateTime(2025),
initialDate: initialDate,
);
2024-01-23 16:28:08 +06:30
if (d != null && controller.text != "") {
2020-10-08 03:32:52 +06:30
controller.text = dateFormatter.format(d);
}
},
controller: controller,
autofocus: autoFocus,
cursorColor: primaryColor,
style: textStyle,
maxLines: maxLines,
keyboardType: textInputType,
decoration: new InputDecoration(
// hintText: '',
hintStyle: TextStyle(
height: 1.5,
),
labelText: labelTextKey == null
? null
2024-01-23 16:28:08 +06:30
: AppTranslations.of(context)!.text(labelTextKey!),
2020-10-12 08:26:27 +06:30
labelStyle: languageModel.isEng
? newLabelStyle(color: Colors.black54, fontSize: 20)
: newLabelStyleMM(color: Colors.black54, fontSize: 20),
2020-10-08 03:32:52 +06:30
icon: iconData == null
? null
: Icon(
iconData,
color: primaryColor,
),
enabledBorder: withBorder
? OutlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0),
)
: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
focusedBorder: withBorder
? OutlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0),
)
: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
),
validator: validator),
);
}
}