【发布时间】:2020-04-06 05:44:24
【问题描述】:
如何从底部和左侧/右侧为小吃店设置空间?
【问题讨论】:
如何从底部和左侧/右侧为小吃店设置空间?
【问题讨论】:
您可以使用Container 包装小吃栏的内容(文本),并根据您的需要提供margin 或padding。下面的工作代码示例:
final snackBar = SnackBar(
content: Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.only(left: 100, right: 50, bottom: 5),
child: Text('Yay! A SnackBar!'),
)
【讨论】:
你可以试试这个:
final snackBar = SnackBar(
elevation: 6.0,
behavior: SnackBarBehavior.floating,
content: Text(
"Snack bar test",
style: TextStyle(color: Colors.white),
),
);
这里的主要变化是 SnackBar 类中的 behavior 属性的存在,该属性将 SnackBarHehavior 属性作为值。
【讨论】:
将行为属性作为 SnackBarBehavior.floating 添加到 Snackbar。请参阅下面的代码。
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Error from Stripe: ${e.error.localizedMessage}'),
behavior: SnackBarBehavior.floating, // this will add margin to the snackbar
),
)
【讨论】:
试试这个:临时解决方案:
Scaffold.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.transparent,
content: Container(
width: MediaQuery.of(context).size.width * 9,
height: 30.0,
color: Colors.red,
padding: EdgeInsets.only(left: 100, right: 50, bottom: 5),
child: Center(child:Text('Yay! A SnackBar!')),
)
)
);
或者
Scaffold.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.transparent,
content: Container(
width: MediaQuery.of(context).size.width * 9,
height: 30.0,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10.0)
),
padding: EdgeInsets.only(left: 100, right: 50, bottom: 5),
child: Center(
child:Text('Yay! A SnackBar!')
),
)
)
);
【讨论】:
试试flushbar,
使用margin 属性给空间。
Flushbar(
message: "Lorem Ipsum is simply dummy text of the printing and typesetting industry",
icon: Icon(
Icons.info_outline,
size: 28.0,
color: Colors.blue[300],
),
duration: Duration(seconds: 3),
leftBarIndicatorColor: Colors.blue[300],
margin: EdgeInsets.all(8),
borderRadius: 8,
)..show(context);
输出:
【讨论】:
小吃店有点难以改变。我发现了一个非常易于使用的包,您可以随意自定义它,这将使您拥有与具有所有自定义属性的小吃店相同的外观。
包名为FlushBar
此软件包适用于 IOS 和 Android。我个人使用过,效果很好。此外,您可以在不使用脚手架的情况下使用 FlushBar,而与小吃店一样,您必须能够引用脚手架才能显示小吃店。像这样,
final snackBar = SnackBar(content: Text('Yay! A SnackBar!'));
// Find the Scaffold in the widget tree and use it to show a SnackBar.
Scaffold.of(context).showSnackBar(snackBar);
这是他们提供的用于使用冲洗条的 sn-p。
class YourAwesomeApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'YourAwesomeApp',
home: Scaffold(
Container(
child: Center(
child: MaterialButton(
onPressed: (){
Flushbar(
title: "Hey Ninja",
message: "Lorem Ipsum is simply dummy text of the printing and typesetting industry",
duration: Duration(seconds: 3),
)..show(context);
},
),
),
),
),
);
}
}
【讨论】: