Expose Dart functions to javascript

后端 未结 3 1047
独厮守ぢ
独厮守ぢ 2020-12-05 15:32

I\'m a bit of a newb to dart, and trying to get my feet wet by writing some library functions in it.

While I\'ve had no problem calling javascript functions from da

相关标签:
3条回答
  • 2020-12-05 16:08

    No problem ! see Calling Dart from JavaScript.

    In your case :

    import 'dart:js' as js;
    main() {
      String foo() {
        return "bar!";
      }
    
      js.context['foo'] = foo;
    }
    
    0 讨论(0)
  • 2020-12-05 16:12

    In Dart 2.3.0 I had to tweak the solution just a bit for allowInterop to play nice.

    
        import 'dart:js' as js;
        main() {
          String foo() {
            return "bar!";
          }
    
          js.context['foo'] = js.allowInterop(foo);
        }
    
    
    0 讨论(0)
  • 2020-12-05 16:23

    In Dart 1.20 I had to add allowInterop()

    import 'dart:js' as js;
    main() {
      String foo() {
        return "bar!";
      }
    
      js.context['foo'] = allowInterop(foo);
    }
    
    0 讨论(0)
提交回复
热议问题