firebase_model_notifier 0.15.1+22 copy "firebase_model_notifier: ^0.15.1+22" to clipboard
firebase_model_notifier: ^0.15.1+22 copied to clipboard

discontinued

ModelNotifier package for Firebase. When you listen in Firestore, you can tell riverpod and others about the update.

example/lib/main.dart

// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "FirestoreModel Notifier Demo",
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyCountUpDemo(),
    );
  }
}

class MyCountUpDemo extends StatefulWidget {
  const MyCountUpDemo();

  @override
  State<StatefulWidget> createState() => MyCountUpDemoState();
}

class MyCountUpDemoState extends State<MyCountUpDemo> {
  late final FirestoreDynamicDocumentModel document;

  @override
  void initState() {
    super.initState();
    document = FirestoreDynamicDocumentModel("app/counter");
    document.addListener(_handledOnUpdate);
  }

  @override
  void dispose() {
    super.dispose();
    document.removeListener(_handledOnUpdate);
  }

  void _handledOnUpdate() {
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    final count = document.get("count", 0);

    return Scaffold(
      appBar: AppBar(
        title: const Text("FirestoreModel Notifier Demo"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              "$count",
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          document["count"] = count + 1;
          document.save();
        },
        tooltip: "Increment",
        child: const Icon(Icons.add),
      ),
    );
  }
}
2
likes
110
points
81
downloads

Publisher

verified publishermathru.net

Weekly Downloads

ModelNotifier package for Firebase. When you listen in Firestore, you can tell riverpod and others about the update.

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

cloud_firestore, cloud_functions, flutter, katana_firebase, model_notifier

More

Packages that depend on firebase_model_notifier