flutter_web 文档说 dart:svg 已移植,但是您如何将其与 flutter 资产/小部件系统一起使用?
我正在使用 flutter for web 构建一个 web 应用程序,我确信在 flutter 的移动版本中有一种方法可以在设备中存储数据,但我不知道这是否甚至在 web 的 flutter 中实现了。
我正在使用Flutter 1.10.15和Android Studio 3.5.1用于 Flutter Web 开发和我的大!问题是我无法调试,甚至无法在控制台中打印某些内容,因为chrome当我按下工具栏中的“运行”或“调试”按钮时,只显示一个白页。
我可以运行项目的唯一方法是在网络服务器模式下使用以下命令并在AlertDialog弹出窗口中显示变量值和异常!:
flutter run -d web-server --web-hostname=192.168.50.147 --web-port=5624 --local-engine=host_debug_unopt --profile -v lib\pages\splash.dart
Run Code Online (Sandbox Code Playgroud)
谁能告诉我一个解决方案?
我创建了一个flutter web使用网络图像和资产图像的项目,在我的电脑上调试时一切正常,但是当我将其部署到 Web 服务器时,网络图像工作正常,但资产图像根本不显示。当我在 Web 浏览器控制台中检查页面时,出现以下错误:
$1 @ window.dart:120
/assets/slack.png:1 Failed to load resource: the server responded with a status of 503 ()
window.dart:120 Error while trying to load an asset: Failed to load asset at "assets/slack.png" (503)
$1 @ window.dart:120
/assets/flutterLogo.png:1 Failed to load resource: the server responded with a status of 503 ()
window.dart:120 Error while trying to load an asset: Failed to load asset at "assets/flutterLogo.png" (503)
$1 @ window.dart:120
/assets/kross.jpg:1 Failed to load resource: …Run Code Online (Sandbox Code Playgroud) flutter build web 将通过混淆和缩小来构建我的 flutter 应用程序。
我希望我的错误堆栈是可读的。
我应该如何修改命令?
在 flutter web 上,我从计算机中选择一个图像文件并获取一个 File 图像对象。然后我想将它上传到 Firebase 存储。对于 Android 和 iOS 版本的应用程序,我使用了 Firebase Cloud Function 和 http 多部分请求。它有效,但对于该应用程序的网络版本则无效。所以,
如何直接或通过 Cloud Functions 将 html 图像文件上传到 Firebase 存储?
file-upload image-upload google-cloud-functions firebase-storage flutter-web
我在使用 Flutter web 并将图像上传到 Firestore 时遇到问题。我很确定问题出在图像选择器中,因为普通(移动)图像选择器不适用于网络。普通图像选择器返回一个文件,但替代image_picker_web返回一个图像,该图像在上传时被拒绝,因为它需要一个Future<File>.
image_picker_web有一种替代方法可以返回Uint8List我使用过的 a,然后转换为Filevia dart:html- 并正常上传,但图像已损坏且无法查看。
这是我所做的:
按下按钮 - 选择图像Uint8List> 转换为Image,存储在内存中并在屏幕上显示
onPressed: () async {
//Upload Image as Uint8List
imageBytes = await ImagePickerWeb.getImage(asUint8List: true);
//Convert Uint8List to Image
_image = Image.memory(imageBytes);
//Show new image on screen
setBottomSheetState(() {
image = _image;
});
},
Run Code Online (Sandbox Code Playgroud)
转换Uint8List为Fileusingdart:html File和 name as users UID.png (PNG Uploaded)
imageFile = html.File(imageBytes, …Run Code Online (Sandbox Code Playgroud) 我不是在问 webview。这是关于 Flutter Web 应用程序。当用户按下浏览器内置的后退按钮时,我需要返回特定页面。
任何猜测?
当我按下后退按钮时出现此错误
Error: Assertion failed: org-dartlang-
sdk:///flutter_web_sdk/lib/_engine/engine/history.dart:110:14
_userProvidedRouteName != null
is not true
at Object.throw_ [as throw] (http://localhost:8300/dart_sdk.js:4770:11)
at Object.assertFailed (http://localhost:8300/dart_sdk.js:4721:15)
Run Code Online (Sandbox Code Playgroud) 我有独立的 Android 应用程序。然后我开发了较小的网络应用程序Flutter并将其导出到网络服务器。它WebView作为 Android 版 Kotlin 中该独立应用程序的一部分加载到内部。
Android 支持 postmessaging,我可以WebView通过渠道直接发送数据。我的问题是如何在 Flutter Dart 代码中(在我的 Web 应用程序中)收听这些消息?
这是我在 Kotlin Android App 中使用的代码:
private var port: WebMessagePort? = null
@TargetApi(Build.VERSION_CODES.M)
private fun initPostMessagePort(){
val channelsAvailable = webView.createWebMessageChannel()
port = channelsAvailable.firstOrNull()
port?.apply {
setWebMessageCallback(object : WebMessageCallback() {
override fun onMessage(port: WebMessagePort, message: WebMessage) {
//TODO do something with message
}
})
}?:kotlin.run {
App.log("Port initialization failed - channels not available")
}
}
@TargetApi(Build.VERSION_CODES.M)
private fun sendMessageToPort(message: String){
port?.let …Run Code Online (Sandbox Code Playgroud) 当我使用该函数将数据添加到数据库时,并且在我添加的服务器上Access-Control-Allow-Origin,它不会被 CORS 阻止,但是当我查看浏览器控制台工具选项卡控制台时仍然出错
Access to XMLHttpRequest at 'https://int.goo.id/api/pg/sso.register' from origin 'http://127.0.0.1:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
如何停用 CORS?
flutter-web ×10
flutter ×7
dart ×3
debugging ×1
file-upload ×1
firebase ×1
image-upload ×1
web ×1