bytoast 1.0.0 bytoast: ^1.0.0 copied to clipboard
A Toast Widget for Flutter. Pure Dart Code.
import 'package:bytoast/bytoast.dart';
import 'package:bytoast/core/toast_style.dart';
import 'package:flutter/material.dart';
import 'base/page_widget.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: 'Pandora 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.lightGreen,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends BasePageWidget {
final String title;
const MyHomePage({Key key, this.title}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends BasePageState<MyHomePage> {
var _funcMap;
var _gValue = ToastStyle.bottom;
onItemClick(BuildContext context, int index) {
switch (index) {
case 0:
toast(context, '这是一条吐司');
break;
case 1:
toast(context, '这是一条很长很长很长很长很长很长很长很长的吐司');
break;
case 2:
ByToast.withIcon(
context,
'成功提示',
Image.asset('images/ic_tips_ok.webp', alignment: Alignment.center),
isOnTop: true,
);
break;
case 3:
ByToast.withIcon(context, '有新的提醒', Icon(Icons.alarm, color: Colors.white));
break;
case 4:
ByToast.more(
context,
msg: '自定义显示',
gravity: _gValue,
txtColor: Colors.lightGreen,
);
break;
}
}
@override
void initParams() {
super.initParams();
_funcMap = [
'吐司:普通',
'吐司:普通换行',
'吐司:成功提示',
'吐司:有新的提醒',
'吐司:自定义显示',
];
}
@override
String getTitle() {
return "Toaster Demo";
}
_switchGravity(value) {
setState(() {
_gValue = value;
});
}
@override
buildBody() => Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: _funcMap.length,
padding: EdgeInsets.all(8),
itemBuilder: (BuildContext context, int index) {
return Card(
child: ListTile(
title: Text(_funcMap[index]),
onTap: () {
onItemClick(context, index);
},
),
);
},
)),
SizedBox(height: 8.0),
RadioListTile(
value: ToastStyle.top,
title: Text('顶部'),
groupValue: _gValue,
onChanged: _switchGravity,
),
RadioListTile(
value: ToastStyle.center,
title: Text('中部'),
groupValue: _gValue,
onChanged: _switchGravity,
),
RadioListTile(
value: ToastStyle.bottom,
title: Text('底部'),
groupValue: _gValue,
onChanged: _switchGravity,
)
],
);
}