carp_firebase_backend 0.1.1 copy "carp_firebase_backend: ^0.1.1" to clipboard
carp_firebase_backend: ^0.1.1 copied to clipboard

outdated

Firebase data backend for CARP mobile sensing in Flutter. Supports uploading zipped json files to the Google Firebase Storage.

CARP Firebase Data Backend #

A Flutter plugin for uploading data from the CARP Mobile Sensing Framework to a Google Firebase data backend.

pub package

For Flutter plugins for other CARP products, see CARP Mobile Sensing in Flutter.

This package can upload files to a Goggle Firebase Storage (GFS) endpoint as raw or zipped JSON file, generated using the FileDataManager in carp_mobile_sensing. In GFS, sensing data is stored in the path specified in the FirebaseStorageDataEndPoint plus subfolders for each study and device. The path on GFS hence follow this pattern:

/<path>/<study_id>/<device_id>/

Setting up support for GFS #

For Firebase to work with your Flutter app, configuration of both GFS and the Flutter app has to be done. Please follow the step below in details, since the level of debugging/error messages are quite limited when setting this up. If you are new to Firebase, then please start by reading the extensive Firebase documentation first.

In GFS #

  1. Create a Firebase project with a cloud storage

  2. Add Firebase to your Flutter project by following the description. Note that you need to add support for both the Android and iOS version of the Flutter app.

  3. Download the configuration file named google-services.json and make sure to put in in your Android app module root directory, i.e a folder like <appname>/android/app/

  4. Add support for the Google Services Gradle plugin to read the google-services.json file that was generated by Firebase.

    • in your IDE, open android/app/build.gradle, and add the following line as the last line in the file:

    apply plugin: 'com.google.gms.google-services'

    • In android/build.gradle, inside the buildscript tag, add a new dependency:
    dependencies {
            // ...
            classpath 'com.google.gms:google-services:4.0.1'   // new
        }
    
  5. Configure authentication

  6. Add users that can upload data e.g. via the console

  7. Set up your storage security rules as shown below.

# Default access rule
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}
  • for testing/debugging purposes, you may remove authentication by the authentication rule below (but should be removed in production)
# No authentication rule
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

Your Flutter app should now be connected to Firebase.

In your Flutter App #

In Flutter, the carp_firebase_backend plugin is used to upload data from carp_mobile_sensing to a Firebase Storage endpoint.

Add the carp_firebase_backend plugin to the pubspec.yaml file.

dependencies:
  flutter:
    sdk: flutter
  carp_firebase_backend: ^0.0.1     # support for uploading CARP data to Firebase

Run flutter packages get. For more information on managing packages and plugins, see Using Packages.

Using the Plugin #

First you should register a FirebaseStorageDataManager in the DataManagerRegistry.

DataManagerRegistry.register(DataEndPointType.FIREBASE, new FirebaseStorageDataManager());

Then, you create a new FirebaseStorageDataEndPoint and add it as your Study data endpoint. FirebaseStorageDataEndPoint contains all the configuration needed to contact you GFS endpoint, as illustrated below. All of these configuration keys can be found in the Projects Settings in the Firebase Console. Remember to register your app in Firebase, as described above.

The firebaseAuthenticationMethod key specify the authentication method. Currently, only email/password and Google Sign-In is implemented (even though FireBaseAuthenticationMethods lists them all (for future use)).

Using email/password as authentication #

 final FirebaseStorageDataEndPoint firebaseEndPoint = new FirebaseStorageDataEndPoint(DataEndPointType.FIREBASE,
     name: "Flutter Sensing Sandbox",
     uri: 'gs://flutter-sensing-sandbox.appspot.com',
     path: 'sensing/data',
     projectID: 'flutter-sensing-sandbox',
     webAPIKey: 'AIzaSyCGy6MeHkiv5XkBtMcMbtgGYOpf6ntNVE4',
     gcmSenderID: '201621881872',
     androidGoogleAppID: '1:201621881872:android:8e84e7ccfc85e121',
     iOSGoogleAppID: '1:159623150305:ios:4a213ef3dbd8997b',
     firebaseAuthenticationMethod: FireBaseAuthenticationMethods.PASSWORD,
     email: "some_email@dtu.dk",
     password: "some_password");

 firebaseEndPoint.bufferSize = 1000 * 1000;
 firebaseEndPoint.zip = true;

 Study study = new Study("1234", "user@dtu.dk", name: "Test study #1");
 study.dataEndPoint = firebaseEndPoint;

Note that a FirebaseStorageDataEndPoint extends the FileDataEndPoint class and parameters related to how to create the files can be specified, including bufferSize, zip, and encrypt. In the example above, the file buffer size is set to 1 MB, which is zipped before upload.

Using Google Sign-In as authentication #

 final FirebaseStorageDataEndPoint firebaseEndPoint = new FirebaseStorageDataEndPoint(DataEndPointType.FIREBASE,
     name: "Flutter Sensing Sandbox",
     uri: 'gs://flutter-sensing-sandbox.appspot.com',
     path: 'sensing/data',
     projectID: 'flutter-sensing-sandbox',
     webAPIKey: 'AIzaSyCGy6MeHkiv5XkBtMcMbtgGYOpf6ntNVE4',
     gcmSenderID: '201621881872',
     androidGoogleAppID: '1:201621881872:android:8e84e7ccfc85e121',
     iOSGoogleAppID: '1:159623150305:ios:4a213ef3dbd8997b',
     firebaseAuthenticationMethod: FireBaseAuthenticationMethods.GOOGLE);

 Study study = new Study("1234", "user@dtu.dk", name: "Test study #1");
 study.dataEndPoint = firebaseEndPoint;

Features and bugs #

Please file feature requests and bug reports at the issue tracker.

License #

This software is copyright (c) 2018 Copenhagen Center for Health Technology (CACHET) at the Technical University of Denmark (DTU). This software is made available 'as-is' in a MIT license.

4
likes
0
pub points
29%
popularity

Publisher

verified publishercachet.dk

Firebase data backend for CARP mobile sensing in Flutter. Supports uploading zipped json files to the Google Firebase Storage.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

carp_core, carp_mobile_sensing, firebase_auth, firebase_storage, flutter, google_sign_in, json_annotation

More

Packages that depend on carp_firebase_backend