cloud_firestore_all 0.1.1+4

  • Readme
  • Changelog
  • Example
  • Installing
  • 36

Cross-Platform Cloud Firestore Plugin #

A Firebase Firestore wrapper for Flutter that wraps cloud_firestore and firebase into a single API for use on both Flutter web and mobile.

Setup #

Mobile #

Follow cloud_firestore setup instructions for mobile setup.

Web #

Add Firebase JavaScript libraries to html file and initialize your application with your variables.

<script src="https://www.gstatic.com/firebasejs/7.4.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.4.0/firebase-firestore.js"></script>
<script>
    firebase.initializeApp({
        apiKey: "API KEY",
        authDomain: "AUTH DOMAIN",
        databaseURL: "DATABASE URL",
        projectId: "PROJECT ID",
        storageBucket: "STORAGE BUCKER URL",
        appId: "APP ID",
        messagingSenderId: "sender-id",
        measurementId: "G-measurement-id"
    });
</script>

See Example for details

TODO #

  • [ ] Add Unit Testing
  • [ ] Test Compatibility

Changelog #

[0.1.1+4] - 2020/1/3 #

  • Changed License

[0.1.1+3] - 2020/1/2 #

  • Fixed incorrect method call

[0.1.1+2] - 2020/1/1 #

  • Formating Changes
  • Removed duplicate properties

[0.1.1] - 2020/1/1 #

  • Added WriteBatch class
  • Added collection method to DocumentReference
  • Added FieldValue methods
  • Moved serverTimestamp to FieldValue class
  • Fixed bug where method parameter did not have default value or null check

[0.1.0+3] - 2019/12/17 #

  • Code reformatting.

[0.1.0+2] - 2019/12/17 #

  • Updated dependencies.
  • Added documentation.

[0.1.0+1] - 2019/11/2 #

  • Code Reformatting.

[0.1.0] - 2019/11/2 #

  • Project reorganized,
  • Added Example,
  • Added More classes.

[0.0.1] - 2019/10/23 #

  • Initial Release with limited support.

example/lib/main.dart

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

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

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

class MessageList extends StatelessWidget {
  MessageList({this.firestore});

  final Firestore firestore;

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
      stream: firestore.collection('messages').onSnapshot,
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (!snapshot.hasData) return const Text('Loading...');
        final int messageCount = snapshot.data.docs.length;
        return ListView.builder(
          itemCount: messageCount,
          itemBuilder: (_, int index) {
            final DocumentSnapshot document = snapshot.data.docs[index];
            final dynamic message = document['message'];
            return ListTile(
              title: Text(
                message != null ? message.toString() : '<No message retrieved>',
              ),
              subtitle: Text('Message ${index + 1} of $messageCount'),
              trailing: Text(
                DateTime.fromMillisecondsSinceEpoch(
                  document['created_at']?.millisecondsSinceEpoch ?? 0,
                  isUtc: true,
                ).toString(),
              ),
            );
          },
        );
      },
    );
  }
}

class MyHomePage extends StatelessWidget {
  final Firestore firestore = firestoreInstance;
  CollectionReference get messages => firestore.collection('messages');

  Future<void> _addMessage() async {
    await messages.add(<String, dynamic>{
      'message': 'Hello World from Cloud_Firestore_All!',
      'created_at': FieldValue.serverTimestamp(),
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Firestore Example'),
      ),
      body: MessageList(firestore: firestore),
      floatingActionButton: FloatingActionButton(
        onPressed: _addMessage,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  cloud_firestore_all: ^0.1.1+4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

This package is not analyzed, because it is discontinued.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0