Home > Net >  Flutter it says The return type 'int' isn't a 'Null'
Flutter it says The return type 'int' isn't a 'Null'

Time:10-27

I'm new to flutter and I encountered this error. It says "The return type 'int' isn't a 'Null', as required by the closure's context.dartreturn_of_invalid_type_from_closure"

I tried troubleshooting however I can't get to fix the error

`

`class _SelectButton extends StatelessWidget {
  int _value = 0;
  @override
  Widget build(BuildContext context) {
    return BlocBuilder<SignUpCubit, SignUpState>(
      buildWhen: (previous, current) => previous.email != current.email,
      builder: (context, state) {
        return Padding(
          padding: const EdgeInsets.all(20.0),
          child: Row(
            children: <Widget>[
              GestureDetector(
                onTap: () => setState(() => _value = 0),
                child: Container(
                  height: 56,
                  width: 56,
                  color: _value == 0 ? Colors.grey : Colors.transparent,
                  child: Icon(Icons.call),
                ),
              ),
              SizedBox(width: 4),
              GestureDetector(
                onTap: () => setState(() => _value = 1),
                child: Container(
                  height: 56,
                  width: 56,
                  color: _value == 1 ? Colors.grey : Colors.transparent,
                  child: Icon(Icons.message),
                ),
              ),
            ],
          ),
        );
      },
    );
  }

  void setState(Null Function() param0) {}
}

`

CodePudding user response:

maybe you auto generated setState which is implemented in StatefulWidget please delete your setState method and change your StatelessWidget with StatefulWidget you can change it easy by using alt enter from your IDE to change it

CodePudding user response:

    class _RadioButton extends StatefulWidget {
  @override
  _RadioButtonState createState() => _RadioButtonState();
}

class _RadioButtonState extends State<_RadioButton> {
  String _value = "";
  @override
  Widget build(BuildContext context) {
    return BlocBuilder<SignUpCubit, SignUpState>(
      buildWhen: (previous, current) => previous.email != current.email,
      builder: (context, state) {
        return Padding(
          padding: const EdgeInsets.all(20.0),
          child: Row(
            children: <Widget>[
              GestureDetector(
                onTap: () => setState(() => _value = "Coach"),
                child: Container(
                  height: 56,
                  width: 56,
                  color: _value == "Coach" ? Colors.grey : Colors.transparent,
                  child: const Icon(Icons.call),
                ),
              ),
              const SizedBox(width: 4),
              GestureDetector(
                onTap: () => setState(() => _value = "Player"),
                child: Container(
                  height: 56,
                  width: 56,
                  color: _value == "Player" ? Colors.grey : Colors.transparent,
                  child: const Icon(Icons.message),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
  • Related