enhanced_meteorify 1.0.12

  • Readme
  • Changelog
  • Example
  • Installing
  • 78

Enhanced Meteorify #

Carefully extended meteorify package to interact with the Meteor framework.

Connect your web or flutter apps, written in Dart, to the Meteor framework.

Features #

  • Connect to Meteor server
  • Use Meteor Subscriptions
  • Meteor Authentication
  • oAuth Authentication with Google, Facebook and Apple* (needs server-side code in JavaScript for use with Meteor)
  • Call custom Methods on Meteor
  • Access underlying databases

*Login with Apple currently only supports iOS 13+.

Dependency #

Add this to your package's pubspec.yaml file:

dependencies:
  enhanced_meteorify: ^1.0.10

Usage #

Capturing the result of operations #

You can use either the then-catchError or await syntax to capture the result of operations and handle errors.

I'll be using the await syntax in this documentation to keep it short and straight. You can use either catchError on Future object or try/catch syntax to catch errors.

Connection Operations #

Connecting with Meteor

Using then-catchError:

import 'package:meteorify/meteorify.dart';

main() async{
  Meteor.connect('ws://example.meteor.com/websocket')
      .then((status){
          // Do something after connection is successful
      })
      .catchError((error){
          print(error);
          //Handle error
      });
}

Using await:

import 'package:meteorify/meteorify.dart';

main() async{
  try{
      var status = await Meteor.connect('ws://example.meteor.com/websocket');
      // Do something after connection is successful
  }catch(error){
      print(error);
      //Handle error
  }
}

Check connection status

var isConnected = Meteor.isConnected;		

Disconnect from server

Meteor.disconnect();

Listen for connection updates

Meteor.connectionListener = (ConnectionStatus connectionStatus){
  print(connectionStatus);
}

Subscriptions #

Subscribe to Data

var subscriptionId = await Meteor.subscribe(subscriptionName);

Subscriptions with Parameters

var subscriptionId = await Meteor.subscribe(subscriptionName,args:[arg1,arg2]);

Unsubscribe from Data

await Meteor.unsubscribe(subscriptionId);

Get subscribed data/collection

SubscribedCollection collection = await Meteor.collection(collectionName);
//collection.find({selectors});
//collection.findAll();
//collection.findOne(id);

Authentication #

Creating New Account

var userId = await Accounts.createUser(username, email, password, profileOptions);

Login

  1. Login with password

    // Login with email
    String loginToken = await Meteor.loginWithPassword(email, password);
    
    // Login with username
    String loginToken = await Meteor.loginWithPassword(username, password);
    
  2. Login with token

    String token = await Meteor.loginWithToken(loginToken);
    
  3. Login with Google

    // `email` to register with. Must be fetched from the Google oAuth API
    // The unique Google `userId`. Must be fetched from the Google oAuth API
    // `authHeaders` from Google oAuth API for server side validation
    String token = await Meteor.loginWithGoogle(email, userId, authHeaders)
    

    Install google_sing_in package

    dependencies:
       flutter:
          sdk: flutter
    
       google_sign_in: ^4.4.4
    
    import 'package:google_sign_in/google_sign_in.dart';
    
    GoogleSignIn _googleSignIn = GoogleSignIn(
     scopes: ['profile', 'email', 'openid'],
    );
    
    Future<void> _loginWithGoogle(context) async {
     try {
       var info = await _googleSignIn.signIn();
       var authHeaders = await info.authHeaders;
       var result = await Meteor.loginWithGoogle(info.email, info.id, authHeaders);
    
       print(result);
     } catch (error) {
       print(error);
     }
    }
    
  4. Login with Facebook

    // [userId] the unique Facebook userId. Must be fetched from the Facebook Login API
    // [token] the token from Facebook API Login for server side validation
    String token = await Meteor.loginWithFacebook(userId, token)
    

    Install flutter_facebook_login package

    dependencies:
       flutter:
          sdk: flutter
    
       flutter_facebook_login: ^3.0.0
    
    import 'package:flutter_facebook_login/flutter_facebook_login.dart';
    
    Future<void> _loginWithFacebook(context) async {
       final result = await facebookLogin.logIn(['email, public_profile']);
    
       switch (result.status) {
       case FacebookLoginStatus.loggedIn:
          var userId = result.accessToken.userId;
          var token = result.accessToken.userId;
          var res = await Meteor.loginWithFacebook(userId, token);
    
          print(res);
          break;
       case FacebookLoginStatus.cancelledByUser:
          print(':/');
          break;
       case FacebookLoginStatus.error:
          print('error: ${result.errorMessage}');
          break;
       }
    }
    
  5. Login with Apple

    // [userId] the unique Apple userId. Must be fetch from the Apple Login API
    // [jwt] the jwt from Apple API Login to get user's e-mail
    // [givenName] user's given Name. Must be fetched from the Apple Login API
    // [lastName] user's last Name. Must be fetched from the Apple Login API
    String token = await Meteor.loginWithApple(userId, jwt, givenName, lastName)
    

Install apple_sign_in package

   dependencies:
      flutter:
         sdk: flutter
      
      apple_sign_in: ^0.1.0
   import 'package:apple_sign_in/apple_sign_in.dart';

   Future<void> _loginWithApple(context) async {
    try {
      final AuthorizationResult result = await AppleSignIn.performRequests([
        AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
      ]);

      switch (result.status) {
        case AuthorizationStatus.authorized:
          var userId = result.credential.user;
          var jwt = result.credential.identityToken;
          var givenName = result.credential.fullName.givenName;
          var lastName = result.credential.fullName.familyName;

          var res = await Meteor.loginWithApple(userId, jwt, givenName, lastName);
         
          print(res);
          break;
        case AuthorizationStatus.error:
          print('Erro: ${result.error.localizedDescription}');
          break;
        case AuthorizationStatus.cancelled:
          print(':/');
          break;
      }
    } catch (error) {
      print(error);
    }
  }
  1. Change Password (need to be logged in)

    String result = await Accounts.changePassword(oldPassword, newPassword);
    
  2. Forgot Password

    String result = await Accounts.forgotPassword(email);
    
  3. Reset Password

    String result = await Accounts.resetPassword(resetToken, newPassword);
    
  4. Logout

   await Meteor.logout();
  1. Get logged in userId
   String userId = Meteor.currentUserId;
  1. Check if logged in
   bool isLoggedIn = Meteor.isLoggedIn();
  1. Get current user as map
   Map<String,dynamic> currentUser = await Meteor.userAsMap();

Call Custom Methods #

Defining custom methods in meteor server

export const helloWorld = new ValidatedMethod({
  name: 'hello',
  validate: new SimpleSchema({
    firstname: {type: String},
    lastname: {type: String},
  }).validator(),
  run({ firstname,lastname }) {
    const message = "hello "+ firstname + " " + lastname;
    console.log(message);
    return message;
  },
});

Invoking custom methods

try{
  var result = await Meteor.call('hello',[{'firstname':'Shivam','lastname':'Arora'}]);
  print(result);
}catch(error){
  print(error);
}

Using Mongo Databases to manage data #

Meteorify uses the mongo_dart package internally to provide access to actual database.

For more instructions regarding use of mongo_dart , visit their mongo_dart guide.

Get Meteor Database

import 'package:mongo_dart/mongo_dart.dart';

Db db = await Meteor.getMeteorDatabase();

Get custom database

import 'package:mongo_dart/mongo_dart.dart';

Db db = await Meteor.getCustomDatabase(dbUrl);
await db.open();

Get collection

import 'package:mongo_dart/mongo_dart.dart';

DbCollection collection = await db.collection('collectionName');

1.0.12 #

  • Update enhanced_ddp package

1.0.11 #

  • Update enhanced_ddp package
  • Add SubscribedCollection.removeUpdateListener

1.0.10 #

  • Update enhanced_ddp package

1.0.9 #

  • Sending encrypted password over the ddp

1.0.8 #

  • Save loginToken on shared preferences
  • Auto reconnect on connection lost (enhanced_ddp)

1.0.7 #

  • Update enhanced_ddp package

1.0.6 #

  • Update enhanced_ddp package

1.0.5 #

  • Remove DDP package
  • Add Enhanced_DDP package

1.0.4 #

  • Update README
  • Authentication with Apple* (needs sever-side code in JavaScript for use with Meteor)

*Login with Apple currently only supports iOS 13+.

1.0.3 #

  • Update README
  • Authentication with Facebook (needs sever-side code in JavaScript for use with Meteor)

1.0.2 #

  • 🚀

1.0.1 #

  • Connect and login with loginWithPassword example

1.0.0 #

  • Initial version
  • Features
    • Connect to Meteor server
    • Use Meteor Subscriptions
    • Meteor Authentication
    • Authentication with Google oAuth (needs server-side code in JavaScript for use with Meteor)
    • Call Custom Methods on Meteor
    • Access underlying databases

example/enhanced_meteorify.dart

import 'package:enhanced_meteorify/enhanced_meteorify.dart';

void main() async {
  try {
    await Meteor.connect('ws://127.0.0.1:3000/websocket');
    if (Meteor.isConnected) {
      var result =
          await Meteor.loginWithPassword('Freeman', 'RiseAndShineMrFreeman');
      print(result);
    }
  } catch (error) {
    print(error);
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  enhanced_meteorify: ^1.0.12

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:enhanced_meteorify/enhanced_meteorify.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Analysis suggestions

Package does not support Flutter platform android

Because:

  • package:enhanced_meteorify/enhanced_meteorify.dart that imports:
  • package:enhanced_meteorify/src/meteor/meteor.dart that imports:
  • package:enhanced_meteorify/src/utils/utils.dart that imports:
  • package:shared_preferences/shared_preferences.dart that imports:
  • package:shared_preferences_linux/shared_preferences_linux.dart that declares support for platforms: linux

Package does not support Flutter platform ios

Because:

  • package:enhanced_meteorify/enhanced_meteorify.dart that imports:
  • package:enhanced_meteorify/src/meteor/meteor.dart that imports:
  • package:enhanced_meteorify/src/utils/utils.dart that imports:
  • package:shared_preferences/shared_preferences.dart that imports:
  • package:shared_preferences_linux/shared_preferences_linux.dart that declares support for platforms: linux

Package does not support Flutter platform macos

Because:

  • package:enhanced_meteorify/enhanced_meteorify.dart that imports:
  • package:enhanced_meteorify/src/meteor/meteor.dart that imports:
  • package:enhanced_meteorify/src/utils/utils.dart that imports:
  • package:shared_preferences/shared_preferences.dart that imports:
  • package:shared_preferences_linux/shared_preferences_linux.dart that declares support for platforms: linux

Package does not support Flutter platform web

Because:

  • package:enhanced_meteorify/enhanced_meteorify.dart that imports:
  • package:enhanced_meteorify/src/meteor/meteor.dart that imports:
  • package:enhanced_meteorify/src/utils/utils.dart that imports:
  • package:shared_preferences/shared_preferences.dart that imports:
  • package:shared_preferences_linux/shared_preferences_linux.dart that declares support for platforms: linux

Package does not support Flutter platform windows

Because:

  • package:enhanced_meteorify/enhanced_meteorify.dart that imports:
  • package:enhanced_meteorify/src/meteor/meteor.dart that imports:
  • package:enhanced_meteorify/src/utils/utils.dart that imports:
  • package:shared_preferences/shared_preferences.dart that declares support for platforms: android, ios, linux, macos, web

Package not compatible with SDK dart

Because:

  • enhanced_meteorify that depends on:
  • shared_preferences that is a package requiring null.

Health suggestions

Format lib/enhanced_meteorify.dart.

Run dartfmt to format lib/enhanced_meteorify.dart.

Format lib/src/meteor/meteor.dart.

Run dartfmt to format lib/src/meteor/meteor.dart.

Format lib/src/meteor/subscribed_collection.dart.

Run dartfmt to format lib/src/meteor/subscribed_collection.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
crypto ^2.1.5 2.1.5
enhanced_ddp ^1.0.9 1.0.9
mongo_dart ^0.4.0 0.4.0
shared_preferences ^0.5.7+3 0.5.8
Transitive dependencies
async 2.4.2
bson 0.3.2
charcode 1.1.3
collection 1.14.12 1.14.13
convert 2.1.1
file 5.2.1
fixnum 0.10.11
flutter 0.0.0
flutter_web_plugins 0.0.0
intl 0.16.1
logging 0.11.4
matcher 0.12.8
meta 1.1.8 1.2.2
mongo_dart_query 0.4.1
more 1.18.2 2.5.0
path 1.7.0
path_provider_linux 0.0.1+2
path_provider_platform_interface 1.0.2
platform 2.2.1
plugin_platform_interface 1.0.2
pool 1.4.0
process 3.0.13
quiver 2.1.3
shared_preferences_linux 0.0.2+1
shared_preferences_macos 0.0.1+10
shared_preferences_platform_interface 1.0.4
shared_preferences_web 0.1.2+7
sky_engine 0.0.99
stack_trace 1.9.5
stream_channel 2.0.0
tuple 1.0.3
typed_data 1.1.6 1.2.0
uuid 2.2.0
vector_math 2.0.8 2.1.0-nullsafety
web_socket_channel 1.1.0
xdg_directories 0.1.0
Dev dependencies
pedantic ^1.0.0
test ^1.0.0