Flutter 分频器小部件未出现
Flutter divider widget not appearing
我目前正在学习如何使用 Flutter SDK 和 Android Studio 构建应用程序。我的问题是我需要在 'Administrative' 文本和卡片的其余部分之间添加一个分隔线小部件,但正如您在下面的屏幕截图中看到的那样,分隔线没有显示出来。我试过更改大小(在这种情况下,两个文本之间的 space 只是增加)并且我尝试设置颜色以查看它是否在我的 phone 上默认为透明。没有任何效果!
这是我的卡片小部件状态代码:
class BBSCardState extends State<BBSCard>{
@override
Widget build(BuildContext context) {
return new Padding(
padding: const EdgeInsets.only(top: 16.0, bottom: 16.0, left: 12.0, right: 12.0),
child: new Card(
child: new Row(
children: <Widget>[
new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Padding(
padding: const EdgeInsets.only(top: 22.0, bottom: 8.0),
child: new Text("Administrative", style: new TextStyle(color: new Color.fromARGB(255, 117, 117, 117), fontSize: 32.0, fontWeight: FontWeight.bold)),
),
new Divider(),
new Text("text")
],
),
],
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
)
)
);
}
}
下面是卡片的屏幕截图:
还有:
有什么方法可以增加分隔线的实际行的大小? (不仅仅是间距)
谢谢!
您可以删除 Row
,然后 Column
将占用所有可用的 space,而 Divider
将具有宽度。
@override
Widget build(BuildContext context) {
return new Padding(
padding: const EdgeInsets.only(
top: 16.0, bottom: 16.0, left: 12.0, right: 12.0),
child: new Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Padding(
padding: const EdgeInsets.only(top: 22.0, bottom: 8.0),
child: new Text("Administrative",
style: new TextStyle(
color: new Color.fromARGB(255, 117, 117, 117),
fontSize: 32.0,
fontWeight: FontWeight.bold)),
),
new Divider(
color: Colors.red,
),
new Text("text")
],
),
),
);
}
要制作自定义分隔线,您可以检查 Divider
的实现并进行调整。例如。将 Divider
替换为
new SizedBox(
height: 10.0,
child: new Center(
child: new Container(
margin: new EdgeInsetsDirectional.only(start: 1.0, end: 1.0),
height: 5.0,
color: Colors.red,
),
),
)
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.lightGreen,width: 3.0),
),
),
)
您可以使用自定义容器代替分隔器...
如果您想为小部件视图画线,请尝试使用如下示例中的 BoxDecoration
child: new Container(
decoration: new BoxDecoration(
border: Border(
top: BorderSide(width: 1.0, color: Colors.grey),
left: BorderSide(width: 1.0, color: Colors.grey),
right: BorderSide(width: 1.0, color: Colors.grey),
bottom: BorderSide(width: 1.0, color: Colors.grey),),
);
child: new Row(
....
),
)
它发生在我身上,但我发现这个 属性 解决了它:thickness
child: Divider(
color: Colors.teal.shade100,
thickness: 1.0,
),
我遇到了同样的问题,但是通过将我的 Divider 放在 Expanded 小部件中解决了我的问题。
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Divider(
thickness: 1,
color: Color(0xff818181),
),
),
SizedBox(width: 10),
Text(
'Login using Social Media',
style: TextStyle(color: Color(0xff818181), fontWeight: FontWeight.w500),
),
SizedBox(width: 10),
Expanded(
child: Divider(
thickness: 1,
color: Color(0xff818181),
),
),
],
),
Container(
width: 200,
child: Divider(
thickness: 10,
color: Colors.red,
),
),
or
Expanded(
child: Divider(
thickness: 10,
color: Colors.red,
),
),
水平分隔线
Container(
width: double.infinity,
height: 2, // Thickness
color: Colors.grey,
)
垂直分隔线
Container(
width: 2, // Thickness
height: double.infinity,
color: Colors.grey,
)
在列中使用 Divider(),在行中使用 VerticalDivider()
Padding(
padding: const EdgeInsets.only(right:20),
child:Divider(
color: Color(0xfff8a9c5),
thickness: 2,
),
),
随心所欲地使用这个功能
Divider verticalDivider() {
return Divider(
height: 2,
color: Colors.greenAccent,
);
}
最近我要归档有圆角的分隔线。但如果我使用带边框的容器,则无法提供准确的输出。所以如果你想要圆角,你可以使用这个代码。
ClipRRect(
borderRadius: BorderRadius.circular(6.33.r),
child: Container(
width: 100.w,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color.fromRGBO(196, 196, 196, 0.6),
width: 5.0.w),
),
),
),
),
我目前正在学习如何使用 Flutter SDK 和 Android Studio 构建应用程序。我的问题是我需要在 'Administrative' 文本和卡片的其余部分之间添加一个分隔线小部件,但正如您在下面的屏幕截图中看到的那样,分隔线没有显示出来。我试过更改大小(在这种情况下,两个文本之间的 space 只是增加)并且我尝试设置颜色以查看它是否在我的 phone 上默认为透明。没有任何效果!
这是我的卡片小部件状态代码:
class BBSCardState extends State<BBSCard>{
@override
Widget build(BuildContext context) {
return new Padding(
padding: const EdgeInsets.only(top: 16.0, bottom: 16.0, left: 12.0, right: 12.0),
child: new Card(
child: new Row(
children: <Widget>[
new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Padding(
padding: const EdgeInsets.only(top: 22.0, bottom: 8.0),
child: new Text("Administrative", style: new TextStyle(color: new Color.fromARGB(255, 117, 117, 117), fontSize: 32.0, fontWeight: FontWeight.bold)),
),
new Divider(),
new Text("text")
],
),
],
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
)
)
);
}
}
下面是卡片的屏幕截图:
还有: 有什么方法可以增加分隔线的实际行的大小? (不仅仅是间距)
谢谢!
您可以删除 Row
,然后 Column
将占用所有可用的 space,而 Divider
将具有宽度。
@override
Widget build(BuildContext context) {
return new Padding(
padding: const EdgeInsets.only(
top: 16.0, bottom: 16.0, left: 12.0, right: 12.0),
child: new Card(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Padding(
padding: const EdgeInsets.only(top: 22.0, bottom: 8.0),
child: new Text("Administrative",
style: new TextStyle(
color: new Color.fromARGB(255, 117, 117, 117),
fontSize: 32.0,
fontWeight: FontWeight.bold)),
),
new Divider(
color: Colors.red,
),
new Text("text")
],
),
),
);
}
要制作自定义分隔线,您可以检查 Divider
的实现并进行调整。例如。将 Divider
替换为
new SizedBox(
height: 10.0,
child: new Center(
child: new Container(
margin: new EdgeInsetsDirectional.only(start: 1.0, end: 1.0),
height: 5.0,
color: Colors.red,
),
),
)
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.lightGreen,width: 3.0),
),
),
)
您可以使用自定义容器代替分隔器...
如果您想为小部件视图画线,请尝试使用如下示例中的 BoxDecoration
child: new Container(
decoration: new BoxDecoration(
border: Border(
top: BorderSide(width: 1.0, color: Colors.grey),
left: BorderSide(width: 1.0, color: Colors.grey),
right: BorderSide(width: 1.0, color: Colors.grey),
bottom: BorderSide(width: 1.0, color: Colors.grey),),
);
child: new Row(
....
),
)
它发生在我身上,但我发现这个 属性 解决了它:thickness
child: Divider(
color: Colors.teal.shade100,
thickness: 1.0,
),
我遇到了同样的问题,但是通过将我的 Divider 放在 Expanded 小部件中解决了我的问题。
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: Divider(
thickness: 1,
color: Color(0xff818181),
),
),
SizedBox(width: 10),
Text(
'Login using Social Media',
style: TextStyle(color: Color(0xff818181), fontWeight: FontWeight.w500),
),
SizedBox(width: 10),
Expanded(
child: Divider(
thickness: 1,
color: Color(0xff818181),
),
),
],
),
Container(
width: 200,
child: Divider(
thickness: 10,
color: Colors.red,
),
),
or
Expanded(
child: Divider(
thickness: 10,
color: Colors.red,
),
),
水平分隔线
Container(
width: double.infinity,
height: 2, // Thickness
color: Colors.grey,
)
垂直分隔线
Container(
width: 2, // Thickness
height: double.infinity,
color: Colors.grey,
)
在列中使用 Divider(),在行中使用 VerticalDivider()
Padding(
padding: const EdgeInsets.only(right:20),
child:Divider(
color: Color(0xfff8a9c5),
thickness: 2,
),
),
随心所欲地使用这个功能
Divider verticalDivider() {
return Divider(
height: 2,
color: Colors.greenAccent,
);
}
最近我要归档有圆角的分隔线。但如果我使用带边框的容器,则无法提供准确的输出。所以如果你想要圆角,你可以使用这个代码。
ClipRRect(
borderRadius: BorderRadius.circular(6.33.r),
child: Container(
width: 100.w,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color.fromRGBO(196, 196, 196, 0.6),
width: 5.0.w),
),
),
),
),