Con*_*tov 4 android dart snackbar flutter flutter-getx
我用来Get.snackbar()显示连接到 API 的过程。\n我不明白如何以编程方式关闭小吃栏?\n我有以下代码:
@override\n Future<List> getImportantData(String inputData) async {\n try {\n final token = basicApiAuthString;\n print("requesting API with the following request: $inputData");\n Get.snackbar(\n "Requesting very important data...",\n "",\n duration: 60.seconds, // it could be any reasonable time, but I set it lo-o-ong\n snackPosition: SnackPosition.BOTTOM,\n showProgressIndicator: true,\n isDismissible: true,\n backgroundColor: Colors.lightGreen,\n colorText: Colors.white,\n );\n List importantData = await _client.requestAPI(basicAuthString: token, body: inputData);\n .then((importantData) {\n // Here I need to dismiss the snackbar I am still showing to user\n print("I want to close snackbar here but I don\'t know how to do that!");\n // Then I return data for future processing... \n return importantData;\n });\n\n return importantData;\n } on DioError catch (error) {\n // Here I handle all possible API errors... Also I want to close snackbar here as well.\n \n }\n } // getImportantData() function.\nRun Code Online (Sandbox Code Playgroud)\n我需要考虑以下因素:
\n.then()部分永远不会被执行。所以,我需要一些外部的方式来关闭零食。Navigator.of(context).hide...不是解决方案,因为我使用 GetX。
\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\nPS:这是snackbar的定义,但不能帮助我澄清:
\nhttps://pub.dev/documentation/get/3.4.2/route_manager/GetNavigation/snackbar.html
\nmuf*_*zmi 12
GetX 已经有一个名为closeAllSnackbars()和的方法closeCurrentSnackbar()。
因此,请使用closeAllSnackbars()关闭所有打开的 Snackbars。
Get.closeAllSnackbars();
Run Code Online (Sandbox Code Playgroud)
要关闭当前活动的 Snakbar,只需调用closeCurrentSnackbar().
Get.closeCurrentSnackbar();
Run Code Online (Sandbox Code Playgroud)
您还可以通过致电 来检查小吃店是否打开/活动isSnackbarOpen()。
Get.isSnackbarOpen();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6923 次 |
| 最近记录: |