post_office 0.1.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • new54

PostOffice #

Overview #

Using a Snackbar requires you to have access to the BuildContext of the current Scaffold. PostOffice allows you to trigger info messages in your app and display them everywhere a PostBox is installed.

Installation #

dependencies:
  post_office: ^0.1.0

Usage #

Simply wrap your MaterialApp in the PostOffice widget. The PostOffice will distribute your messages throughout your app.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return PostOffice(
      child: MaterialApp(
        home: LoginPage(),
      ),
    );
  }
}

Wrap your Scaffold's body content in a PostBox widget to receive and display all messages sent to PostOffice.

Scaffold(
  body: PostBox(
    child: //Put your body here
  )
);

Anywhere in your app you can send messages to the PostOffice. Additionally, you can specify a type and a duration, how long the message should be displayed.

PostOffice.of(context).send(
  "registration complete",
  type: MessageType.success,
  duration: Duration(seconds: 3),
);

If you want complete freedom of how your Message should look like, you can also use PostBoxBuilder and render your own Widget.

PostBoxBuilder(
  builder: (context, message){
    return Text(message.text);
  },
),

[0.0.1] #

  • Initial release containing basic setup for simple info messages throughout the app.
  • Widgets: PostOffice, PostBox, PostBoxBuilder

[0.1.0] #

  • Added example

[0.1.0+1] #

  • updated metadata

example/main.dart

import 'package:flutter/material.dart';
import 'package:post_office/post_box.dart';
import 'package:post_office/post_office.dart';

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

class PostOfficeApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return PostOffice(
      child: MaterialApp(
        home: LoginPage(),
      ),
    );
  }
}

class LoginPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Login"),
      ),
      body: PostBox(
        child: Center(
          child: RaisedButton(
            child: Text("Start registration"),
            onPressed: () {
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => RegisterPage()));
            },
          ),
        ),
      ),
    );
  }
}

class RegisterPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Registration"),
      ),
      body: PostBox(
        child: Center(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              RaisedButton(
                child: Text("Invalid Registration"),
                onPressed: () => PostOffice.of(context)
                    .send("Invalid Registration", type: MessageType.error),
              ),
              RaisedButton(
                child: Text("Valid Registration"),
                onPressed: () {
                  Navigator.pop(context);
                  PostOffice.of(context)
                      .send("Valid Registration", type: MessageType.success);
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  post_office: ^0.1.0+1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:post_office/post_office.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
7
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Jul 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [post_office] that is in a package requiring null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test