Home > OS >  Selected date don't show in the textField Bottom Picker flutter
Selected date don't show in the textField Bottom Picker flutter

Time:06-01

I'm still a beginner in Dart and flutter I'm trying to Select date in a form , and show it in the textfield when it's picked , but when when i pick the date nothing show

here's the code :

TextField(
                       controller: dateinput,
                       textAlign: TextAlign.center,
                       readOnly: true,
                      
                  
                  onChanged: (value) {
                    birth = value ;
                  },
                  
                  
                onTap: () async {
                  BottomPicker.date(
                    title:  "Set your Birthday",
                    titleStyle: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize:  15,
                        color: Colors.teal
                    ),
                    onChange: (value) {
                        print(value);
                    },
                    onSubmit: (value) {
                        print(value);
                    },
                    bottomPickerTheme: BOTTOM_PICKER_THEME.plumPlate
                  ).show(context);
                  
                },

CodePudding user response:

You are currently just printing the value you are picking from the BottomPicker. Try also setting the controller's text to the value:

onTap: () async {
      BottomPicker.date(
          title:  "Set your Birthday",
          titleStyle: TextStyle(
              fontWeight: FontWeight.bold,
              fontSize:  15,
              color: Colors.teal
          ),
          onChange: (value) {
            print(value);
            setState({
              dateinput.text = value.toString();
            });
          },
          onSubmit: (value) {
            print(value);
            setState({
              dateinput.text = value.toString();
            });
          },
          bottomPickerTheme: BOTTOM_PICKER_THEME.plumPlate
      ).show(context);
    }

CodePudding user response:

Since you are using a controller, there is no need to setState. It will be displayed on the screen anyway. In addition, you don't need to override both "onSubmit" and "onChange"; One of them would be enough depending on your needs.

onTap: () => BottomPicker.date(
        title: "Set your Birthday",
        titleStyle: const TextStyle(
          fontWeight: FontWeight.bold,
          fontSize: 15,
          color: Colors.teal,
        ),
        onSubmit: (value) => controller.text = '$value',
      ).show(context),
  • Related