Show Toast message

Android and iOS Toast Library for Flutter
Supported Platforms
  • Android
  • IOS
If you dont want to use androidx then use fluttertoast version 2.2.11

How to Use #

# add this line to your dependencies
fluttertoast: ^3.1.3
import 'package:fluttertoast/fluttertoast.dart';
Fluttertoast.showToast(
        msg: "This is Center Short Toast",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIos: 1,
        backgroundColor: Colors.red,
        textColor: Colors.white,
        fontSize: 16.0
    );
propertydescription
msgString (Not Null)(required)
toastLengthToast.LENGTH_SHORT or Toast.LENGTH_LONG (optional)
gravityToastGravity.TOP (or) ToastGravity.CENTER (or) ToastGravity.BOTTOM
timeInSecForIosint (only for ios)
bgcolorColors.red
textcolorColors.white
fontSize16.0 (float)

To cancel all the toasts call 

Fluttertoast.cancel(
Example:-
Firstly add your pubspec.yaml dependencies than try this
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
         title: Text('Welcome to Flutter'),
        ),
        body: Toastex(
        ),  
      ),
    );
  }
}

class Toastex extends StatefulWidget {
  @override
  _ToastexState createState() => _ToastexState();
}

class _ToastexState extends State<Toastex> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: RaisedButton(onPressed: (){
            Fluttertoast.showToast(
            msg: "This is Toast exampule",
            toastLength: Toast.LENGTH_LONG,
            gravity: ToastGravity.CENTER,
            timeInSecForIos: 1,
            backgroundColor: Colors.red[100],
            textColor: Colors.white,
            fontSize: 16.0
          );
        }
      ), 
    );
  }
}

Comments

Popular posts from this blog

Auto slide image with indicator in flutter

Flutter Architecture | Flutter - Architecture Application

Automatic Scrolling Image in flutter