toast_badge 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

Toast Like Message Badge Widget #

What does it do? #

With toast_badge we can simply call

ToastBadge.show("Hello world");

From anywhere in the app and it will show Toast like shown in the Image Above.

While also being able to place it right in the place where you want it.

How to use it? #

  1. Add toast_badge to pubspec.yml

    toast_badge: ^0.1

  1. Import Toast Wiget import 'package:toast_badge/toast_badge.dart';

  2. Now wrap your widget inside Toast Widget

    a. Just Wrap any Widget with ToastWidget() like this

     child: ToastBadge(
         child: SettingPage(),
     ),
    

    b. You can also use the extension method .enableBadge() on any Widget:

     child: SettingPage().enableBadge(),
    
  1. Finally, call ToastBadge.show() from anywhere in the app.

    a. Just Show Text :

     ToastBadge.show("Hello Toast");
    

    b. Show Toast with additional setting:

     ToastBadge.show(
     "Hello Toast",
     mode: ToastMode.INFO,
     duration: Duration(milliseconds: 500)
     );
    

Parameter info :

Mode #

mode:

// ToastMode.INF0 - Green Background
// ToastMode.DEBUG - Blue Background
// ToastMode.ERROR - Red Background

Duration #

duration:

// Give Duration for how long do you want the toast to show and disappear itself.

// User can also click the 'X' icon on the Toast to close.

[0.1.0] - May 8 2020 Initial release #

[0.1.1] - May 8 2020 Fixed a typo #

example/lib/main.dart

import 'dart:async';
import 'dart:math';

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

StreamController<bool> isLightTheme = StreamController();

main() {
  runApp(MainApp());
}

class MainApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return StreamBuilder<bool>(
        initialData: true,
        stream: isLightTheme.stream,
        builder: (context, snapshot) {
          return MaterialApp(
              theme: snapshot.data ? ThemeData.light() : ThemeData.dark(),
              debugShowCheckedModeBanner: false,
              home: Scaffold(
                  appBar: AppBar(title: Text("Toast Badge Example")),
                  body: ToastBadge(child: SettingPage())));
        });
  }
}

class SettingPage extends StatefulWidget {
  @override
  _SettingPageState createState() => _SettingPageState();
}

class _SettingPageState extends State<SettingPage> {
  String userName = "Press Fetch User Button";

  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: const EdgeInsets.all(16.0),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Spacer(flex: 1),
              Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    RaisedButton(
                        color: Colors.blue,
                        child: Text("Light Theme",
                            style: TextStyle(color: Colors.white)),
                        onPressed: () {
                          ToastBadge.show("Light Theme Applied",
                              mode: ToastMode.DEBUG);
                          isLightTheme.add(true);
                        }),
                    RaisedButton(
                        color: Colors.black,
                        child: Text("Dark Theme",
                            style: TextStyle(color: Colors.white)),
                        onPressed: () {
                          ToastBadge.show("Dark Theme Applied",
                              mode: ToastMode.ERROR);
                          isLightTheme.add(false);
                        }),
                  ]),
              Spacer(
                flex: 1,
              ),
              Padding(
                padding: const EdgeInsets.only(top: 32),
                child: RaisedButton(
                  color: Colors.blue,
                  onPressed: () async {
                    var name = await getUserNameFromBackend();
                    setState(() {
                      userName = name;
                    });
                  },
                  child:
                      Text("Fetch User", style: TextStyle(color: Colors.white)),
                ),
              ).enableBadge(),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text("User Name : $userName"),
              ),
              Spacer(
                flex: 1,
              ),
            ],
          ),
        ));
  }
}

Future<String> getUserNameFromBackend() async {
  await Future.delayed(Duration(milliseconds: 400));
  var success = Random().nextInt(30) % 4 != 0;
  ToastBadge.show(
    success ? "User Fetch Success" : "User Fetch Failed",
    mode: success ? ToastMode.INFO : ToastMode.ERROR,
  );
  return success ? "Laxman Bhattarai" : "User Fetch Error";
}

Use this package as a library

1. Depend on it

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


dependencies:
  toast_badge: ^0.1.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:toast_badge/toast_badge.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
49
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
89
Overall:
Weighted score of the above. [more]
72
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • toast_badge that is a package requiring null.

Maintenance suggestions

The package description is too short. (-11 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

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