flutter 我的代码在elevatedbutton和if语句处标记错误

mm5n2pyu  于 2023-01-27  发布在  Flutter
关注(0)|答案(1)|浏览(180)
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: () {})),}

if语句标记了一个错误,我的if语句也是
我还没试过。

xqkwcwgp

xqkwcwgp1#

你的代码是在坏的形状,它可以像

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: () {},
),

相关问题