- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 flutter 应用程序中,我将数据从移动设备发送到服务器。该部分的完成方式如下。
注册.dart
void _createUser()
{
DataFetch().createUser(AppNavigation.getAPIUrl() +
"user/saveUser", user).then((String result){
print("RESULT IS: "+result);
});
}
data_fetch.dart
Future<String> createUser(String url, User body) async {
print("BODY: " + body.toJson().toString());
return http.post(url, body: convert.json.encode(body.toJson()), headers: {
"Accept": "application/json",
"content-type": "application/json"
}).then((http.Response response) {
final int statusCode = response.statusCode;
print("RESPONSE: " + response.body);
print("STATUS CODE: " + statusCode.toString());
if (statusCode < 200 || statusCode > 400 || response.body == null) {
throw new Exception("Error while fetching data");
} else {
return response.body;
}
});
}
我的 UI 位于 register.dart 中,data_fetch.dart 是一个单独的类,其中包含支持各种数据传递工作的方法。
我需要显示一个snackbar
,直到数据保存完成。我知道我可以使用 FutureBuilder
,但无需将其附加为返回一些 UI 的小部件,因为保存数据后我没有可显示的 UI。我正在尝试将数据发送到服务器,我只需要指出这一点。
我该怎么做?无论如何,Future
中似乎没有这样的设施。
最佳答案
为你的脚手架创建一个 key ,如下所示:
var _key = new GlobalKey<ScaffoldState>();
然后将其与脚手架连接:
Scaffold(
key: _key,
body: your_ui_here,
)
将这把 key 传递给你的 future
void _createUser(var key)
{
DataFetch().createUser(AppNavigation.getAPIUrl() +
"user/saveUser", user).then((String result){
key.currentState.showSnackbar(
Snackbar(content:Text("hello"))
);
});
}
您可以将此 key 传递到任何地方,只要附加的脚手架没有被丢弃,它就会起作用。
关于android - Flutter - 如何在 `snackbar` 中显示 `Future`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55547394/
Snackbar.make(...).show() 将只显示最后一个 snackbar,不像 toast 其他 snackbar 都消失了。 for(int i = 1;i mSnackbarLis
Snackbar.make(...).show() 将只显示最后一个 snackbar,不像 toast 其他 snackbar 都消失了。 for(int i = 1;i mSnackbarLis
我有一个实现 swipetorefresh 布局的 recyclerview - 如果您在列表中向下滑动手指,它将加载较新的帖子。它还有一个 onloadmorelistener 用于对我的 recy
我正在尝试添加 Snackbar到我的应用程序, Snackbar.make(findViewById(android.R.id.content), R.string.not_
我对 snackbar 有疑问。我的 snackbar 对解雇没有反应 我的代码: ConnectivityReceiver = new BroadcastReceiver() { @
我试图在显示 snackbar 时将焦点直接放在 snackbar 中的操作按钮上,以便让用户知道可以使用 snackbar 中显示的警报消息执行某些操作。注意:这是针对对讲模式。我尝试使用 requ
如果我连续多次调用snackbar,则只显示最后一个snackbar 项。 例如使用下面的代码,只会显示第 3 项。似乎第 1 项和第 2 项的 Snackbar.LENGTH_LONG 被忽略(并设
我的应用程序中有一个包含消息的 RecyclerView。在向右滑动时,我将其配置为删除消息,在向左滑动时,我将其配置为存档消息。下面是 ItemTouchHelper 部分删除归档相关的代码: if
我正在尝试使用此设置 snackbar 长度: Snackbar oSnackbar = Snackbar.make(Context, "Testing", Snackbar.LENGTH_LONG)
flutter SnackBar的动画入口是什么? ScaffoldMessanger.of(context).showSnackBar(SnackBar( animation: /* --- *
在我的应用程序中,可能(并且有意!)多个 SnackBar元素被创建。这些 SnackBar元素排队并一个接一个地显示,这一切都很好。但是,如果我转到不同的屏幕然后返回(所以 push 和 pop 一
我有一个 flutter 应用程序,它在应用程序的不同屏幕上发出许多不同的 http 请求。现在,我想实现一些通用的错误处理,例如,每当没有连接时,我都想显示一个 SnackBar,无论我目前在应用程
我因为工作室提示 Dialog 而苦苦挣扎已弃用, 所以我又去阅读文档,似乎 Toast也被弃用了。 所以我尝试从 Toast 迁移至Snackbar ,但目前失败...我 我加了 implement
我有问题在我的应用程序中实现了 BLoC 模式。 一旦我有一个特殊的事件,我需要显示一个 snackbar ,但我有这个错误: The following assertion was thrown b
我尝试在 JavaScript 中使用“if else”语句,但无法使其工作。 这是js脚本: var vid = document.getElementById("myVideo"); functi
我使用 Material 2 创建了 Snackbar(下面我添加了演示)。我在主页中有一个按钮,当我单击该按钮时,它会在页面底部显示消息(snackbar)。我想将其(快捷栏消息)更改为页面的右上角
我有按钮而不是 float 操作按钮,我想将其与 snackbar 锚定,因为它与 float 操作栏锚定,就像显示 snackbar 时 float 操作按钮向上移动一样,对于 float 操作栏,
在ReactJS中,我想仅在登录成功时显示material-ui Snackbar。在ReactJS中有哪些方法可以做到这一点? 最佳答案 Material-ui Snackbar 的 open 状态
您好,我有一段代码可以生成 snackbar 。我使用带有关闭选项的 Bootstrap 警报来生成 snackbar ,但是当我单击关闭按钮时,它对我不起作用。是否可以添加关闭选项?如果是,你能解释
令我惊讶的是,如果 TextView 跨越多行,Snackbar 本身似乎会在 TextView 上设置额外的填充。它有效地使 Snackbar 的高度加倍,并且由于某种原因仅影响垂直填充。我在 Sn
我是一名优秀的程序员,十分优秀!