简体   繁体   中英

my code is flagging an error at the elevatedbutton and if statement

child: ElevatedButton(
                    style: ButtonStyle(backgroundColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> State){}
                    )),
                      if (states.contains(MaterialState.pressed))
                      return Colors.green;
                    child: Text('Add task',style: GoogleFonts.roboto(fontSize: 10),
                    ),
                    onPressed: () {})),}

The if statement is flagging an error and my if statement too

I have not try anything yet.

Your code is on bad shape, It can be like

child: ElevatedButton(
  style: ButtonStyle(
    backgroundColor: MaterialStateProperty.resolveWith<Color>(
        (Set<MaterialState> states) {
      if (states.contains(MaterialState.pressed)) return Colors.green;
      return Colors.white;
    }),
  ),
  child: Text(
    'Add task',
  ),
  onPressed: () {},
),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM