Android and iOS Toast Library for Flutter
Supported Platforms
If you dont want to use androidx then use fluttertoast
version 2.2.11
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
);
property | description |
msg | String (Not Null)(required) |
toastLength | Toast.LENGTH_SHORT or Toast.LENGTH_LONG (optional) |
gravity | ToastGravity.TOP (or) ToastGravity.CENTER (or) ToastGravity.BOTTOM |
timeInSecForIos | int (only for ios) |
bgcolor | Colors.red |
textcolor | Colors.white |
fontSize | 16.0 (float) |
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