firestore_all 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 46

firestore_all #

Plugin that wraps Firestore from firebase and cloud_firestore packages and expose them as a single API.

Getting Started #

Shared #

To get the Firestore instance use setupFirestore function.

var firestore = setupFirestore(
  webApiKey: 'apiKey',
  webAuthDomain: 'authDomain',
  webDatabaseUrl: 'databaseUrl',
  webProjectId: 'projectId',
  webStorageBucket: 'storageBucket',
);

Web #

Add following code to index.html in web directory.

<script src="https://www.gstatic.com/firebasejs/5.10.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.10.1/firebase-firestore.js"></script>

TODO #

  • [x] Wrap Firestore from firebase package (for Flutter web)
  • [x] Wrap Firestore from cloud_firestore (for Flutter Android/iOS)
  • [ ] Test: Check if it's working on web
    • [x] snapshot streams
    • [x] add, update, edit
    • [ ] get document
  • [x] Test: Check if it's working on Android
  • [ ] Test: Check if it's working on iOS
  • [ ] Integrate with Firebase Auth

0.2.0 #

  • remove FirestoreInterface class

0.1.0+1 #

  • apply pub.dev suggestions

0.1.0 #

  • Wrap cloud_firestore (Android/iOS)
  • Wrap firebase (Web)

example/lib/main.dart

import 'package:firestore_all/firestore_all.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

Firestore firestore;

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  firestore = setupFirestore(
    webApiKey: 'AIzaSyA_oLeZpKm9gX_MszdSGdgIP9PokdqQJw4',
    webAuthDomain: 'flutterblocwithprovider.firebaseapp.com',
    webDatabaseUrl: 'https://flutterblocwithprovider.firebaseio.com',
    webProjectId: 'flutterblocwithprovider',
    webStorageBucket: 'flutterblocwithprovider.appspot.com',
  );
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: ArticlesList(),
    );
  }
}

class ArticlesList extends StatelessWidget {
  const ArticlesList({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Firestore All Example')),
      body: StreamBuilder<List<DocumentSnapshot>>(
        stream: firestore
            .collection('articles')
            .snapshots()
            .map((snapshot) => snapshot.documents),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return ListView.builder(
              itemCount: snapshot.data.length,
              itemBuilder: (context, index) {
                final data = snapshot.data[index];

                return ListTile(
                  title: Text(data['title']),
                  subtitle: Text(data['content']),
                );
              },
            );
          } else if (snapshot.hasError) {
            return Center(child: Text('Error :('));
          } else {
            return Center(child: CircularProgressIndicator());
          }
        },
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () => Navigator.of(context)
            .push(MaterialPageRoute(builder: (_) => AddArticlePage())),
      ),
    );
  }
}

class AddArticlePage extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final formKey = useMemoized(() => GlobalKey<FormState>());
    final scaffoldKey = useMemoized(() => GlobalKey<ScaffoldState>());

    final title = useState<String>();
    final content = useState<String>();

    final onAddClick = () {
      formKey.currentState.save();

      scaffoldKey.currentState.showSnackBar(
        SnackBar(content: Text('Adding...')),
      );
      firestore.collection('articles').add({
        'title': title.value,
        'content': content.value,
      }).then((_) {
        Navigator.of(context).pop();
      });
    };

    return Scaffold(
      key: scaffoldKey,
      appBar: AppBar(title: Text('Add article')),
      body: Form(
        key: formKey,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TextFormField(
              decoration: InputDecoration(hintText: 'Title'),
              onSaved: (value) => title.value = value,
            ),
            TextFormField(
              decoration: InputDecoration(hintText: 'Content'),
              onSaved: (value) => content.value = value,
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: onAddClick,
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  firestore_all: ^0.2.0

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:firestore_all/firestore_all.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
46
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.9+1
  • Flutter: 1.17.3

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:firestore_all/firestore_all.dart, package:firestore_all/src/firestore_mobile.dart, package:cloud_firestore/cloud_firestore.dart]

Package does not support Flutter platform macos

Because of import path [package:firestore_all/firestore_all.dart, package:firestore_all/src/firestore_mobile.dart, package:cloud_firestore/cloud_firestore.dart]

Package does not support Flutter platform windows

Because of import path [package:firestore_all/firestore_all.dart, package:firestore_all/src/firestore_mobile.dart, package:cloud_firestore/cloud_firestore.dart]

Package not compatible with SDK dart

because of import path [firestore_all]

Maintenance issues and suggestions

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (cloud_firestore, firebase).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
cloud_firestore >=0.12.0 <0.13.0 0.12.11 0.13.7
firebase >=5.0.0 <5.1.0 5.0.4 7.3.0
flutter 0.0.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
firebase_core 0.4.2+2 0.4.5
firebase_core_platform_interface 1.0.4
http 0.12.1
http_parser 3.1.4
js 0.6.2
matcher 0.12.8
meta 1.1.8 1.2.0
path 1.7.0
pedantic 1.9.0 1.9.1
plugin_platform_interface 1.0.2
quiver 2.1.3
sky_engine 0.0.99
source_span 1.7.0
stack_trace 1.9.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test