large Flutter Favorite logosmall Flutter Favorite logo

cloud_functions 0.9.1-1.0.nullsafety.1 icon indicating copy to clipboard operation
cloud_functions: ^0.9.1-1.0.nullsafety.1 copied to clipboard

A Flutter plugin allowing you to use Firebase Cloud Functions.


// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9

import 'dart:async';
import 'dart:core';

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

Future<void> main() async {
  await Firebase.initializeApp();
      .useFunctionsEmulator(origin: 'http://localhost:5001');

class MyApp extends StatefulWidget {
  MyApp({Key key}) : super(key: key);
  _MyAppState createState() => _MyAppState();

class _MyAppState extends State<MyApp> {
  List fruit = [];

  void initState() {

  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Firebase Functions Example'),
        body: Center(
            child: ListView.builder(
                itemCount: fruit.length,
                itemBuilder: (context, index) {
                  return ListTile(
                    title: Text('${fruit[index]}'),
        floatingActionButton: Builder(
          builder: (context) => FloatingActionButton.extended(
            onPressed: () async {
              // See index.js in the functions folder for the example function we
              // are using for this example
              HttpsCallable callable = FirebaseFunctions.instance.httpsCallable(
                  options: HttpsCallableOptions(
                      timeout: const Duration(seconds: 5)));

              await callable().then((v) {
                setState(() {
              }).catchError((e) {
                  content: Text('ERROR: $e'),
            label: const Text('Call Function'),
            icon: const Icon(,
            backgroundColor: Colors.deepOrange,