Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

setState isn't referenced flutter 3.0

I am working on a school project, since we updated the flutter version from 2.X to 3.0.1 we face this problem : setState isn’t referenced. We do not understand as we are using this in a statefulWidget. We went to the internet to show what the problem is but we cannot find a way to make it work because most of the time it was because people where using a stateless widget which is not our case.

Start of file :

``` class PageProfilAmi extends StatefulWidget {
  final User user;
  final String? idRelation;

  const PageProfilAmi({Key? key, required this.user, this.idRelation})
      : super(key: key);

  @override
  _PageProfilAmiState createState() => _PageProfilAmiState();
}

class _PageProfilAmiState extends State<PageProfilAmi> {
  IconData _icon = Icons.add;

  @override
  void initState() {
    super.initState();
  } ``` 

Where we have the issue :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

``` IconButton(
            onPressed: () {
                setState() {
                              _icon = Icons.delete;
                            }

                AuthController.deleteAmi(
                           widget.idRelation.toString());
                          },
                icon: Icon(
                           _icon,
                           color: CustomColors.MAIN_PURPLE,
                           size: 20,
                          ),
        ) ```

>Solution :

enter code hereHere issue is in syntax of setState

setState(() { 

// code 

 });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading