【发布时间】:2019-12-07 13:55:49
【问题描述】:
我试图在我的应用程序中显示小吃栏以通知用户,但没有脚手架它会显示错误。我当前的代码是:
scaffoldKey.currentState?.showSnackBar(
new SnackBar(
backgroundColor: color ?? Colors.red,
duration: Duration(milliseconds: milliseconds),
content: Container(
height: 50.0,
child: Center(
child: new Text(
title,
style: AppTheme.textStyle.lightText.copyWith(color: Colors.white),
overflow: TextOverflow.ellipsis,
),
),
),
),
)
【问题讨论】:
-
您可能还有一个包含
Scaffold的父小部件。为此创建一个scaffoldKey并将其传递给您的孩子widget,该孩子必须显示Snakcbar。请注意,如果没有Scaffold小部件,您将无法使用Sanckbar。 -
我想在没有脚手架的情况下实现它。这可以实现吗?
-
不,没有
Scaffold,你不能这样做。
标签: flutter dart flutter-layout snackbar