use Jquery UI in Dart

前端 未结 3 1903
醉梦人生
醉梦人生 2021-02-06 19:21

I\'m trying to create a simple dialog in Dart and I thought it was easier to use existing javascript libraries. Here you can find the basic example, basically

$(         


        
相关标签:
3条回答
  • 2021-02-06 19:28

    try:

    context.callMethod(r'$', ['#dialog'])
           .callMethod('dialog', []);    
    
    0 讨论(0)
  • 2021-02-06 19:36

    Basically, there are 2 libraries to interop with js : dart:js and package:js. dart:js has been created after package:js and most of the stackoverflow answers use package:js and are still valid (it isn't worth to downvote these answers...)

    package:js provides a simpler Api that comes at the cost of an increase of the js size (because package:js uses dart:mirrors and noSuchMethod).

    With package:js :

    import 'package:js/js.dart' as js;
    
    main() {
      js.context.$("#dialog").dialog();
    }
    

    With dart:js :

    import 'dart:js' as js;
    
    main() {
      js.context.callMethod(r'$', ['#dialog']).callMethod('dialog');
    }
    
    0 讨论(0)
  • 2021-02-06 19:47

    You can need just to be notified on callback. There is quick fix:

    class CallbackFunction implements Function {
      final Function f;
      CallbackFunction(this.f);
      call() => throw new StateError('There should always been at least 1 parameter'
      '(js this).');
      noSuchMethod(Invocation invocation) {
        Function.apply(f, []);
      }
    }
    
    .callMethod("spinner", [new js.JsObject.jsify({
        "stop": new js.JsFunction.withThis(new CallbackFunction(recalc),
        "page": 1,
        "step": 0.1
        })])
    
    void recalc(){
       print("recalcing");
    }
    

    You can parse invocation argument to read javascript callback arguments. Source: 'package:js/js.dart':line 238 (may change)

    0 讨论(0)
提交回复
热议问题