Search code examples
androidflutterweb

import dart:html Error while compiling android app


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();
    }
  }

Solution

  • 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