Commit a71ea49b by Karthik Ponnam

formated

parent a10da367
......@@ -5,10 +5,22 @@ import 'package:flutter/services.dart';
enum Toast { LENGTH_SHORT, LENGTH_LONG }
enum ToastGravity { TOP, BOTTOM, CENTER, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER_LEFT, CENTER_RIGHT, SNACKBAR }
enum ToastGravity {
TOP,
BOTTOM,
CENTER,
TOP_LEFT,
TOP_RIGHT,
BOTTOM_LEFT,
BOTTOM_RIGHT,
CENTER_LEFT,
CENTER_RIGHT,
SNACKBAR
}
class Fluttertoast {
static const MethodChannel _channel = const MethodChannel('PonnamKarthik/fluttertoast');
static const MethodChannel _channel =
const MethodChannel('PonnamKarthik/fluttertoast');
static Future<bool> cancel() async {
bool res = await _channel.invokeMethod("cancel");
......@@ -43,7 +55,8 @@ class Fluttertoast {
gravityToast = "bottom";
}
if (backgroundColor == null && defaultTargetPlatform == TargetPlatform.iOS) {
if (backgroundColor == null &&
defaultTargetPlatform == TargetPlatform.iOS) {
backgroundColor = Colors.black;
}
if (textColor == null && defaultTargetPlatform == TargetPlatform.iOS) {
......@@ -67,7 +80,8 @@ class Fluttertoast {
}
}
typedef PositionedToastBuilder = Widget Function(BuildContext context, Widget child);
typedef PositionedToastBuilder = Widget Function(
BuildContext context, Widget child);
class FToast {
BuildContext context;
......@@ -95,7 +109,8 @@ class FToast {
}
_ToastEntry _toastEntry = _overlayQueue.removeAt(0);
_entry = _toastEntry.entry;
if (context == null) throw ("Error: Context is null, Please call init(context) before showing toast.");
if (context == null)
throw ("Error: Context is null, Please call init(context) before showing toast.");
Overlay.of(context).insert(_entry);
_timer = Timer(_toastEntry.duration, () {
......@@ -131,10 +146,12 @@ class FToast {
toastDuration ?? Duration(seconds: 2),
);
OverlayEntry newEntry = OverlayEntry(builder: (context) {
if (positionedToastBuilder != null) return positionedToastBuilder(context, newChild);
if (positionedToastBuilder != null)
return positionedToastBuilder(context, newChild);
return _getPostionWidgetBasedOnGravity(newChild, gravity);
});
_overlayQueue.add(_ToastEntry(entry: newEntry, duration: toastDuration ?? Duration(seconds: 2)));
_overlayQueue.add(_ToastEntry(
entry: newEntry, duration: toastDuration ?? Duration(seconds: 2)));
if (_timer == null) _showOverlay();
}
......@@ -150,7 +167,8 @@ class FToast {
return Positioned(top: 100.0, right: 24.0, child: child);
break;
case ToastGravity.CENTER:
return Positioned(top: 50.0, bottom: 50.0, left: 24.0, right: 24.0, child: child);
return Positioned(
top: 50.0, bottom: 50.0, left: 24.0, right: 24.0, child: child);
break;
case ToastGravity.CENTER_LEFT:
return Positioned(top: 50.0, bottom: 50.0, left: 24.0, child: child);
......@@ -165,7 +183,11 @@ class FToast {
return Positioned(bottom: 50.0, right: 24.0, child: child);
break;
case ToastGravity.SNACKBAR:
return Positioned(bottom: MediaQuery.of(context).viewInsets.bottom, left: 0, right: 0, child: child);
return Positioned(
bottom: MediaQuery.of(context).viewInsets.bottom,
left: 0,
right: 0,
child: child);
break;
case ToastGravity.BOTTOM:
default:
......@@ -191,7 +213,8 @@ class _ToastStateFul extends StatefulWidget {
ToastStateFulState createState() => ToastStateFulState();
}
class ToastStateFulState extends State<_ToastStateFul> with SingleTickerProviderStateMixin {
class ToastStateFulState extends State<_ToastStateFul>
with SingleTickerProviderStateMixin {
showIt() {
_animationController.forward();
}
......@@ -212,7 +235,8 @@ class ToastStateFulState extends State<_ToastStateFul> with SingleTickerProvider
vsync: this,
duration: const Duration(milliseconds: 350),
);
_fadeAnimation = CurvedAnimation(parent: _animationController, curve: Curves.easeIn);
_fadeAnimation =
CurvedAnimation(parent: _animationController, curve: Curves.easeIn);
super.initState();
showIt();
......
import 'dart:async';
import 'dart:html' as html;
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment