global_snack_bar 0.0.12 copy "global_snack_bar: ^0.0.12" to clipboard
global_snack_bar: ^0.0.12 copied to clipboard

Provides a convenient way to summon a SnackBar Widget on any open page, without much extra code.

global_snack_bar #

Provides a class for a global snack bar. This makes it convenient to summon a SnackBar with simple code, regardless of the Scaffold that is currently visible.

This is useful for cases such as intermittently checking the network connection — cases where you don't know what Scaffold will be visible before needing to show a SnackBar.

Just wrap your content in GlobalMsgWrapper.

Make sure that your content is a child of a Scaffold.

Then, from anywhere, use the following to show a SnackBar:

GlobalSnackBarBloc.showMessage(
  GlobalMsg("hello", bgColor: Colors.cyanAccent),
); 

How to use #

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


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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Global Snack Bar Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(title: 'Global Snack Bar Example'),
    );
  }
}

class HomePage extends StatefulWidget {
  HomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: GlobalMsgWrapper(
        Center(
          child: Text("Hello, World"),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          GlobalSnackBarBloc.showMessage(
            GlobalMsg("hello", bgColor: Colors.cyanAccent),
          );
        },
        child: Icon(Icons.ac_unit),
      ),
    );
  }
}
3
likes
140
pub points
67%
popularity

Publisher

unverified uploader

Provides a convenient way to summon a SnackBar Widget on any open page, without much extra code.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on global_snack_bar