tbib_toast 0.0.2 tbib_toast: ^0.0.2 copied to clipboard
Toast Package.
import 'package:flutter/material.dart';
import 'package:tbib_toast/tbib_toast.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Toast Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Toast Demo Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: ElevatedButton(
child: Text('Show Short Toast'),
onPressed: () => showToast("Show Short Toast")),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: ElevatedButton(
child: Text('Show Long Toast'),
onPressed: () =>
showToast("Show Long Toast", duration: Toast.lengthLong)),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: ElevatedButton(
child: Text('Show Bottom Toast'),
onPressed: () =>
showToast("Show Bottom Toast", gravity: Toast.bottom)),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: ElevatedButton(
child: Text('Show Center Toast'),
onPressed: () =>
showToast("Show Center Toast", gravity: Toast.center)),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: ElevatedButton(
child: Text('Show Top Toast'),
onPressed: () => showToast(
"""所爱隔山海,山海皆可平。可是你不爱我啊,隔了座火焰山还拿不到芭蕉扇。我奋不顾身穿山越岭到了你身旁,你也只会来一句“卧槽你好666啊”""",
gravity: Toast.top)),
),
],
),
),
);
}
void showToast(String msg, {int? duration, int? gravity}) {
Toast.show(msg, context, duration: duration, gravity: gravity);
}
}