pottery 0.4.0 copy "pottery: ^0.4.0" to clipboard
pottery: ^0.4.0 copied to clipboard

Utility for using Pot in Flutter to limit the lifespan of particular Pots according to the widget lifecycle.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:grab/grab.dart';
import 'package:pottery/pottery.dart';

import 'package:pottery_example/counter_notifier.dart';
import 'package:pottery_example/widgets.dart';

final counterNotifierPot = Pot.pending<CounterNotifier>(
  disposer: (notifier) => notifier.dispose(),
);

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

class App extends StatelessWidget {
  const App();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      scaffoldMessengerKey: scaffoldMessengerKey,
      home: const HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () => Navigator.of(context).push(
            CounterPage.route(),
          ),
          child: const Text('To counter page'),
        ),
      ),
    );
  }
}

class CounterPage extends StatelessWidget with Grab {
  const CounterPage._();

  static Route<void> route() {
    return MaterialPageRoute(
      builder: (_) => Pottery(
        pots: {
          counterNotifierPot: () => CounterNotifier(showMessage: true),
        },
        builder: (_) => const CounterPage._(),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    final notifier = counterNotifierPot();
    final count = notifier.grab(context);

    return Scaffold(
      appBar: AppBar(title: const Text('Counter')),
      body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              '$count',
              style: const TextStyle(fontSize: 32.0),
            ),
            const SizedBox(width: 16.0),
            IncrementButton(onPressed: notifier.increment),
          ],
        ),
      ),
    );
  }
}
2
likes
0
pub points
48%
popularity

Publisher

verified publisherkaboc.cc

Utility for using Pot in Flutter to limit the lifespan of particular Pots according to the widget lifecycle.

Repository (GitHub)
View/report issues

Topics

#dependency-injection

License

unknown (LICENSE)

Dependencies

flutter, pot

More

Packages that depend on pottery