- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在使用默认的 ButtonThemeData 制作渐变按钮之前很容易......但现在我无法弄清楚如何使用新的 MaterialButtons 正确制作自定义渐变按钮。
我正在尝试制作一个三个自定义渐变按钮,它必须使用 AppTheme 中定义的 ButtonStyle(splashColor、elevation...)。
升高按钮
GradientElevatedButton 使用带有渐变背景的 ElevatedButtonThemeData
文本按钮
GradientTextButton 使用带有渐变文本的 TextButtonThemeData
轮廓按钮
GradientOutlinedButton 使用带有渐变边框和渐变文本的 OutlinedButtonThemeData
已经试过了
我曾尝试用 ShaderMask 包装 ElevatedButton,但它涵盖了墨迹动画,因此无法实现我的目标。
最佳答案
ElevatedButton
DecoratedBox(
decoration: BoxDecoration(gradient: LinearGradient(colors: [Colors.red, Colors.blue])),
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(primary: Colors.transparent),
child: Text('Elevated Button'),
),
)
OutlinedButton
OutlinedButton
,您需要执行一些额外的步骤。创建一个类(空安全):class MyOutlinedButton extends StatelessWidget {
final VoidCallback onPressed;
final Widget child;
final ButtonStyle? style;
final Gradient? gradient;
final double thickness;
const MyOutlinedButton({
Key? key,
required this.onPressed,
required this.child,
this.style,
this.gradient,
this.thickness = 2,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(gradient: gradient),
child: Container(
color: Colors.white,
margin: EdgeInsets.all(thickness),
child: OutlinedButton(
onPressed: onPressed,
style: style,
child: child,
),
),
);
}
}
用法:MyOutlinedButton(
onPressed: () {},
gradient: LinearGradient(colors: [Colors.indigo, Colors.pink]),
child: Text('OutlinedButton'),
)
关于flutter - ElevatedButton、TextButton 和 OutlinedButton 渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66355441/
我正在做一个 TextButton,我需要在页面的右侧部分。 按钮内容在右侧,但按钮本身占据了页面的整个宽度。我怎样才能让它不呢? 这是我的代码: Padding( padding: const
随着 Flutter 2.0 的发布,FlatButton已被替换为 TextButton . 因此,填充属性不再直接可用,而是作为 ButtonStyle属性(property)。 我的问题是,我该
我刚刚在 Flutter 中更新了我的代码以使用 TextButton 而不是旧的 FlatButton .我不知道如何设置按钮的宽度和高度。 我有两个问题。第一个是我现在有这个图标按钮: TextB
我正在使用FlatButton并传递了属性 FlatButton( splashColor: Colors.transparent, highlightColor: Color
如何在 TextButton 中分离文本和图标,使其像 whatsapp 设置一样 Row( modifier = Modifier .fillMaxWidth()
尝试更改我的 Android 应用程序中所有 TextButtons 的默认颜色 w/material。我看到我可以设置“materialButtonStyle”和“materialButtonOut
有没有办法向 TextButton 添加尾随图标? 这是我的代码: TextButton( child: Center( child: Text ('Dummy', s
我已经阅读了一些关于 scene2d 的 UI 功能的教程和文档,但我不太明白皮肤是如何工作的。我只是想要一个按下时会改变颜色的 TextButton。我设法改变了 TextButton 的背景,但这
有没有办法向 TextButton 添加尾随图标? 这是我的代码: TextButton( child: Center( child: Text ('Dummy', s
我在使用 scene2d 时遇到问题。我已经以编程方式创建了一个 TextButton (没有 json 文件),并且由于某种原因,当我按下它时 isPressed() 不会返回 true 。不仅如此
我有一个 GWT TextButton。应用于全局 css 文件的以下 css 样式不执行任何操作: .gwt-TextButton { color: red !important; } 为什么
在 libGDX 中,我有一个 TextButtonStyle 定义如下: TextButtonStyle style = new TextButtonStyle(); style.font = he
免责声明:我是 LibGDX 的新手,对 java 有相当基本的了解。我已经使用 Google 和 Stackoverflow 来搜索答案,但无济于事。对不起英语,我不是母语人士。 这是我的问题: 我
我正在编写一个使用按钮的 libGDX 应用程序。该按钮看起来像这样: TextButton btnPrint = new TextButton( "Print", skin ); btnPrint.
我一直在尝试使用本文所述的距离场字体:https://github.com/libgdx/libgdx/wiki/Distance-field-fonts 当我只是渲染字体时一切正常,但是当我尝试在
大家好!我正在尝试使用 libgdx 和 scene2d 设置 TextButton 中文本的大小。 下面是我如何创建和初始化文本按钮对象: Skin skin = new Skin(); skin.
假设我有这个 TextButton : TextButton( style: TextButton.styleFrom( minimumSize: const Size(newWidt
我如何在新的 TextButton 中添加给定高度并使其角变圆 这就是在现已弃用的 FlatButton 中执行此操作的方法。 FlatButton( height: 44, mate
我想创建一个 MaterialButton以编程方式使用 TextButton风格就可以了。 我尝试了以下操作,但生成的按钮有背景颜色,而不是 TextButton . val newContext
我正在制作一款游戏,其中有两个按钮可以旋转玩家,一个向左,另一个向右。我在 LibGDX 中使用 TextButton。我的问题是,ClickListener 中的方法 clicked(InputEv
我是一名优秀的程序员,十分优秀!