cloud_functions 0.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 90

Cloud Functions Plugin for Flutter

A Flutter plugin to use the Cloud Functions for Firebase API

pub package

For Flutter plugins for other Firebase products, see FlutterFire.md.

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

Setup

To use this plugin:

  1. Using the Firebase Console, add an Android app to your project: Follow the assistant, download the generated google-services.json file and place it inside android/app. Next, modify the android/build.gradle file and the android/app/build.gradle file to add the Google services plugin as described by the Firebase assistant. Ensure that your android/build.gradle file contains the maven.google.com as described here.
  2. Using the Firebase Console, add an iOS app to your project: Follow the assistant, download the generated GoogleService-Info.plist file, open ios/Runner.xcworkspace with Xcode, and within Xcode place the file inside ios/Runner. Don't follow the steps named "Add Firebase SDK" and "Add initialization code" in the Firebase assistant.
  3. Add cloud_functions as a dependency in your pubspec.yaml file.

Usage

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

Calling a function:

dynamic resp = await FirebaseFunctions.instance.call(functionName: 'YOUR_CALLABLE_FUNCTION_NAME');

Getting Started

See the example directory for a complete sample app using Cloud Functions for Firebase.

0.0.1

  • The Cloud Functions for Firebase client SDKs let you call functions directly from a Firebase app. This plugin exposes this ability to Flutter apps.

    Callable functions are similar to other HTTP functions, with these additional features:

    • With callables, Firebase Authentication and FCM tokens are automatically included in requests.
    • The functions.https.onCall trigger automatically deserializes the request body and validates auth tokens.

example/lib/main.dart

// Copyright 2018, the Chromium project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:cloud_functions/cloud_functions.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _response = 'no response';
  int _responseCount = 0;

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Cloud Functions example app'),
        ),
        body: new Center(
          child: new Container(
            margin: const EdgeInsets.only(top: 32.0, left: 16.0, right: 16.0),
            child: new Column(
              children: <Widget>[
                new Text('Response $_responseCount: $_response'),
                new MaterialButton(
                  child: const Text('SEND REQUEST'),
                  onPressed: () async {
                    try {
                      final dynamic resp = await CloudFunctions.instance.call(
                        functionName: 'repeat',
                        parameters: <String, dynamic>{
                          'message': 'hello world!',
                          'count': _responseCount,
                        },
                      );
                      print(resp);
                      setState(() {
                        _response = resp['repeat_message'];
                        _responseCount = resp['repeat_count'];
                      });
                    } on CloudFunctionsException catch (e) {
                      print('caught firebase functions exception');
                      print(e.code);
                      print(e.message);
                      print(e.details);
                    } catch (e) {
                      print('caught generic exception');
                      print(e);
                    }
                  },
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  cloud_functions: ^0.0.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support 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:cloud_functions/cloud_functions.dart';
  
Version Uploaded Documentation Archive
0.0.4+1 Oct 12, 2018 Go to the documentation of cloud_functions 0.0.4+1 Download cloud_functions 0.0.4+1 archive
0.0.4 Aug 31, 2018 Go to the documentation of cloud_functions 0.0.4 Download cloud_functions 0.0.4 archive
0.0.2 Jul 23, 2018 Go to the documentation of cloud_functions 0.0.2 Download cloud_functions 0.0.2 archive
0.0.1 Jun 22, 2018 Go to the documentation of cloud_functions 0.0.1 Download cloud_functions 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
92
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

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

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
firebase_core ^0.2.2 0.2.5+1
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test