首页 > 解决方案 > Flutter:更改轮廓按钮的边框颜色

问题描述

旧版:

 OutlineButton.icon(
                        textColor: Theme.of(context).primaryColorDark,
                        icon: Icon(Icons.person_add),
                        label: Text(translate('contacts_list.import')),
                        shape: new RoundedRectangleBorder(
                        borderSide: BorderSide(
                          color: Colors.red,
                          style: BorderStyle.solid,
                          width: 1,
                        ),
);

新版本:

OutlinedButton.icon(
                    onPressed: () async {},
                    icon: Icon(Icons.person_add),
                    label: Text("Import"),
                    style: OutlinedButton.styleFrom(
                      backgroundColor: Colors.white,
                      primary: Theme.of(context).primaryColorDark,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(
                          Radius.circular(2),
                        ),
                      ),
                    ),
                  )

我不知道如何更改边框颜色。这里有一个例子,但与此效果无关:https ://docs.google.com/document/d/1yohSuYrvyya5V1hB6j9pJskavCdVq9sVeTqSoEPsWH0/edit

标签: flutterflutter-layout

解决方案


你可以这样做side: BorderSide()

例子:

OutlinedButton.icon(
                    onPressed: () async {},
                    icon: Icon(Icons.person_add),
                    label: Text("Import"),
                    style: OutlinedButton.styleFrom(
                      side: BorderSide(width: 2, color: Colors.green),
                      backgroundColor: Colors.white,
                      primary: Theme.of(context).primaryColorDark,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(
                          Radius.circular(2),
                        ),
                      ),
                    ),
                  )

推荐阅读