Flutter Web 给出有关“不支持的操作”的错误:Platform._operatingSystem
Flutter web 给出有关 Unsupported operation: Platform._operatingSystem
代码在 flutter android 上正常运行的错误。我认为错误在于我的上传图像方法,它在 flutter web 上不起作用。
Here is the error
Error: Unsupported operation: Platform._operatingSystem
at Object.throw_ [as throw] (http://localhost:37805/dart_sdk.js:5388:11)
at Function._operatingSystem (http://localhost:37805/dart_sdk.js:61565:17)
at Function.get operatingSystem [as operatingSystem] (http://localhost:37805/dart_sdk.js:61611:27)
at get _operatingSystem (http://localhost:37805/dart_sdk.js:61524:27)
at Function.desc.get [as _operatingSystem] (http://localhost:37805/dart_sdk.js:5897:17)
at get isWindows (http://localhost:37805/dart_sdk.js:61542:26)
at Function.desc.get [as isWindows] (http://localhost:37805/dart_sdk.js:5897:17)
at Function._isAbsolute (http://localhost:37805/dart_sdk.js:56712:33)
at io._File.new.get isAbsolute [as isAbsolute] (http://localhost:37805/dart_sdk.js:56708:34)
at io._File.new.get [_absolutePath] (http://localhost:37805/dart_sdk.js:56719:26)
at io._File.new.get absolute [as absolute] (http://localhost:37805/dart_sdk.js:58252:30)
at firebase_storage.Reference.__.putFile (http://localhost:37805/packages/firebase_storage/firebase_storage.dart.lib.js:385:27)
at productprovider.ProductProvider.new.uploadProductImage (http://localhost:37805/packages/phataphat_web_dashboard/services/productprovider.dart.lib.js:223:93)
at uploadProductImage.next (<anonymous>)
at runBody (http://localhost:37805/dart_sdk.js:43060:34)
at Object._async [as async] (http://localhost:37805/dart_sdk.js:43091:7)
at productprovider.ProductProvider.new.uploadProductImage (http://localhost:37805/packages/phataphat_web_dashboard/services/productprovider.dart.lib.js:218:20)
at http://localhost:37805/packages/phataphat_web_dashboard/pages/product/widget/addnewproduct.dart.lib.js:1342:47
at ink_well._InkResponseState.new.[_handleTap] (http://localhost:37805/packages/flutter/src/material/icon_button.dart.lib.js:44059:31)
at tap.TapGestureRecognizer.new.invokeCallback (http://localhost:37805/packages/flutter/src/gestures/recognizer.dart.lib.js:201:18)
at tap.TapGestureRecognizer.new.handleTapUp (http://localhost:37805/packages/flutter/src/gestures/tap.dart.lib.js:429:40)
at tap.TapGestureRecognizer.new.[_checkUp] (http://localhost:37805/packages/flutter/src/gestures/tap.dart.lib.js:229:12)
at tap.TapGestureRecognizer.new.handlePrimaryPointer (http://localhost:37805/packages/flutter/src/gestures/tap.dart.lib.js:175:23)
at tap.TapGestureRecognizer.new.handleEvent (http://localhost:37805/packages/flutter/src/gestures/recognizer.dart.lib.js:454:16)
at pointer_router.PointerRouter.new.[_dispatch] (http://localhost:37805/packages/flutter/src/gestures/pointer_router.dart.lib.js:94:9)
at http://localhost:37805/packages/flutter/src/gestures/pointer_router.dart.lib.js:125:26
at LinkedMap.new.forEach (http://localhost:37805/dart_sdk.js:29167:11)
at pointer_router.PointerRouter.new.[_dispatchEventToRoutes] (http://localhost:37805/packages/flutter/src/gestures/pointer_router.dart.lib.js:122:29)
at pointer_router.PointerRouter.new.route (http://localhost:37805/packages/flutter/src/gestures/pointer_router.dart.lib.js:114:37)
at binding$5.WidgetsFlutterBinding.new.handleEvent (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:397:26)
at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:383:24)
at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:37805/packages/flutter/src/rendering/layer.dart.lib.js:5819:13)
at binding$5.WidgetsFlutterBinding.new.[_handlePointerEventImmediately] (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:356:14)
at binding$5.WidgetsFlutterBinding.new.handlePointerEvent (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:329:43)
at binding$5.WidgetsFlutterBinding.new.[_flushPointerEventQueue] (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:318:14)
at binding$5.WidgetsFlutterBinding.new.[_handlePointerDataPacket] (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:308:65)
at Object.invoke1 (http://localhost:37805/dart_sdk.js:204155:7)
at _engine.EnginePlatformDispatcher.__.invokeOnPointerDataPacket (http://localhost:37805/dart_sdk.js:182962:15)
at _engine.PointerBinding.__.[_onPointerData] (http://localhost:37805/dart_sdk.js:183925:49)
at http://localhost:37805/dart_sdk.js:184408:28
at http://localhost:37805/dart_sdk.js:184361:16
at loggedHandler (http://localhost:37805/dart_sdk.js:184035:11)
这是代码
Future<String> uploadProductImage(filePath, productName) async {
File file = File(filePath);
var timeStamp = Timestamp.now().millisecondsSinceEpoch;
FirebaseStorage _storage = FirebaseStorage.instance;
try {
await _storage
.ref('ProductImage/$productName$timeStamp')
.putFile(file);
} on FirebaseException catch (e) {
// e.g, e.code == 'canceled'
if (kDebugMode) {
print(e.code);
}
}
String downloadURL = await _storage
.ref('ProductImage/$productName$timeStamp')
.getDownloadURL();
productUrl = downloadURL;
notifyListeners();
return downloadURL;
}
Flutter web is giving an error about Unsupported operation: Platform._operatingSystem
codes are running properly on flutter android. I think the error is with my upload image method it's not working on flutter web.
Here is the error
Error: Unsupported operation: Platform._operatingSystem
at Object.throw_ [as throw] (http://localhost:37805/dart_sdk.js:5388:11)
at Function._operatingSystem (http://localhost:37805/dart_sdk.js:61565:17)
at Function.get operatingSystem [as operatingSystem] (http://localhost:37805/dart_sdk.js:61611:27)
at get _operatingSystem (http://localhost:37805/dart_sdk.js:61524:27)
at Function.desc.get [as _operatingSystem] (http://localhost:37805/dart_sdk.js:5897:17)
at get isWindows (http://localhost:37805/dart_sdk.js:61542:26)
at Function.desc.get [as isWindows] (http://localhost:37805/dart_sdk.js:5897:17)
at Function._isAbsolute (http://localhost:37805/dart_sdk.js:56712:33)
at io._File.new.get isAbsolute [as isAbsolute] (http://localhost:37805/dart_sdk.js:56708:34)
at io._File.new.get [_absolutePath] (http://localhost:37805/dart_sdk.js:56719:26)
at io._File.new.get absolute [as absolute] (http://localhost:37805/dart_sdk.js:58252:30)
at firebase_storage.Reference.__.putFile (http://localhost:37805/packages/firebase_storage/firebase_storage.dart.lib.js:385:27)
at productprovider.ProductProvider.new.uploadProductImage (http://localhost:37805/packages/phataphat_web_dashboard/services/productprovider.dart.lib.js:223:93)
at uploadProductImage.next (<anonymous>)
at runBody (http://localhost:37805/dart_sdk.js:43060:34)
at Object._async [as async] (http://localhost:37805/dart_sdk.js:43091:7)
at productprovider.ProductProvider.new.uploadProductImage (http://localhost:37805/packages/phataphat_web_dashboard/services/productprovider.dart.lib.js:218:20)
at http://localhost:37805/packages/phataphat_web_dashboard/pages/product/widget/addnewproduct.dart.lib.js:1342:47
at ink_well._InkResponseState.new.[_handleTap] (http://localhost:37805/packages/flutter/src/material/icon_button.dart.lib.js:44059:31)
at tap.TapGestureRecognizer.new.invokeCallback (http://localhost:37805/packages/flutter/src/gestures/recognizer.dart.lib.js:201:18)
at tap.TapGestureRecognizer.new.handleTapUp (http://localhost:37805/packages/flutter/src/gestures/tap.dart.lib.js:429:40)
at tap.TapGestureRecognizer.new.[_checkUp] (http://localhost:37805/packages/flutter/src/gestures/tap.dart.lib.js:229:12)
at tap.TapGestureRecognizer.new.handlePrimaryPointer (http://localhost:37805/packages/flutter/src/gestures/tap.dart.lib.js:175:23)
at tap.TapGestureRecognizer.new.handleEvent (http://localhost:37805/packages/flutter/src/gestures/recognizer.dart.lib.js:454:16)
at pointer_router.PointerRouter.new.[_dispatch] (http://localhost:37805/packages/flutter/src/gestures/pointer_router.dart.lib.js:94:9)
at http://localhost:37805/packages/flutter/src/gestures/pointer_router.dart.lib.js:125:26
at LinkedMap.new.forEach (http://localhost:37805/dart_sdk.js:29167:11)
at pointer_router.PointerRouter.new.[_dispatchEventToRoutes] (http://localhost:37805/packages/flutter/src/gestures/pointer_router.dart.lib.js:122:29)
at pointer_router.PointerRouter.new.route (http://localhost:37805/packages/flutter/src/gestures/pointer_router.dart.lib.js:114:37)
at binding$5.WidgetsFlutterBinding.new.handleEvent (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:397:26)
at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:383:24)
at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:37805/packages/flutter/src/rendering/layer.dart.lib.js:5819:13)
at binding$5.WidgetsFlutterBinding.new.[_handlePointerEventImmediately] (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:356:14)
at binding$5.WidgetsFlutterBinding.new.handlePointerEvent (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:329:43)
at binding$5.WidgetsFlutterBinding.new.[_flushPointerEventQueue] (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:318:14)
at binding$5.WidgetsFlutterBinding.new.[_handlePointerDataPacket] (http://localhost:37805/packages/flutter/src/gestures/binding.dart.lib.js:308:65)
at Object.invoke1 (http://localhost:37805/dart_sdk.js:204155:7)
at _engine.EnginePlatformDispatcher.__.invokeOnPointerDataPacket (http://localhost:37805/dart_sdk.js:182962:15)
at _engine.PointerBinding.__.[_onPointerData] (http://localhost:37805/dart_sdk.js:183925:49)
at http://localhost:37805/dart_sdk.js:184408:28
at http://localhost:37805/dart_sdk.js:184361:16
at loggedHandler (http://localhost:37805/dart_sdk.js:184035:11)
Here are the codes
Future<String> uploadProductImage(filePath, productName) async {
File file = File(filePath);
var timeStamp = Timestamp.now().millisecondsSinceEpoch;
FirebaseStorage _storage = FirebaseStorage.instance;
try {
await _storage
.ref('ProductImage/$productName$timeStamp')
.putFile(file);
} on FirebaseException catch (e) {
// e.g, e.code == 'canceled'
if (kDebugMode) {
print(e.code);
}
}
String downloadURL = await _storage
.ref('ProductImage/$productName$timeStamp')
.getDownloadURL();
productUrl = downloadURL;
notifyListeners();
return downloadURL;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Adie 所提到的,该问题已通过使用 Web 版 Image Piker 得到解决。
您可以参考类似的stackoverflow线程:
有关更多信息,您可以参考此 链接,其中讨论了类似的问题。
As mentioned by Adie, the issue has been resolved by using Image Piker for web.
you can refer to the similar stackoverflow thread:
For more information you can refer to this link where a similar issue has been discussed.
我遇到了同样的问题,并通过使用
Platform
库和kIsWeb
类解决了它:I had same problem and solved it by use
Platform
library andkIsWeb
class: