Sum*_*ans 2 dart snackbar flutter
有没有办法在小吃栏上显示多行文本而不引发 renderflex 错误?
我尝试用灵活的和扩展的小部件包装它,但两者都没有帮助,我仍然收到错误。以下方法收到的 errorMessage 有时可能很长。
void displayMessage(context, errorMessage) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Expanded(
child: Row(
children: [
const Icon(
Icons.warning,
color: Colors.red,
size: 22,
),
const SizedBox(
width: 7,
),
Text(
errorMessage,
style: const TextStyle(
fontWeight: FontWeight.normal,
fontSize: 17,
color: Colors.red),
),
],
),
),
backgroundColor: Colors.black,
padding: const EdgeInsets.all(20),
duration: const Duration(milliseconds: 5000),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
)
);
}
Run Code Online (Sandbox Code Playgroud)
取出Expanded并Text用包裹Flexible,
content: Row(
children: [
const Icon(
Icons.warning,
color: Colors.red,
size: 22,
),
const SizedBox(
width: 7,
),
Flexible(
child: Text(
errorMessage,
style: const TextStyle(
fontWeight: FontWeight.normal,
fontSize: 17,
color: Colors.red),
),
),
],
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1120 次 |
| 最近记录: |