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

PlatformLinux

The cloud_functions implementation for desktop Linux, backed by the Firebase C++ SDK through firebase_ffi. Registers itself, so apps use cloud_functions unchanged.

example/lib/main.dart

// SPDX-FileCopyrightText: 2026 Joel Winarske
// SPDX-License-Identifier: Apache-2.0

// Calls a callable named echo.
//
// The only lines specific to Linux are the registerWith calls below. Every
// other line is ordinary cloud_functions and would compile unchanged on Android.

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

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // On Linux nothing registers these automatically yet, so an app says so
  // once at startup. Elsewhere the plugin registers itself and these are not
  // called.
  FirebaseCoreFfi.registerWith();
  CloudFunctionsFfi.registerWith();

  await Firebase.initializeApp(
    // Replace with your project's values, or generate them with the FlutterFire
    // CLI. The C++ SDK reads them from here rather than from a plist.
    options: const FirebaseOptions(
      apiKey: 'replace-me',
      appId: '1:1:android:1',
      messagingSenderId: '1',
      projectId: 'replace-me',
    ),
  );

  runApp(const _ExampleApp());
}

class _ExampleApp extends StatefulWidget {
  const _ExampleApp();

  @override
  State<_ExampleApp> createState() => _ExampleAppState();
}

class _ExampleAppState extends State<_ExampleApp> {
  String _status = 'press the button';

  Future<void> _run() async {
    setState(() => _status = 'working...');
    try {
      final message = await _work();
      setState(() => _status = message);
    } on Object catch (e) {
      // Shown rather than swallowed: a binding that cannot reach the SDK
      // fails here, and the reason is the useful part.
      setState(() => _status = 'failed: $e');
    }
  }

  Future<String> _work() async {
    final result = await FirebaseFunctions.instance.httpsCallable('echo').call({
      'hi': 1,
    });
    return 'callable answered ${result.data}';
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('cloud_functions on Linux')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Padding(
                padding: const EdgeInsets.all(24),
                child: Text(_status, textAlign: TextAlign.center),
              ),
              FilledButton(onPressed: _run, child: const Text('Run')),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
160
points
149
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

The cloud_functions implementation for desktop Linux, backed by the Firebase C++ SDK through firebase_ffi. Registers itself, so apps use cloud_functions unchanged.

Repository (GitHub)
View/report issues

License

Apache-2.0 (license)

Dependencies

cloud_functions_platform_interface, firebase_core, firebase_ffi, flutter

More

Packages that depend on cloud_functions_ffi

Packages that implement cloud_functions_ffi