oktoast 2.1.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 88

oktoast

pub package Hex.pm

A library for flutter.

A pure dart toast Library.

You can completely customize the style of toast.

screenshot

default pic

custom position and widget pic

gif:

about version 1.X.X

if you use oktoast 1.X.X ,Please use the 1.X branch, and read version readme.

Proposed migration to 2.X.X version. The new version does not require buildContext.

And you can completely customize the style of toast, because now you can use showToastWidget.

use

  1. add library to your pubspec.yaml
dependencies:
  oktoast: ^2.1.0
  1. import library in dart file
import 'package:oktoast/oktoast.dart';
  1. wrap your app widget
OKToast(
  /// set toast style, optional
  child:MaterialApp()
);
  1. call method showToast
showToast("content");

// position and second have default value, is optional

showToastWidget(Text('hello oktoast'));

properties

oktoast have default style, and you also can custom textStyle.

textStyle: the toast text style
radius: the toast background color radius
backgroundColor: the background color
position: the toast align and padding
child: the application
onDismiss: on toast dismiss will be called.

about return type:
showToast and showToastWidget change return type from void to ToastFuture in version 2.1.0
The ToastFuture can be use to dismiss the toast.

examples

import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart'; // 1. import library

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return OKToast(
      //2. wrap your app with OKToast
      textStyle: TextStyle(fontSize: 19.0, color: Colors.white),
      backgroundColor: Colors.grey,
      radius: 10.0,
      child: new MaterialApp(
        title: 'Flutter Demo',
        theme: new ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: new MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    _counter++;

    // 3.1 use showToast method
    showToast(
      "$_counter",
      duration: Duration(seconds: 2),
      position: ToastPosition.bottom,
      backgroundColor: Colors.black.withOpacity(0.8),
      radius: 13.0,
      textStyle: TextStyle(fontSize: 18.0),
    );

    showToast(
      "$_counter",
      duration: Duration(seconds: 2),
      position: ToastPosition.top,
      backgroundColor: Colors.black.withOpacity(0.8),
      radius: 3.0,
      textStyle: TextStyle(fontSize: 30.0),
    );

    // 3.2 use showToastWidget method to custom widget
    Widget widget = Center(
      child: ClipRRect(
        borderRadius: BorderRadius.circular(30.0),
        child: Container(
          width: 40.0,
          height: 40.0,
           color: Colors.grey.withOpacity(0.3),
          child: Icon(
            Icons.add,
            size: 30.0,
            color: Colors.green,
          ),
        ),
      ),
    );

    ToastFuture toastFuture = showToastWidget(
      widget,
      duration: Duration(seconds: 3),
      onDismiss: () {
        print("the toast dismiss"); // the method will be called on toast dismiss.
      },
    );

    // can use future
    Future.delayed(Duration(seconds: 1), () {
      toastFuture.dismiss(); // dismiss
    });

    setState(() {

    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("ktoast demo"),
      ),
      body: Stack(
        children: <Widget>[
          new Center(
            child: ListView(
              children: <Widget>[
                new Text(
                  'You have pushed the button this many times:',
                ),
                new Text(
                  '$_counter',
                  style: Theme.of(context).textTheme.display1,
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: RaisedButton(
                    onPressed: () {
                      Navigator.push(context,
                          MaterialPageRoute(builder: (ctx) => MyHomePage()));
                    },
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: RaisedButton(
                    onPressed: _incrementCounter,
                    child: Text('toast'),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}


Change log

2.1.0

add new params to helper user listen toast dismiss

showToast and showToastWidget will return ToastFuture the toastFuture call dismiss() to dismiss toast.

2.0.1

oktoast support page level.

you can use oktoast wrap your Scaffold.

2.0.0

use BuildContext cache. then showToast not need context, you can use the showToast in anywhere.

1.0.4

support flutter sdk 0.10 ,fix bug

1.0.3

update the textAlign : TextAlign.center update the overflow: TextOverflow.ellipsis,

1.0.2

fix defaultPosition is invalid.

[1.0.1+2]

update readme

[1.0.1+1]

update readme

[1.0.1] rename library name

now libray is oktoast

[1.0.0] first release version

stable version

[0.0.3] add the toast position

the toast can set position

  1. showToast
  2. defaultPosition

[0.0.2] - add toast style

add the textStyle radius backgroundColor

[0.0.1] - first version

init commit

example/main.dart

import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart'; // 1. import library

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return OKToast(
      //2. wrap your app with OKToast
      textStyle: TextStyle(fontSize: 19.0, color: Colors.white),
      backgroundColor: Colors.grey,
      radius: 10.0,
      child: new MaterialApp(
        title: 'Flutter Demo',
        theme: new ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: new MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    _counter++;

    // 3.1 use showToast method
    showToast(
      "$_counter",
      duration: Duration(seconds: 2),
      position: ToastPosition.bottom,
      backgroundColor: Colors.black.withOpacity(0.8),
      radius: 13.0,
      textStyle: TextStyle(fontSize: 18.0),
    );

    showToast(
      "$_counter",
      duration: Duration(seconds: 2),
      position: ToastPosition.top,
      backgroundColor: Colors.black.withOpacity(0.8),
      radius: 3.0,
      textStyle: TextStyle(fontSize: 30.0),
    );

    // 3.2 use showToastWidget method
    Widget widget = Center(
      child: ClipRRect(
        borderRadius: BorderRadius.circular(30.0),
        child: Container(
          width: 40.0,
          height: 40.0,
          color: Colors.grey.withOpacity(0.3),
          child: Icon(
            Icons.add,
            size: 30.0,
            color: Colors.green,
          ),
        ),
      ),
    );
    ToastFuture toastFuture = showToastWidget(
      widget,
      duration: Duration(seconds: 3),
      onDismiss: () {
        print("the toast dismiss"); // the method will be called on toast dismiss.
      },
    );

    // can use future
    Future.delayed(Duration(seconds: 1), () {
      toastFuture.dismiss(); // dismiss
    });

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("ktoast demo"),
      ),
      body: Stack(
        children: <Widget>[
          new Center(
            child: ListView(
              children: <Widget>[
                new Text(
                  'You have pushed the button this many times:',
                ),
                new Text(
                  '$_counter',
                  style: Theme.of(context).textTheme.display1,
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: RaisedButton(
                    onPressed: () {
                      Navigator.push(context, MaterialPageRoute(builder: (ctx) => MyHomePage()));
                    },
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: RaisedButton(
                    onPressed: _incrementCounter,
                    child: Text('toast'),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  oktoast: ^2.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:oktoast/oktoast.dart';
  
Version Uploaded Documentation Archive
2.1.0 Dec 7, 2018 Go to the documentation of oktoast 2.1.0 Download oktoast 2.1.0 archive
2.0.1 Nov 22, 2018 Go to the documentation of oktoast 2.0.1 Download oktoast 2.0.1 archive
2.0.0 Oct 24, 2018 Go to the documentation of oktoast 2.0.0 Download oktoast 2.0.0 archive
1.0.4 Oct 24, 2018 Go to the documentation of oktoast 1.0.4 Download oktoast 1.0.4 archive
1.0.3 Sep 7, 2018 Go to the documentation of oktoast 1.0.3 Download oktoast 1.0.3 archive
1.0.2 Sep 7, 2018 Go to the documentation of oktoast 1.0.2 Download oktoast 1.0.2 archive
1.0.1+2 Aug 9, 2018 Go to the documentation of oktoast 1.0.1+2 Download oktoast 1.0.1+2 archive
1.0.1+1 Aug 8, 2018 Go to the documentation of oktoast 1.0.1+1 Download oktoast 1.0.1+1 archive
1.0.1 Aug 8, 2018 Go to the documentation of oktoast 1.0.1 Download oktoast 1.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
81
Health:
Code health derived from static analysis. [more]
91
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

We analyzed this package on Dec 7, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs (-9.44 points)

17 out of 18 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test