0

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();
    }
  }
Honey Last
  • 255
  • 1
  • 3
  • 15
  • 1
    You need to import a package based on the platform app will be running on, please refer to this answer https://stackoverflow.com/a/58713064/4224426 – Antonio Valentic Dec 20 '22 at 09:45

2 Answers2

1

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

Ivo
  • 18,659
  • 2
  • 23
  • 35
0

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

lou_codes
  • 101
  • 7