carp_firebase_backend 0.0.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 34

CARP Firebase Data Backend #

This package supports uploading of data from the CARP Mobile Sensing Framework to a Google Firebase data backend. 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 carp_firebase_backend

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.

0.0.1 - Initial version, Oct. 2018. #

  • Initial version of dedicated package bringing together the old implementation.
  • Detailed documentation (see readme.md file)
  • Improved cooperation with FileDataManager

Use this package as a library

1. Depend on it

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


dependencies:
  carp_firebase_backend: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:carp_firebase_backend/carp_firebase_backend.dart';
  
Version Uploaded Documentation Archive
0.3.0 Jan 21, 2019 Go to the documentation of carp_firebase_backend 0.3.0 Download carp_firebase_backend 0.3.0 archive
0.2.0 Dec 5, 2018 Go to the documentation of carp_firebase_backend 0.2.0 Download carp_firebase_backend 0.2.0 archive
0.1.1 Nov 15, 2018 Go to the documentation of carp_firebase_backend 0.1.1 Download carp_firebase_backend 0.1.1 archive
0.1.0 Oct 21, 2018 Go to the documentation of carp_firebase_backend 0.1.0 Download carp_firebase_backend 0.1.0 archive
0.0.1 Oct 21, 2018 Go to the documentation of carp_firebase_backend 0.0.1 Download carp_firebase_backend 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
45
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
56
Overall:
Weighted score of the above. [more]
34
Learn more about scoring.

We analyzed this package on Feb 4, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.13
  • Flutter: 1.2.0

Platforms

Detected platforms:

Error(s) prevent platform classification:

Error(s) in lib/firebase/firebase_data_manager.dart: Classes can only extend other classes.

Health issues and suggestions

Fix lib/carp_firebase_backend.g.dart. (-95.78 points)

Analysis of lib/carp_firebase_backend.g.dart failed with 11 errors, including:

line 15 col 7: The setter '$' isn't defined for the class 'FirebaseStorageDataEndPoint'.

line 16 col 7: The setter 'bufferSize' isn't defined for the class 'FirebaseStorageDataEndPoint'.

line 17 col 7: The setter 'zip' isn't defined for the class 'FirebaseStorageDataEndPoint'.

line 18 col 7: The setter 'encrypt' isn't defined for the class 'FirebaseStorageDataEndPoint'.

line 19 col 7: The setter 'publicKey' isn't defined for the class 'FirebaseStorageDataEndPoint'.

Fix lib/firebase/firebase_data_manager.dart. (-94.54 points)

Analysis of lib/firebase/firebase_data_manager.dart failed with 10 errors, 6 hints, including:

line 19 col 42: Classes can only extend other classes.

line 19 col 42: Undefined class 'AbstractDataManager'.

line 36 col 21: Undefined class 'Study'.

line 37 col 11: The method 'initialize' isn't defined in a superclass of 'FirebaseStorageDataManager'.

line 122 col 29: Undefined class 'Datum'.

Fix lib/firebase/firebase_data_endpoint.dart. (-57.81 points)

Analysis of lib/firebase/firebase_data_endpoint.dart failed with 3 errors:

line 12 col 43: Classes can only extend other classes.

line 12 col 43: Undefined class 'FileDataEndPoint'.

line 72 col 14: Too many positional arguments: 0 expected, but 1 found.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Error(s) in lib/firebase/firebase_data_manager.dart: Classes can only extend other classes.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and carp_firebase_backend.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-4 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
carp_mobile_sensing ^0.2.1 0.2.6 0.3.1
firebase_auth ^0.5.20 0.5.20 0.8.0+1
firebase_storage ^1.0.2 1.1.0+1 2.0.0
flutter 0.0.0
google_sign_in ^3.0.5 3.3.0+1 4.0.0
json_annotation ^1.0.0 1.2.0 2.0.0
Transitive dependencies
activity_recognition 0.1.3
app_usage 0.0.2
archive 2.0.8
args 1.5.1
async 2.0.8
battery 0.2.3 0.3.0
call_log 1.0.6
carp_core 0.1.2
charcode 1.1.2
collection 1.14.11
connectivity 0.3.2 0.4.0+1
convert 2.1.1
crypto 2.0.6
device_apps 1.0.5
device_info 0.2.1 0.4.0
file_utils 0.1.1
firebase_core 0.2.5+1 0.3.0
fixnum 0.10.9
flutter_blue 0.4.2
flutter_sound 1.3.1
globbing 0.2.0
http 0.12.0+1
http_parser 3.1.3
light 0.0.4
location 1.4.1
meta 1.1.6 1.1.7
noise_meter 0.0.3
path 1.6.2
path_provider 0.4.1 0.5.0
pedometer 0.0.5
protobuf 0.10.8 0.13.1
screen_state 0.0.1
sensors 0.3.5 0.4.0
sky_engine 0.0.99
sms 0.2.4
source_span 1.5.4
stats 0.2.0+2
string_scanner 1.0.4
system_info 0.1.0
term_glyph 1.1.0
typed_data 1.1.6
uuid 1.0.3 2.0.0-rc1
vector_math 2.0.8
weather 0.1.03
Dev dependencies
build_runner any
flutter_test
json_serializable ^1.0.0