get_notifier 0.0.4 copy "get_notifier: ^0.0.4" to clipboard
get_notifier: ^0.0.4 copied to clipboard

outdated

Flutter plugin to use the power of ChangeNotifier and GetIt together.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:get_notifier/get_notifier.dart';
import 'package:get_notifier_example/app_model.dart';
import 'package:get_notifier_example/helper.dart';

// This is our global ServiceLocator
// GetIt getIt = GetIt.instance;

void main() {
  GetIt.instance
    ..registerSingleton(AppModel(), signalsReady: true)
    ..registerFactory(() => Service());

  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Get Notifier Example Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  final s = GetIt.I.get<Service>();

  @override
  Widget build(BuildContext context) {
    return Material(
      child: FutureBuilder(
          future: GetIt.I.allReady(),
          builder: (context, snapshot) {
            if (snapshot.hasData) {
              return Scaffold(
                appBar: AppBar(
                  title: Text(title),
                ),
                body: Consumer2<AppModel, Service>(builder: (appModel, service, child) {
                  return Center(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        const Text(
                          'You have pushed the button this many times:',
                        ),
                        Text(
                          appModel.counter.toString(),
                          style: Theme.of(context).textTheme.headline4,
                        ),
                        ElevatedButton(onPressed: service.incrementCounter, child: const Text('Increment'))
                      ],
                    ),
                  );
                }),
                floatingActionButton: FloatingActionButton(
                  onPressed: () {
                    // getIt<AppModel>().incrementCounter();
                    s.incrementCounter();
                  },
                  tooltip: 'Increment',
                  child: const Icon(Icons.add),
                ),
              );
            } else {
              return Column(
                mainAxisAlignment: MainAxisAlignment.center,
                mainAxisSize: MainAxisSize.min,
                children: const [
                  Text('Waiting for initialisation'),
                  SizedBox(
                    height: 16,
                  ),
                  CircularProgressIndicator(),
                ],
              );
            }
          }),
    );
  }
}
6
likes
0
pub points
15%
popularity

Publisher

unverified uploader

Flutter plugin to use the power of ChangeNotifier and GetIt together.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, flutter_web_plugins, get_it, nested

More

Packages that depend on get_notifier