skip to Main Content

I have developed app which works on both Web and Android.
I have used ‘dart:html’ library to check app is resumed or pause.

But when I compiling app for android its giving error.

lib/controller/home_controller.dart:2
import 'dart:html';
       ^

Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:dart%3Ahtml; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:34:7)

I need dart:html library to check app is resumed or paused.
My code :

  @override
  onInit() {
    super.onInit();

    if (isWebApp()) {
      window.addEventListener('focus', onFocus);
      window.addEventListener('blur', onBlur);
    } else {
      WidgetsBinding.instance.addObserver(this);
    }
  }

  void onFocus(Event e) {
    didChangeAppLifecycleState(AppLifecycleState.resumed);
  }

  void onBlur(Event e) {
    didChangeAppLifecycleState(AppLifecycleState.paused);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    printWithDateTime("111111");
    if (state == AppLifecycleState.resumed) {
      getEmployee();
      homeDashboard();
    }
  }

2

Answers


  1. Try adding to the import the following

    import 'dart:html' as html;
    

    Then any method used from the html package call it using html.Method()

    Login or Signup to reply.
  2. dart:html can only be imported for web applications. I suggest to use universal_html in your project instead. It’s a package that still uses dart:html under the hood when using web, but allows you to import it in other platforms as well

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search