notifiable 1.0.0 copy "notifiable: ^1.0.0" to clipboard
notifiable: ^1.0.0 copied to clipboard

outdated

A simple widget that allows updating specific widgets instead of the whole widget tree.

example/notifiable_example.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Notifiable Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: NotifiableExample(),
    );
  }
}

class NotifiableExample extends StatelessWidget {
  final _model = TitleAndSubtitle();
  final _titleChangeNotifier = Notifier();
  final _subtitleChangeNotifier = Notifier();

  NotifiableExample({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          const SizedBox(height: 60),
          Notifiable(
            notifier: _titleChangeNotifier,
            builder: (context) => Text(
              _model.title,
              style: const TextStyle(fontSize: 20),
            ),
          ),
          TextButton(
            child: Container(
              width: double.infinity,
              height: 30,
              color: Colors.blue,
              child: const Center(
                child: Text(
                  "TAP TO CHANGE THE TITLE",
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            onPressed: () {
              _model.title = "This is the new title";
              _titleChangeNotifier.notify();
            },
          ),
          const SizedBox(height: 60),
          Notifiable(
            notifier: _subtitleChangeNotifier,
            builder: (context) => Text(
              _model.subtitle,
              style: const TextStyle(fontSize: 20),
            ),
          ),
          TextButton(
            child: Container(
              width: double.infinity,
              height: 30,
              color: Colors.green,
              child: const Center(
                child: Text(
                  "TAP TO CHANGE THE SUBTITLE",
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            onPressed: () {
              _model.subtitle = "This is the new subtitle";
              _subtitleChangeNotifier.notify();
            },
          )
        ],
      ),
    );
  }
}

class TitleAndSubtitle {
  var title = "Title";
  var subtitle = "Subtitle";
}
4
likes
0
pub points
15%
popularity

Publisher

verified publishershoutoutsoftware.com

A simple widget that allows updating specific widgets instead of the whole widget tree.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on notifiable