How to make my main Dart app object accessible from browser console?

Issue

I want to debug my app in Dartium, call its methods, like APP.getUserState() from browser console.

With JavaScript I would just make APP global this way window.APP = myAPP.

How do I achieve the same effect with Dart app?

Solution

web/index.dart

class X {
  static void p() => print('xxx');
  static void q(String a) => print(a);
}

void main() {
  // your application code
}

Ensure the context is set to Dart and start using Dart classes:

enter image description here

Answered By – Günter Zöchbauer

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.