use*_*307 17 flutter flutter-layout flutter-web
我正在使用FlatButton
并通过属性
FlatButton(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
child: ...,
)
Run Code Online (Sandbox Code Playgroud)
该文件说FlatButton将变得过时,并使用TextButton
替代,但它并不需要splashColor
或highlightColor
性质
TextButton(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
child: ...,
)
Run Code Online (Sandbox Code Playgroud)
不起作用。不允许
我也试过这样
TextButton(
style: ButtonStyle(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
child: ...,
)
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?谢谢
dGo*_*ran 20
Colors.transparent 将拒绝任何效果,只是它是透明的,所以它会看起来没有任何反应......在 ButtonStyle 中,它与颜色类似。
ButtonStyle(
overlayColor: MaterialStateColor.resolveWith((states) => Colors.red),
),
Run Code Online (Sandbox Code Playgroud)
Bal*_*oss 15
你也可以这样使用
TextButton( onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: AppColors.primaryColor,
primary: Colors.black12),//ripple color
child:Text(AppLocalizations.of(context).startAdventure,
));
Run Code Online (Sandbox Code Playgroud)
您可以设置原色来创建波纹颜色
小智 11
由于平面按钮已被弃用,您必须使用 TextButton 而不是它,但在文本按钮中没有直接属性来更改初始颜色。因此,如果您想将初始颜色更改为透明,您可以这样做。
TextButton(
style: ButtonStyle(
overlayColor: MaterialStateProperty.all(Colors.transparent),
),
)
Run Code Online (Sandbox Code Playgroud)
小智 8
对于 Flutter 3.1.0 及以上版本,primary已被弃用,我使用以下方法更改了 spash 颜色:
style: TextButton.styleFrom(
backgroundColor: Colors.green, // Button color
foregroundColor: Colors.lime, // Splash color
),
child:Text(...)
Run Code Online (Sandbox Code Playgroud)
万一有帮助呢!
使用主题,它将应用于项目中的所有 TextButtons
将其放入 themeData 中:
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
splashFactory: NoSplash.splashFactory,
overlayColor: MaterialStateProperty.all(Colors.transparent),
),
),
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5126 次 |
最近记录: |