Flutter 使自定义RisedButton展开
我不熟悉颤振和定制上升按钮 我有这个按钮Flutter 使自定义RisedButton展开,flutter,button,width,Flutter,Button,Width,我不熟悉颤振和定制上升按钮 我有这个按钮 import 'package:flutter/material.dart'; class EasyButton extends StatelessWidget { final onPressed; final text; EasyButton(this.onPressed, this.text); @override Widget build(BuildContext context) { return RaisedBut
import 'package:flutter/material.dart';
class EasyButton extends StatelessWidget {
final onPressed;
final text;
EasyButton(this.onPressed, this.text);
@override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: this.onPressed,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(60),
),
padding: EdgeInsets.all(0),
elevation: 2,
splashColor: Colors.blue[300],
child: Ink(
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(60),
gradient: new LinearGradient(
colors: [Colors.blue, Colors.blue[800]],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 10),
child: new Text(this.text, style: TextStyle(color: Colors.white)),
),
);
}
}
但是当我在扩展小部件中使用它时,我得到了这个结果
如何使其100%父级宽度扩展
具有双重无限性
带容器
将升起的按钮包裹在按钮中间,并指定最小宽度
ButtonTheme(
minWidth: double.infinty, //takes up all the width
child: RaisedButton(),
)
然后我有灰色区域变得不可见,但可点击和梯度延伸与文本长度相同。作出更改,请更新您的代码,让我们知道谢谢。现在整个灰色区域变成了蓝色。请看原始问题中的截图。仍然不是你想要的样子。在我这方面效果很好,也许其他一些特性阻碍了你想要的样子。尝试删除填充并使用其他属性。它会拉伸,但不会渐变。如果我删除渐变,所有按钮看起来都是蓝色的。看起来只有梯度是那个宽度。没有多少填充物可供使用:(