flutter 抖动错误-参数类型'MaterialStateProperty< RoundedRectangleBorder>'无法指派给参数类型'OutlinedBorder

ncgqoxb0  于 2022-12-05  发布在  Flutter
关注(0)|答案(3)|浏览(81)

想要自定义按钮的默认边框半径,但出现以下错误:“无法将参数类型'MaterialStateProperty'指派给参数类型'OutlinedBorder'”

Padding(
              padding: const EdgeInsets.all(20.0),
              child: ElevatedButton(
                  style: ElevatedButton.styleFrom(
                      shape: MaterialStateProperty.all<RoundedRectangleBorder>(
                          RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(10.0))),
                      elevation: 0,
                      primary: Colors.white,
                      minimumSize: const Size.fromHeight(50)),
                  onPressed: () {
                    Navigator.pushNamed(context, '/home');
                    // Navigator.of(context).pushReplacementNamed('/home');
                  },
                  child: const Text(
                    "Start",
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 18,
                        color: Color.fromRGBO(86, 96, 49, 1)),
                  )),
            ),
yiytaume

yiytaume1#

只需删除MaterialStateProperty.all(或者用下面的代码替换您的代码。

Padding(
  padding: const EdgeInsets.all(20.0),
  child: ElevatedButton(
      style: ElevatedButton.styleFrom(
          shape:RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(30.0),
          ),
          elevation: 0,
          primary: Colors.white,
          minimumSize: const Size.fromHeight(50)),
      onPressed: () {
        Navigator.pushNamed(context, '/home');
        // Navigator.of(context).pushReplacementNamed('/home');
      },
      child: const Text(
        "Start",
        style: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 18,
            color: Color.fromRGBO(86, 96, 49, 1)),
      )),
)
hmae6n7t

hmae6n7t2#

如果您不想避免,只需添加泛型类型,这对键入很有帮助。Documentation
高架按钮(样式:按钮样式(背景颜色:所有(Colors.red),形状:材料状态属性。所有(常量圆角矩形边界(边界半径:BorderRadius.all(半径.圆形(8)),),)),子项:const Text('使用Google登录'),onPressed:(){},);

yuvru6vn

yuvru6vn3#

这对类型很有帮助,如果你想使用,你只需要添加泛型类型。Documentation

ElevatedButton(
      style: ButtonStyle(
          backgroundColor: MaterialStateProperty.all<Color>(Colors.red),
          shape: MaterialStateProperty.all<RoundedRectangleBorder>(
            const RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(8)),
            ),
          )),
      child: const Text('Text'),
      onPressed: () {},
    );

相关问题