Button 如何向颤振按钮添加边框?
我最近刚进入flutter,到目前为止我很喜欢它,但我在一些UI更改上遇到了麻烦。感谢您的帮助 我的目标是得到一个圆形按钮,它有一个蓝色背景的图标,但是在外面有一个深蓝色的边框。附有照片 我的做法是:Button 如何向颤振按钮添加边框?,button,dart,icons,flutter,border,Button,Dart,Icons,Flutter,Border,我最近刚进入flutter,到目前为止我很喜欢它,但我在一些UI更改上遇到了麻烦。感谢您的帮助 我的目标是得到一个圆形按钮,它有一个蓝色背景的图标,但是在外面有一个深蓝色的边框。附有照片 我的做法是: 拿一个蓝色的圆形按钮 在那个按钮上放一个图标 添加边框 我被第3步卡住了,因为我不知道如何添加边界,或者考虑到我处理问题的方式,这是否可能。具体的颜色目前对我来说并不重要,我会在以后更改主题 这就是我目前拥有的代码: var messageBtn = new Row( children:
var messageBtn = new Row(
children: <Widget>[
new Padding(
padding: const EdgeInsets.all(20.0),
child: new RawMaterialButton(
onPressed: _messages,
child: new Padding(
padding: const EdgeInsets.all(20.0),
child: new Icon(
Icons.message,
size: 30.0,
color: Colors.white,
),
),
shape: new CircleBorder(),
fillColor: Colors.deepPurple,
),
),
new Padding(
padding: const EdgeInsets.all(8.0),
child: new Text(
'Send Messages',
style: new TextStyle(
fontSize: 20.0,
),
)),
],
);
var messageBtn=新行(
儿童:[
新填料(
填充:常数边集全部(20.0),
子项:新的RawMaterialButton(
onPressed:\u消息,
孩子:新的填充物(
填充:常数边集全部(20.0),
孩子:新图标(
图标。信息,
尺寸:30.0,
颜色:颜色,白色,
),
),
形状:新的CircleBorder(),
fillColor:Colors.deepPurple,
),
),
新填料(
填充:常数边集全部(8.0),
儿童:新文本(
“发送消息”,
样式:新文本样式(
字体大小:20.0,
),
)),
],
);
它产生了以下结果:
我想要这个:嗨,凯瑟琳,欢迎 您可以通过深入了解组成
MaterialButton
的小部件来实现所需
首先,您需要小部件。这提供了更灵活的样式使用一个新的
Ink
可以包含一个识别onTap
并绘制飞溅效果的小部件。默认情况下,飞溅会持续到包含框的边缘,但您可以通过给墨水池
一个非常大的边界半径
使其成为圆形
下面是一个您所追求的按钮示例:
Material(
type: MaterialType.transparency, //Makes it usable on any background color, thanks @IanSmith
child: Ink(
decoration: BoxDecoration(
border: Border.all(color: Colors.indigoAccent, width: 4.0),
color: Colors.indigo[900],
shape: BoxShape.circle,
),
child: InkWell(
//This keeps the splash effect within the circle
borderRadius: BorderRadius.circular(1000.0), //Something large to ensure a circle
onTap: _messages,
child: Padding(
padding:EdgeInsets.all(20.0),
child: Icon(
Icons.message,
size: 30.0,
color: Colors.white,
),
),
),
)
),
结果如下:
只需将
图标按钮
包装到容器中
,并将其装饰设置为如下所示:
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.blue, width: 4),
color: Colors.yellow,
shape: BoxShape.circle,
),
child: IconButton(
iconSize: 56,
icon: Icon(Icons.check),
onPressed: () {},
),
),
可以使用带边框的FloatingActionButton:
FloatingActionButton(
mini: false,
backgroundColor: Colors.blue.shade900,
splashColor: Colors.black,
onPressed: () {
logOutDialog(context);
},
hoverElevation: 1.5,
shape: StadiumBorder(
side: BorderSide(
color: Colors.blue, width: 4)),
elevation: 1.5,
child: Icon(
Icons.logout,
color: _foregroundColor,
),
)
颤振2中有文本按钮
:
TextButton(
style: ButtonStyle(
side: RedSelectedBorderSide(),
),
child: Text(
"Button"
),
onPressed: (){}
);
其中RedSelectedBorderSide()
是:
class RedSelectedBorderSide extends MaterialStateBorderSide {
@override
BorderSide resolve(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
return BorderSide(
width: 2,
color: Colors.red,
); //
}
return null;// Defer to default value on the theme or widget.
}
}
class RedSelectedBorderSide扩展了MaterialStateBorderSide{
@凌驾
边界解析(设置状态){
if(states.contains(MaterialState.selected)){
返回边界边(
宽度:2,
颜色:颜色,红色,
); //
}
return null;//遵从主题或小部件上的默认值。
}
}
用于文本按钮
内部style
使用side
和MaterialStateProperty
和BorderSide
text按钮(
样式:钮扣样式(
侧面:MaterialStateProperty.all(
边框边(宽度:1,颜色:颜色。黑色),
),
),
子:文本(
“我的按钮”
),
onPressed:(){}
);
Hmm,更新是否破坏了这一点?由于BoxEdition形状,现在有一个白盒作为背景。也许它从未被注意到。@IanSmith,它仍然在最新的颤振稳定(1.17)上为我工作。很高兴看一看您的代码。@Xander下面是一个示例应用程序,它显示了这个问题:@IanSmith谢谢,我明白您的意思了。我们可能应该使用材质(类型:MaterialType.transparency)
。我会更新答案