Home > Software design >  Flutter - setState function does not work
Flutter - setState function does not work

Time:12-14

I am trying to manage some gap between elements and update the gap using setState()

    double gap = 64.00;
    @override
    Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset : false,
      body: SafeArea(
          child: Container(
            padding: const EdgeInsets.symmetric(horizontal: 32),
            width: double.infinity,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                SizedBox(
                  height: gap,
                ),
    
                // svg image
                SvgPicture.asset(
                  'assets/ic_instagram.svg',
                  color: primaryColor,
                  height: 64,
                ),
    
                SizedBox(
                  height: gap,
                ),
...

and update "gap" onTap:

...    
GestureDetector(
                      onTap: () {
                        setState(() {
                          gap = 16.00;
                        });
                      },
                      child: TextFieldInput(
                        textEditingController: _passwordController,
                        hintText: 'Enter your password',
                        textInputType: TextInputType.text,
                        isPass: true,
                      ),
                    ),

But "gap" does not change even on tapping on the TextFieldInput. Can anyone help with this ?

CodePudding user response:

gesture detector doesn't work with textField try adding ignorePointer

GestureDetector(
            child: new IgnorePointer (
                child: new TextField(
              .......
            ))),
        onTap: () {
         //do some thing
        },

CodePudding user response:

The TextField has its onTap property, I think this is the cause of your problem. You should you onTap property of TextField or use another suitable widget

  • Related