无法更改 OutlinedButton 中的边框颜色

Spa*_*000 3 dart flutter

OutlinedButton我正在尝试更改我的边框,main.dart但它似乎不起作用。我环顾四周,似乎我需要添加BorderSide. 这就是我的outlinedButtonTheme样子:

              outlinedButtonTheme: OutlinedButtonThemeData(
                style: ButtonStyle(
                  backgroundColor: MaterialStateProperty.resolveWith<Color>(
                    (Set<MaterialState> states) {
                      if (states.contains(MaterialState.pressed)) {
                        return AppColors.SecondaryButtonPressed;
                      }

                      return AppColors.SecondaryButton;
                    },
                  ),
                  minimumSize: MaterialStateProperty.all<Size>(Size(335, 60)),
                  shape: MaterialStateProperty.all<OutlinedBorder>(
                      RoundedRectangleBorder(
                    side: BorderSide(
                        style: BorderStyle.solid,
                        color: AppColors.Primary,
                        width: 1), // <-- this doesn't work?
                    borderRadius: BorderRadius.all(Radius.circular(12)),
                  )),
                  foregroundColor: MaterialStateProperty.all<Color>(
                      AppColors.SecondaryButtonText),
                  textStyle: MaterialStateProperty.all<TextStyle>(TextStyle(
                    color: AppColors.SecondaryButtonText,
                    fontSize: 14 * FONT_SCALE_FACTOR,
                    fontWeight: FontWeight.w600,
                  )),
                ),
              ),
Run Code Online (Sandbox Code Playgroud)

如上所示,BorderSide 所在位置。看起来这根本不起作用。

小智 9

这对我有用:

OutlinedButton(onPressed: () {},
    style: ButtonStyle(shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0))),
                  side: MaterialStateProperty.all(BorderSide(
                    color: AppColors.blue,
                  )),
                ),)
Run Code Online (Sandbox Code Playgroud)


Cal*_*ves 5

我按照新材料按钮的指南进行操作并解决了这个问题,如下所示:

OutlinedButton.icon(
          style: OutlinedButton.styleFrom(
            shape: const RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(5)),
            ),
          ).copyWith(
            side: MaterialStateProperty.resolveWith<BorderSide>(
              (Set<MaterialState> states) {
                if (states.contains(MaterialState.disabled)) return null;
                return BorderSide(
                  color: Theme.of(context).primaryColor,
                  width: 3,
                );
                // Defer to the widget's default.
              },
            ),
          ),
     ...
Run Code Online (Sandbox Code Playgroud)

我需要为禁用状态和活动状态指定不同的颜色,因为我希望边框在活动时有颜色,在禁用时没有颜色(返回 null,因为默认情况下边框没有颜色,与旧按钮不同)