D. Go.
D. Go.

Reputation: 407

How can we use Firebase database with desktop application in Flutter?

I was thinking of developing a desktop application with Dart and Flutter, but I don't know how can I integrate a Firebase database with it.

Upvotes: 25

Views: 30458

Answers (5)

Khurram
Khurram

Reputation: 311

I connect Firebase with my windows flutter app using http method; code and snapshot are below. Firebase real time database work perfectly. i follow this tutorial https://medium.com/flutterdevs/http-request-dcc13e885985

my code is:

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}



class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
    sendData();
  }

  sendData() {
    http.post(
        Uri.parse(
            "https://rest-12bb2-default-rtdb.firebaseio.com/userprofile.json"),
        body: json.encode({
          'firstName': "b",
          'lastName': "c",
          'email': "f",
        }));
    // setState(() {
    //   userProfile.add(Profile(
    //     firstName: firstname;
    //     lastName: lastname;
    //     email: email;
    //   ));
    // });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("app"),
      ),
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text(
              'You have pushed the button this many times:',
            ),
            new Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ),
    );
  }
}

///////////// firebase snapshotenter image description here

Upvotes: 3

Fathah Cr
Fathah Cr

Reputation: 501

Use Firedart package to integrate FIrebase to Desktop-based Flutter apps.

https://pub.dev/packages/firedart

Documentation Says

This library attempts to minimize dependencies with the intention of making it able to run in any environment capable of executing dart code. Currently it has been successfully tested using the dart runtime (x86-64 and arm32) as well as on Flutter Android, iOS and Desktop.

Upvotes: 15

arvin
arvin

Reputation: 1

you can use Firebase C++ SDK :

https://firebase.google.com/docs/cpp/setup#desktop-workflow

Upvotes: -1

Rob
Rob

Reputation: 174

Context: As of 24/02/2021 the main project for supporting firebase services in Flutter can be found here. If you look at this issue raised on GitHub it provides a rough roadmap for the project which is looking at the "possibility" of supporting desktop.

An issue has been opened to provide support for Windows and Linux.

Answer: Right now the best options to use Firebase with your desktop application is to either -

  1. Read the documentation for each firebase service and see if they support RESTful API requests to interact with the service. For example Cloud Firestore supports this.
  2. firedart is an open source attempt to provide an API for some Firebase services.
  3. Wait for ("hopefully") Google to provide a package written natively in dart.

Upvotes: 8

Frank van Puffelen
Frank van Puffelen

Reputation: 598797

The main FlutterFire page has a table that shows what Firebase products work in which environment.

Right now that shows that these products are supported in macOS desktop apps:

  • Cloud Firestore
  • Cloud Functions
  • Firebase Authentication
  • Firebase Crashlytics
  • Firebase Storage

If you're having problems making one of these work, edit your question to include the minimal information with which we can reproduce where you got stuck and any error messages you're getting.

Upvotes: 5

Related Questions