snack_bar_presenter 0.1.3+1 copy "snack_bar_presenter: ^0.1.3+1" to clipboard
snack_bar_presenter: ^0.1.3+1 copied to clipboard

discontinued

Provide easy and flexible way to show SnackBar. Simple text, undo, and error style are supported.

snack_bar_presenter #

Provide easy and flexible way to show SnackBar. Simple text, undo, and error style are supported.

. . .
Screenshot_1594537088 Screenshot_1594537095 Screenshot_1594537100

Usage #

import 'package:example/providers/providers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:snack_bar_presenter/snack_bar_presenter.dart';

class BasicPage extends HookWidget {
  const BasicPage({
    Key key,
    this.index = 0,
  }) : super(key: key);

  final int index;

  static const routeName = '/basic';

  @override
  Widget build(BuildContext context) {
    final controller = useProvider(_controllers(index));
    final canPop = useProvider(navigatorKeyProvider).currentState.canPop();
    return Scaffold(
      key: controller.scaffoldKey,
      appBar: AppBar(title: Text('index: $index')),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            RaisedButton(
              child: const Text('Show SnackBar'),
              onPressed: () => controller.showSnackBarMessage('Hey( ´・‿・`)'),
            ),
            RaisedButton(
              child: const Text('👉 Navigate to next page'),
              onPressed: () {
                Navigator.of(context).push<void>(
                  MaterialPageRoute(
                    builder: (context) => BasicPage(
                      index: index + 1,
                    ),
                  ),
                );
              },
            ),
            if (canPop)
              RaisedButton(
                child: const Text('👈 Pop and show SnackBar'),
                onPressed: controller.popAndShowSnackBar,
              ),
          ],
        ),
      ),
      bottomNavigationBar: BottomAppBar(
        child: Row(
          children: [
            IconButton(
              icon: const Icon(Icons.add),
              onPressed: () {},
            )
          ],
        ),
      ),
    );
  }
}

final _controllers = Provider.autoDispose.family<_Controller, int>(
  (ref, __) {
    final controller = _Controller(ref);
    ref.onDispose(controller.dispose);
    return controller;
  },
);

class _Controller with SnackBarMixin {
  _Controller(this._ref) {
    registerToStackBarPresenter();
  }

  final ProviderReference _ref;

  @override
  SnackBarPresenter get snackBarPresenter =>
      _ref.read(snackBarPresenterProvider);

  void popAndShowSnackBar() {
    _ref.read(navigatorKeyProvider).currentState.pop();
    // Remove registration before showing SnackBar
    unregisterFromStackBarPresenter();
    showSnackBarMessage('Came back( ´・‿・`)');
  }

  void dispose() {
    unregisterFromStackBarPresenter();
  }
}
2
likes
40
pub points
0%
popularity

Publisher

verified publishermono0926.com

Provide easy and flexible way to show SnackBar. Simple text, undo, and error style are supported.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, riverpod, simple_logger

More

Packages that depend on snack_bar_presenter