bot_toast 2.1.0
bot_toast: ^2.1.0 copied to clipboard
A really easy to use flutter toast library.Easy to use and feature rich.
example/lib/main.dart
import 'dart:convert';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'all.dart';
import 'attached_toast/attached_toast.dart';
import 'custom/custom_animation.dart';
import 'custom/custom_widget.dart';
import 'loading/custom_loading.dart';
import 'loading/loading.dart';
import 'notification/custom_notification.dart';
import 'notification/notification.dart' as notification;
import 'notification/simple_notification.dart';
import 'text/custom_text.dart';
import 'text/text.dart';
void main() {
runApp(MyApp());
}
class Locations {
final Locale locale;
Locations(this.locale);
static Locations of(BuildContext context) {
return Localizations.of<Locations>(context, Locations);
}
Map<String, String> _localizedValues;
Future<bool> loadLocalizedValues(String root) async {
await Future.delayed(Duration(milliseconds: 1000));
final String data = jsonEncode({'test':'test123'});
final dynamic _result = json.decode(data);
_localizedValues = <String, String>{};
_result.forEach((String key, dynamic value) {
_localizedValues[key] = value.toString();
});
return true;
}
String locate(String key) {
return _localizedValues[key];
}
}
abstract class IL10NService extends LocalizationsDelegate<Locations> {
void initialize(String root);
String currentLocation();
String localize(String key);
@override
bool isSupported(Locale locale) => true;
@override
bool shouldReload(LocalizationsDelegate<Locations> old) => false;
}
class L10NService extends IL10NService {
String _root;
Locations _locations;
@override
void initialize(String root) {
_root = root;
}
@override
String currentLocation() => _locations.locale.languageCode;
@override
String localize(String key) => _locations.locate(key);
@override
Future<Locations> load(Locale locale) async {
_locations = Locations(locale);
await _locations.loadLocalizedValues(_root);
return _locations;
}
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
GlobalKey<NavigatorState> key = GlobalKey<NavigatorState>();
@override
Widget build(BuildContext context) {
return BotToastInit(
child: MaterialApp(
title: 'BotToast Demo',
key: key,
navigatorObservers: [BotToastNavigatorObserver()],
localizationsDelegates: <LocalizationsDelegate<dynamic>>[
L10NService(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
home: Stack(
children: <Widget>[
EnterPage(),
Center(
child: Card(
child: RaisedButton(onPressed: (){
setState(() {
key = GlobalKey<NavigatorState>();
});
},child: Text('toggle'),),
),
)
],
),
),
);
}
}
class EnterPage extends StatefulWidget {
@override
_EnterPageState createState() => _EnterPageState();
}
class _EnterPageState extends State<EnterPage> {
@override
void initState() {
BotToast.showText(text: '123');
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("BotToast"),
centerTitle: true,
),
body: Align(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
child: Container(
margin: EdgeInsets.only(top: 5),
child: Column(children: <Widget>[
Text(
"Notification",
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
),
Divider(),
Row(
children: <Widget>[
Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => SimpleNotification()));
},
child: Text("SimpleNotification"),
),
),
),
Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => notification.Notification()));
},
child: Text("Notification"),
),
),
)
],
),
Container(
width: double.infinity,
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => CustomNotification()));
},
child: Text("CustomNotification"),
),
),
Container(
height: 40,
),
Text(
"TextToast",
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
),
Divider(),
Row(
children: <Widget>[
Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => TextSample()));
},
child: Text("TextToast"),
),
),
),
Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => CustomText()));
},
child: Text("CustomText"),
),
),
)
],
),
Container(
height: 40,
),
Text(
"Load",
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
),
Divider(),
Row(
children: <Widget>[
Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => Loading()));
},
child: Text("Loading"),
),
),
),
Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => CustomLoading()));
},
child: Text("CustomLoading"),
),
),
),
],
),
Text(
'Other',
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
),
const Divider(),
Row(
children: <Widget>[
Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => AttachedToast()));
},
child: Text('AttachedToast'),
),
),
),
Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => All()));
},
child: Text("All"),
),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => CustomAnimation()));
},
child: const Text('CustomAnimation'),
),
),
),
Expanded(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 10),
child: RaisedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (_) => CustomWidget()));
},
child: const Text('CustomWidget'),
),
),
)
],
)
]),
),
),
));
}
}