import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:intl/intl.dart'; class CycleAddDatePicker extends StatefulWidget { const CycleAddDatePicker({ Key? key, required this.dateCTRL, required double deviceBlockSize, }) : _deviceBlockSize = deviceBlockSize, super(key: key); final TextEditingController dateCTRL; final double _deviceBlockSize; @override _CycleAddDatePickerState createState() => _CycleAddDatePickerState(); } class _CycleAddDatePickerState extends State { @override Widget build(BuildContext context) { return InkWell( onTap: () async { var res = await showDatePicker( context: context, initialDate: DateTime.now(), firstDate: DateTime(2010, 1), lastDate: DateTime(2101), ); if (res != null) { // dateTimeFrom = res; setState( () { widget.dateCTRL.text = DateFormat('y-M-d').format(res); // dateValue = DateFormat('y-M-d').format( // dateTimeFrom, // ); // baraye tavize makane gharar giri baraye api }, ); } }, child: Row( mainAxisSize: MainAxisSize.min, children: [ Expanded( child: TextField( enabled: false, controller: widget.dateCTRL, decoration: InputDecoration( icon: Icon( FontAwesomeIcons.alignLeft, size: 7 * widget._deviceBlockSize, ), labelStyle: TextStyle( fontWeight: FontWeight.w100, fontSize: 4 * widget._deviceBlockSize, ), labelText: 'Date', isDense: true, contentPadding: EdgeInsets.only( bottom: 7, right: 3, left: 3, ), // border: InputBorder.none, ), style: TextStyle( fontWeight: FontWeight.w700, fontSize: 5 * widget._deviceBlockSize, ), ), ), Icon(FontAwesomeIcons.angleDown) ], ), ); } }