Kod*_*ata 3 flutter flutter-web
我正在尝试渲染渐变按钮,但在某些设备上,渐变颜色不会像下图那样展开。
我怎样才能解决这个问题?
谢谢!
代码
class GradientButton extends StatelessWidget {
final Widget child;
final VoidCallback onPressed;
const GradientButton({@required this.child, @required this.onPressed});
@override
Widget build(BuildContext context) {
return RaisedButton(
textColor: Colors.white,
shape: StadiumBorder(),
padding: const EdgeInsets.all(0.0),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: <Color>[Color(0xff00F260), Color(0xff0575E6)],
),
),
padding: EdgeInsets.all(8.0),
child: child
onPressed: onPressed,
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
class GradientButton extends StatelessWidget {
final Widget child;
final VoidCallback onPressed;
const GradientButton({Key key, this.onPressed, this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
decoration: ShapeDecoration(
shape: const StadiumBorder(),
gradient: LinearGradient(
colors: [Color(0xff00F260), Color(0xff0575E6)],
),
),
child: MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: const StadiumBorder(),
child: child,
onPressed: onPressed,
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
您还可以获得一些MaterialButton效果,例如点击时出现波纹、当 onPressed 为空时禁用等。对于中的高程设置shadows属性ShapeDecoration
shadows: [
BoxShadow(
color: Colors.black54,
spreadRadius: 0.5,
blurRadius: 3,
offset: Offset(1, 1))
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2205 次 |
| 最近记录: |