model_notifier 0.15.1+16 copy "model_notifier: ^0.15.1+16" to clipboard
model_notifier: ^0.15.1+16 copied to clipboard

Package that makes it easy to define ValueNotifier as a model and improves the affinity with riverpod and freezed.

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:flutter/material.dart';
import 'package:model_notifier/model_notifier.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "LocalModel 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 LocalDynamicDocumentModel document;

  @override
  void initState() {
    super.initState();
    document = LocalDynamicDocumentModel("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("LocalModel 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),
      ),
    );
  }
}
0
likes
120
pub points
1%
popularity

Publisher

verified publishermathru.net

Package that makes it easy to define ValueNotifier as a model and improves the affinity with riverpod and freezed.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter, katana_flutter

More

Packages that depend on model_notifier