The reason of this was that is not a statefull widget ,at lenght I update as a statefull widget and make k as local variable and setState when update happend
class Fdate extends StatefulWidget {
@override
_FdateState createState() => _FdateState();
}
class _FdateState extends State<Fdate> {
String k ='Select Date';
DateTime selectedDate = DateTime.now();
void setDate(String date){
setState(() {
k = date;
});
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Container(
padding: EdgeInsets.zero,
margin: EdgeInsets.all(0),
// color: Colors.black87,
child:
Align(
alignment: Alignment.centerLeft,
child: Text("Select Date",style: TextStyle(fontSize: 14.sp,fontWeight: FontWeight.w400,fontFamily:'OpenSans',),),
)
),
Container(
// color: Colors.blue,
margin: EdgeInsets.only(top:0),
// color: Colors.blue,
child: Align(
alignment: Alignment.centerLeft,
child: GestureDetector(
onTap: () async {
final DateTime picked = await showDatePicker(
context:context ,
initialDate: DateTime.now(),
firstDate: DateTime(2001),
lastDate: DateTime(2200),
// initialEntryMode: DatePickerEntryMode.input,
);
setDate(picked.toIso8601String().split('T').first);
},
child: Container(
// height:40.h,
height: MediaQuery.of(context).size.height*0.050,
child: DropdownButton(
icon: Container(
alignment: Alignment.centerLeft,
// color: Colors.blueGrey,
padding: EdgeInsets.zero,
margin: EdgeInsets.only(left: MediaQuery.of(context).size.width*0.25),
child: IconButton(
icon:Icon(Icons.arrow_drop_down,size:25.w,),
color: Colors.black87,
padding: EdgeInsets.all(0),
constraints: BoxConstraints(),
onPressed: (){
// print("Hello");
// showDatePicker(
// context:context ,
// initialDate: DateTime.now(),
// firstDate: DateTime(2001),
// lastDate: DateTime(2200),
// ).then((pickedDate) => print(pickedDate));
},
)),
hint:Container(
// color: Colors.red,
child: Text(k,style: TextStyle(fontSize: 14.sp,fontWeight: FontWeight.bold,color:Colors.black87,fontFamily:'OpenSans'),)),
),
),
),
),
)
],
);
}
}