1

I am creating my first Flutter app for web. I need using Chrome api. For example I need to use it:

chrome.runtime.onInstalled.addListener

   or

   chrome.tabs...

but unfortunately I did not find any information about it.

Is it possible?

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
FetFrumos
  • 5,388
  • 8
  • 60
  • 98

1 Answers1

3

Yes, the chrome.* APIs are JavaScript just like all the other web APIs, so you can use Dart's JS support.

That means using Dart's js library.

For example, you could bind a function something like this (untested, without any type annotation, just an example)

@JS('chrome.runtime.onInstalled.addListener')
external void addInstalledListener(Function callback);

Edit: If you'd rather pull in a dependency than roll your own, you can use something like chrome.dart.

import 'package:chrome/chrome_app.dart' as chrome;

void main() {
  chrome.runtime.getPlatformInfo().then((Map m) {
    print(m.toString());
  });
}
AlexApps99
  • 3,506
  • 9
  • 21