stove 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 14

Stove 🔥🍳 #

Stove is the thin, but strongly typed wrapper library for cloud_firestore.

Now you can,

  • take advantages of the type checker of Dart language
  • avoid runtime errors due to dynamic arguments of cloud_firestore
  • avoid typos due to using raw String literals for the name of document's fields

Stove provides you a happy yummy Firestore life for you! 🔥🍳

Using #

Define the document class #

/// User document
class User {}

That's it!

Also, you can add fields for this class if you want.

Define fields of the document #

// The document `User` has fields named `name` and `gender`.
class UserField<FT, LT> implements Field<User, FT, LT> {
  final String name;
  final Converter<FT, LT> storeToLocal;
  final Converter<LT, FT> localToStore;

  const UserField._(this.name, this.storeToLocal, this.localToStore);

  static const name$ = UserField<String, String>._("name", identity, identity);
  static final gender = UserField._(
        "gender",
            (f) => Gender.values.where((g) => g.toString().contains(f)).first,
            (l) => l.toString().split(".")[1]);
}

The class represents the field of the document should extend Field<T, FT, LT>. T should be unique by each document. FT means "Type in Firesore". LT means "Type in the local environment".

You can define your own converters that converts FT and LT. You can use all type of instance if you write converters. If you don't want to convert the value, put identity converter (it through arguments).

Define children of the document #

// The document `User` has a child (sub collection) named `friends`.
class UserChildren<C> implements SubCollection<User, C> {
  final String name;

  const UserChildren._(this.name);

  static const friends = UserChildren<Friend>._("friends");
}

The class represents the child (sub collection) should extend SubCollection<C>. C is the class represents the document of the element of that collection.

Using document reference #

// Create the reference of new document
final userReference = Stove.instance.collection<User>("/users").document();

// Save data
await userReference.setData(DocumentDifference()
  ..set(UserFields.name$, "Bob")
  ..set(UserFields.gender, Gender.male)
);

// Update data
await userReference.updateData(DocumentDifference()
  ..set(UserFields.name$, "John")
  ..delete(UserFields.gender)
);
// Delete data

await userReference.delete();

// Get the snapshot
final userSnapshot = await userReference.get();
final name = userSnapshot.data.get(UserFields.name$);    // name: String
final gender = userSnapshot.data.get(UserFields.gender); // gender: Gender (automatically converted!)
switch (gender) {
  case Gender.male:
    ......
}

// Access sub collection
final friendsReference = userReference.SubCollection(UserChildren.friends);

Using sub collection reference #

final usersReference = Stove.instance.collection<User>("/users");

// Get all documents
final snapshots = usersReference.documents();

// Listen all documents
usersReference.snapshots()
  .listen((/*List<DocumentSnapshot<User>>*/ snapshots) {
    doYourStuff(snapshots)
});

// Query documents
usersReference
  .where(UserFields.gender, isEqualTo: Gender.female)
  .order(UserFields.name$)
  .documents();

[0.0.1] - First release #

  • First release to get opinions for this library.

example/lib/main.dart

import 'package:example/data/repository.dart';
import 'package:example/screens/category_screen.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

void main() => runApp(Provider(
      create: (context) => Repository(),
      child: 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(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: CategoryScreen(),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  stove: ^0.0.1

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:stove/stove.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
14
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Health issues and suggestions

Fix lib/src/query.dart. (-92.49 points)

Analysis of lib/src/query.dart failed with 9 errors, including:

line 18 col 6: This requires the 'non-nullable' experiment to be enabled.

line 19 col 6: This requires the 'non-nullable' experiment to be enabled.

line 20 col 6: This requires the 'non-nullable' experiment to be enabled.

line 21 col 6: This requires the 'non-nullable' experiment to be enabled.

line 22 col 6: This requires the 'non-nullable' experiment to be enabled.

Fix lib/src/document_reference.dart. (-90.09 points)

Analysis of lib/src/document_reference.dart failed with 8 errors, 2 hints, including:

line 5 col 11: This requires the 'non-nullable' experiment to be enabled.

line 6 col 27: This requires the 'non-nullable' experiment to be enabled.

line 7 col 24: This requires the 'non-nullable' experiment to be enabled.

line 20 col 3: Constructors can't have a return type.

line 20 col 8: The name of a constructor must match the name of the enclosing class.

Fix lib/src/document_data.dart. (-68.36 points)

Analysis of lib/src/document_data.dart failed with 4 errors:

line 4 col 44: This requires the 'non-nullable' experiment to be enabled.

line 14 col 37: This requires the 'non-nullable' experiment to be enabled.

line 17 col 28: This requires the 'non-nullable' experiment to be enabled.

line 19 col 5: This requires the 'non-nullable' experiment to be enabled.

Fix additional 4 files with analysis or formatting issues. (-93.75 points)

Additional issues in the following files:

  • lib/src/document_difference.dart (2 errors)
  • lib/src/collection_reference.dart (1 error)
  • lib/src/stove.dart (1 error)
  • lib/src/sub_collection.dart (Run flutter format to format lib/src/sub_collection.dart.)

Document public APIs. (-1 points)

99 out of 99 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance issues and suggestions

No valid SDK. (-20 points)

The analysis could not detect a valid SDK that can use this package.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.1 <3.0.0
cloud_firestore ^0.13.5 0.13.7 0.14.0-dev.1
flutter 0.0.0
Transitive dependencies
charcode 1.1.3
cloud_firestore_platform_interface 1.1.2 2.0.0-dev.1
cloud_firestore_web 0.1.1+2 0.2.0-dev.1
collection 1.14.12 1.14.13
firebase 7.3.0
firebase_core 0.4.5 0.5.0-dev.1
firebase_core_platform_interface 1.0.4 2.0.0-dev.1
firebase_core_web 0.1.1+2 0.2.0-dev.1
flutter_web_plugins 0.0.0
http 0.12.1
http_parser 3.1.4
js 0.6.2
matcher 0.12.9
meta 1.1.8 1.2.2
path 1.7.0
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 2.1.0-nullsafety
Dev dependencies
flutter_test
pedantic ^1.8.0 1.9.0 1.9.2