meteorify 1.0.7 copy "meteorify: ^1.0.7" to clipboard
meteorify: ^1.0.7 copied to clipboard

A dart package to interact with Meteor. Connect your web or flutter apps, written in Dart, with the Meteor framework.

Meteorify #

Pub

A Dart 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
  • Call custom Methods on Meteor
  • Access underlying databases

Dependency #

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

dependencies:
  meteorify: ^1.0.7
copied to clipboard

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
      });
}
copied to clipboard

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
  }
}
copied to clipboard

Check connection status

var isConnected = Meteor.isConnected;		
copied to clipboard

Disconnect from server

Meteor.disconnect();
copied to clipboard

Listen for connection updates

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

Subscriptions #

Subscribe to Data

var subscriptionId = await Meteor.subscribe(subscriptionName);
copied to clipboard

Subscriptions with Parameters

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

Unsubscribe from Data

await Meteor.unsubscribe(subscriptionId);
copied to clipboard

Get subscribed data/collection

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

Authentication #

Creating New Account

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

Login

  1. Login with password

    String loginToken = await Meteor.loginWithPassword(emailOrUsername,password);
    
    copied to clipboard
  2. Login with token

    String token = await Meteor.loginWithToken(loginToken);
    
    copied to clipboard
  3. Change Password (need to be logged in)

    String result = await Accounts.changePassword(oldPassword,newPassword);
    
    copied to clipboard
  4. Forgot Password

    String result = await Accounts.forgotPassword(email);
    
    copied to clipboard
  5. Reset Password

    String result = await Accounts.resetPassword(resetToken,newPassword);
    
    copied to clipboard
  6. Logout

    await Meteor.logout();
    
    copied to clipboard
  7. Get logged in userId

    String userId = Meteor.currentUserId;
    
    copied to clipboard
  8. Check if logged in

    bool isLoggedIn = Meteor.isLoggedIn();
    
    copied to clipboard
  9. Get current user as map

    Map<String,dynamic> currentUser = await Meteor.userAsMap();
    
    copied to clipboard

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;
  },
});
copied to clipboard

Invoking custom methods

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

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();
copied to clipboard

Get custom database

import 'package:mongo_dart/mongo_dart.dart';

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

Get collection

import 'package:mongo_dart/mongo_dart.dart';

DbCollection collection = await db.collection('collectionName');
copied to clipboard
6
likes
40
points
48
downloads

Publisher

verified publishershivamarora.dev

Weekly Downloads

2024.09.22 - 2025.04.06

A dart package to interact with Meteor. Connect your web or flutter apps, written in Dart, with the Meteor framework.

Repository (GitHub)

License

BSD-2-Clause (license)

Dependencies

ddp, mongo_dart

More

Packages that depend on meteorify