我需要改变边框颜色和宽度的OutlineButton,我知道通过直接内嵌提的是如下这样的一种方式:
OutlineButton(
child: Text('SIGN IN'),
padding: EdgeInsets.all(8.0),
onPressed: handleSignIn,
borderSide: BorderSide(
color: Colors.white, //Color of the border
style: BorderStyle.solid, //Style of the border
width: 1, //width of the border
),
)
Run Code Online (Sandbox Code Playgroud)
如果我按照下面提到的那样做,它会产生影响FlatButton,RaisedButton并且不会产生影响OutlineButton。
MaterialApp(
title: 'MyApp',
theme: ThemeData(
buttonTheme: ButtonThemeData(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
// this effects to FlatButton and RaisedButton
side: BorderSide(
color: Colors.white, //Color of the border
style: BorderStyle.solid, //Style of the border
width: 1, //width of the border
),
),
),
),
);
Run Code Online (Sandbox Code Playgroud)
那么,如何仅全局(通过应用程序)更改边框颜色和宽度OutlineButton?
我不认为你可以在 OutlineButton 中做到这一点。因此,我可以建议您在全局文件中创建全局主题数据。
var borderData=BorderSide(
color: Colors.white, //Color of the border
style: BorderStyle.solid, //Style of the border
width: 1, //width of the border
)
Run Code Online (Sandbox Code Playgroud)
然后您可以通过导入该全局文件轻松地在任何类中使用它。
OutlineButton(
child: Text('SIGN IN'),
padding: EdgeInsets.all(8.0),
onPressed: handleSignIn,
borderSide: borderData,
)
Run Code Online (Sandbox Code Playgroud)
在您的情况下,这将减少您的样板代码。
| 归档时间: |
|
| 查看次数: |
3764 次 |
| 最近记录: |