Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Error: Dart library 'dart:ui_web' is not available on this platform. #40

Closed
Patrick386 opened this issue Nov 6, 2023 · 3 comments
Closed
Labels
help wanted Extra attention is needed invalid This doesn't seem right question Further information is requested

Comments

@Patrick386
Copy link

My app is being developed to support both web and mobile. When I develop for the web first and then run it on mobile, I encounter the following package error:

main() {
...
  if(kIsWeb) {
  usePathUrlStrategy();
  }
...
}

Error:

Launching lib/main.dart on iPhone 14 in debug mode...
Running pod install...                                             19.8s
Running Xcode build...                                                  
Xcode build done.                                           292.3s
Failed to build iOS app
Error (Xcode): ../../flutter/packages/flutter_web_plugins/lib/src/navigation/url_strategy.dart:5:8: Error: Dart library 'dart:ui_web' is not available on this platform.


Could not build the application for the simulator.
Error launching application on iPhone 14.

Copy link
Contributor

github-actions bot commented Nov 6, 2023

Hi 👋🏽 Thank you for opening your first issue with simpleclub/url_strategy ❤

You can expect triage from us soon 🙂
In the meantime, you can try to search for similar issues in our issue database.

@Sese-Schneider
Copy link
Member

Thank you for your report @Patrick386

Can you please share your imports in main.dart file with us?
It looks like you're calling usePathUrlStrategy(); on mobile or you are not importing the package, but a specific file of our package.

@Sese-Schneider Sese-Schneider added help wanted Extra attention is needed invalid This doesn't seem right question Further information is requested labels Nov 6, 2023
@Patrick386
Copy link
Author

Thank you for your report @Patrick386

Can you please share your imports in main.dart file with us? It looks like you're calling usePathUrlStrategy(); on mobile or you are not importing the package, but a specific file of our package.

I created a small sample code and tested it. When using usePathUrlStrategy(), it works correctly without the need for 'if(kIsWeb)'

This is my mistake. I haven't been using the correct approach for Flutter multi-platform development. When running on mobile, I should have used it like this, but I didn't. I'll need to do more testing to see if there's another issue. Since all the code is already built for the web, I have to examine many screens. Thank you.

Ex:

import 'check_out_screen.dart'
  if(dart.library.html) 'check_out_screen_web.dart'; 
  if(dart.library.io) 'check_out_screen_mobile.dart'; 

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed invalid This doesn't seem right question Further information is requested
Development

No branches or pull requests

2 participants