firebase_model_notifier 0.9.0+21 copy "firebase_model_notifier: ^0.9.0+21" to clipboard
firebase_model_notifier: ^0.9.0+21 copied to clipboard

discontinued
outdated

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 ProviderScope(
      child: MaterialApp(
        title: "FirestoreModel Notifier Demo",
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MyCountUpDemo(),
      ),
    );
  }
}

class MyCountUpDemo extends ConsumerWidget {
  const MyCountUpDemo();

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final document = ref.watch(firestoreDocumentProvider("app/counter"));
    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),
      ),
    );
  }
}