如何显示不带脚手架的点心栏 [英] How to show snackBar without Scaffold
本文介绍了如何显示不带脚手架的点心栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的应用中显示小吃栏以通知用户,但没有脚手架会显示我错误.我当前的代码是:
I am trying to show snackbar in my app to notify User but without scaffold it shows me error. My current code is:
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,
),
),
),
),
)
推荐答案
它可以获取当前上下文并显示小吃栏:
It can get the current context and show snackbar like this:
void _showToast(BuildContext context) {
final scaffold = Scaffold.of(context);
scaffold.showSnackBar(
SnackBar(
content: const Text('Updating..'),
),
);
this._showToast(context);
这篇关于如何显示不带脚手架的点心栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文