2

This is the screenshot of dialog box where i want to update new date after picked up. Getx dialog box

This is what i tried in controller.dart.

class AppointmentController extends GetxController {
String t;
var selectedDate = DateTime.now().obs;
var selectedTime = TimeOfDay.now().obs;

void selectDate() async {
final DateTime pickedDate = await showDatePicker(
  context: Get.context,
  initialDate: selectedDate.value,
  firstDate: DateTime(2018),
  lastDate: DateTime(2025),
   );
  if (pickedDate != null && pickedDate != selectedDate.value) {
  selectedDate.value = pickedDate;
  }
}

This is what I tried in homepage.dart

Obx(
()=>TextFormField(
onTap:(){
controller.selectDate();
},
initialValue:DateFormat('DD-MM- 
yyyy').format(controller.selectedDate.value).toString(),
),

1 Answers1

2

add a TextEditingController to the textformfield and change text with this controller

class AppointmentController extends GetxController {
String t;
var selectedDate = DateTime.now().obs;
var selectedTime = TimeOfDay.now().obs;
TextEditingController textEditingController=TextEditingController(); 


void selectDate() async {
final DateTime pickedDate = await showDatePicker(
  context: Get.context,
  initialDate: selectedDate.value,
  firstDate: DateTime(2018),
  lastDate: DateTime(2025),
   );
  if (pickedDate != null && pickedDate != selectedDate.value) {
  selectedDate.value = pickedDate;
  textEditingController.text=DateFormat('DD-MM- 
yyyy').format(selectedDate.value).toString();
  }
}

Obx(
()=>TextFormField(
controller:controller.textEditingController,
onTap:(){
controller.selectDate();
},
initialValue:DateFormat('DD-MM- 
yyyy').format(DateTime.now()).toString(),
),