javascript - How to use Google Dart with Firebase Simple login (pass function inside function) -


has figured out how use firebase simple login google dart? trying figure out how define function(error, user){} when calling firebasesimplelogin. both error , user() objects.

this sample javascript code firebase

   var mydataref = new js.proxy(js.context.firebase, 'https://johnstest1.firebaseio.com/');     var mydataref = new firebase('https://johnstest1.firebaseio.com/');     var auth = new firebasesimplelogin(mydataref, function(error, user) {       if (error) {         // error occurred while attempting login         console.log(error);       } else if (user) {         // user authenticated firebase         console.log('user id: ' + user.id + ', provider: ' + user.provider);       } else {         // user logged out       }     }); 

this code added html file use both dart , firebase

    <script type='text/javascript' src='https://cdn.firebase.com/v0/firebase.js'></script>      <script type='text/javascript' src='https://cdn.firebase.com/v0/firebase-simple-login.js'></script>       <script type="application/dart" src="firebasetestlogin.dart"></script>     <script src="packages/browser/dart.js"></script>     <script src="packages/browser/interop.js"></script>     

in .dart file javascript library has been imported using pubspec.yaml

   import 'package:js/js.dart' js; 

in main() line of code works fine , able write data database. line commented out original javascript line while next line dart version , works.

    js.scoped((){         // var mydataref = new firebase('https://johnstest1.firebaseio.com');         var mydataref = new js.proxy(js.context.firebase, 'https://johnstest1.firebaseio.com/');       }); 

this same code main line firebase simple login added. have been trying figure out how write code function(error, user).

  js.scoped((){         // var mydataref = new firebase('https://johnstest1.firebaseio.com');         var mydataref = new js.proxy(js.context.firebase, 'https://johnstest1.firebaseio.com/');           //var auth = new firebasesimplelogin(js.context.firebase(mydataref, function(error, user){}{}));           var auth = new js.proxy(js.context.firebasesimplelogin(mydataref, js.context.function(error, user)));    }); 

when want use dart callback functions in js have create callback , use paramter.

the dart equivalent of first pasted js code :

var mydataref = new js.proxy(js.context.firebase,      'https://johnstest1.firebaseio.com/'); var auth = new js.proxy(js.context.firebasesimplelogin, mydataref,      new js.callback.many((error, user) {       if (error != null) {         // error occurred while attempting login         window.console.log(error);       } else if (user != null) {         // user authenticated firebase         window.console.log('user id: ${user.id}, provider: ${user.provider}');       } else {         // user logged out       }     })); 

note : can avoid js.scoped not needed since few versions of js package.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -