cloud_functions 0.4.2+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 95

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 README.md.

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 #

import 'package:cloud_functions/cloud_functions.dart';

Getting an instance of the callable function:

final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
    functionName: 'YOUR_CALLABLE_FUNCTION_NAME',
);

Calling the function:

dynamic resp = await callable.call();

Calling the function with parameters:

dynamic resp = await callable.call(<String, dynamic>{
    'YOUR_PARAMETER_NAME': 'YOUR_PARAMETER_VALUE',
});

Getting Started #

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

Issues and feedback #

Please file Flutterfire specific issues, bugs, or feature requests in our issue tracker.

Plugin issues that are not specific to Flutterfire can be filed in the Flutter issue tracker.

To contribute a change to this plugin, please review our contribution guide, and send a pull request.

0.4.2+3 #

  • Fix for missing UserAgent.h compilation failures.

0.4.2+2 #

  • Fix method channel on darwin

0.4.2+1 #

  • Make the pedantic dev_dependency explicit.

0.4.2 #

  • Add macOS support

0.4.1+9 #

  • Depends on cloud_functions_web so that projects importing this plugin will get web support.
  • Added web implementation to the example application.

0.4.1+8 #

  • Fixes the No implementation found for method CloudFunctions#call

0.4.1+7 #

  • Update to use the platform interface to execute calls.
  • Fix timeout for Android (which had been ignoring explicit timeouts due to unit mismatch).
  • Update repository location based on platform interface refactoring.

0.4.1+6 #

  • Fix analysis failures

0.4.1+5 #

  • Remove the deprecated author: field from pubspec.yaml
  • Migrate the plugin to the pubspec platforms manifest.
  • Bump the minimum Flutter version to 1.10.0.

0.4.1+4 #

  • Updated README instructions for contributing for consistency with other Flutterfire plugins.

0.4.1+3 #

  • Remove AndroidX warning.

0.4.1+2 #

  • Update Android package name.

0.4.1+1 #

  • Update documentation to reflect new repository location.
  • Update unit tests to call TestWidgetsFlutterBinding.ensureInitialized.

0.4.1 #

  • Support for cloud functions emulators.

0.4.0+3 #

  • Update google-services Android gradle plugin to 4.3.0 in documentation and examples.

0.4.0+2 #

  • Automatically use version from pubspec.yaml when reporting usage to Firebase.

0.4.0+1 #

  • Remove reference to unused header file.

0.4.0 #

  • Removed unused parameters param from getHttpsCallable.

0.3.0+1 #

  • Update iOS dependencies to latest.

0.3.0 #

  • Update Android dependencies to latest.

0.2.0+1 #

  • Removed flaky timeout test.

0.2.0 #

  • Breaking change. Updated Dart API to replace call with getHttpsCallable.
  • Added support for timeouts.
  • Additional integration testing.

0.1.2+1 #

  • Added a driver test.

0.1.2 #

  • Specifying a version for Cloud Functions CocoaPod dependency to prevent build errors on iOS.
  • Fix on iOS when using a null region.
  • Upgrade the firebase_core dependency of the example app.

0.1.1+1 #

  • Log messages about automatic configuration of the default app are now less confusing.

0.1.1 #

  • Support for regions and multiple apps

0.1.0+1 #

  • Log a more detailed warning at build time about the previous AndroidX migration.

0.1.0 #

  • Breaking change. Migrate from the deprecated original Android Support Library to AndroidX. This shouldn't result in any functional changes, but it requires any Android apps using this plugin to also migrate if they're using the original support library.

0.0.5 #

  • Set iOS deployment target to 8.0 (minimum supported by both Firebase SDKs and Flutter), fixes compilation errors.
  • Fixes null pointer error when callable function fails with exception (iOS).

0.0.4+1 #

  • Bump Android dependencies to latest.

0.0.4 #

  • Fixed podspec to use static_framework

0.0.3 #

  • Added missing dependency on meta package.

0.0.2 #

  • Bump Android and Firebase dependency versions.

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(MyApp());

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

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

  @override
  Widget build(BuildContext context) {
    final HttpsCallable callable = CloudFunctions.instance
        .getHttpsCallable(functionName: 'repeat')
          ..timeout = const Duration(seconds: 30);
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Cloud Functions example app'),
        ),
        body: Center(
          child: Container(
            margin: const EdgeInsets.only(top: 32.0, left: 16.0, right: 16.0),
            child: Column(
              children: <Widget>[
                Text('Response $_responseCount: $_response'),
                MaterialButton(
                  child: const Text('SEND REQUEST'),
                  onPressed: () async {
                    try {
                      final HttpsCallableResult result = await callable.call(
                        <String, dynamic>{
                          'message': 'hello world!',
                          'count': _responseCount,
                        },
                      );
                      print(result.data);
                      setState(() {
                        _response = result.data['repeat_message'];
                        _responseCount = result.data['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.4.2+3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:cloud_functions/cloud_functions.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
97
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
95
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Maintenance suggestions

The package description is too short. (-20 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.28.0 <3.0.0
cloud_functions_platform_interface ^1.0.0 1.0.0
cloud_functions_web ^1.0.2 1.0.3
firebase_core ^0.4.4 0.4.4+3
flutter 0.0.0
meta ^1.1.6 1.1.8
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
firebase 7.2.1
firebase_core_platform_interface 1.0.4
firebase_core_web 0.1.1+2
flutter_web_plugins 0.0.0
http 0.12.0+4
http_parser 3.1.4
js 0.6.1+1
matcher 0.12.6
path 1.6.4
plugin_platform_interface 1.0.2
quiver 2.1.3
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_driver
flutter_test
pedantic ^1.8.0 1.9.0
test any