Home > database >  Flutter inkwell ontap not reacting
Flutter inkwell ontap not reacting

Time:10-15

I want to ask why my ontap not working on my code , I'm creating separate function and I wanted to call it inside my textformfield which is in another separate function, I'm new and still learning , please help me.

this is my code

   _showTaskCategoriesDial({required Size size}) {
showDialog(
    context: context,
    builder: (ctx) {
      return AlertDialog(
        backgroundColor: Colors.black54,
        title: Text(
          'Job Category',
          textAlign: TextAlign.center,
          style: TextStyle(color: Colors.white, fontSize: 20),
        ),
        content: Container(
          width: size.width * 0.9,
          child: ListView.builder(
            shrinkWrap: true,
            itemCount: Persistent.jobCategoryList.length,
            itemBuilder: (ctx, index) {
              return InkWell(
                onTap: () {
                  setState(() {
                    _jobCategoryController.text =
                        Persistent.jobCategoryList[index];
                  });
                  Navigator.pop(context);
                },
                child: Row(
                  children: [
                    const Icon(
                      Icons.arrow_right_alt_outlined,
                      color: Colors.grey,
                    ),
                    Padding(
                      padding: EdgeInsets.all(8.0),
                      child: Text(
                        Persistent.jobCategoryList[index],
                        style: TextStyle(
                          color: Colors.grey,
                          fontSize: 16,
                        ),
                      ),
                    )
                  ],
                ),
              );
            },
          ),
        ),
      );
    });

}

and then I call it in my textFormFields like so and I don't know why it doesn't work

                        _textFormFields(
                            valueKey: 'JobCategory',
                            controller: _jobCategoryController,
                            enabled: false,
                            fct: () {
                              _showTaskCategoriesDial(size: size);
                            },

this is my textFormFields class

 Widget _textFormFields(
  {required String valueKey,
  required TextEditingController controller,
  required bool enabled,
  required Function fct,
  required int maxlength}) {
return Padding(
  padding: EdgeInsets.all(5.0),
  child: InkWell(
    onTap: () {
      fct;
    },
    child: TextFormField(
      validator: (value) {
        if (value!.isEmpty) {
          return 'Value is missing';
        }
        return null;
      },
      controller: controller,
      enabled: enabled,
      key: ValueKey(valueKey),
      style: TextStyle(
        color: Colors.white,
      ),
      maxLines: valueKey == 'JobDescription' ? 3 : 1,
      maxLength: maxlength,
      keyboardType: TextInputType.text,
      decoration: InputDecoration(
          filled: true,
          fillColor: Colors.black54,
          enabledBorder: UnderlineInputBorder(
              borderSide: BorderSide(color: Colors.black)),
          focusedBorder: UnderlineInputBorder(
            borderSide: BorderSide(
              color: Colors.black,
            ),
          ),
          errorBorder: UnderlineInputBorder(
              borderSide: BorderSide(color: Colors.red))),
    ),
  ),
);

}

CodePudding user response:

Change this:

Widget _textFormFields(
  {required String valueKey,
  required TextEditingController controller,
  required bool enabled,
  required Function fct,
  required int maxlength}) {
return Padding(
  padding: EdgeInsets.all(5.0),
  child: InkWell(
    onTap: () {
      fct;
    },
    child: TextFormField(
      ...
    ),
    ...
)

to:

Widget _textFormFields(
      {required String valueKey,
      required TextEditingController controller,
      required bool enabled,
      required Function()? fct, // <---- change this
      required int maxlength}) {
    return Padding(
      padding: EdgeInsets.all(5.0),
      child: InkWell(
        onTap: fct, // <---- change this
        child: TextFormField(
          ...
        ),
        ...
    )

or :

InkWell(
    onTap: (){
       fct(); // <---- change this
    }, 
    child: TextFormField(
      ...
    ),
)
  • Related