Commit 6df57b14 by Ponnam Karthik

Added iOS Support

parent ecfaee70
## [2.0.1]
* Ios Support added
* option for setting toast gravity (top, center, bottom)
## [1.0.1] ## [1.0.1]
* Initial Open Sources * Initial Open Sources
......
# fluttertoast # [fluttertoast](https://pub.dartlang.org/packages/fluttertoast)
Android Toast Library for Flutter Android Toast Library for Flutter
> Supported Platforms
> * Android
> * IOS
## How to Use ## How to Use
```yaml ```yaml
# add this line to your dependencies # add this line to your dependencies
fluttertoast: ^1.0.1 fluttertoast: ^2.0.1
``` ```
```dart ```dart
Fluttertoast.showToast("Toast Text", <Toast Length>); Fluttertoast.showToast(
msg: "This is Center Short Toast",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIos: 1
);
``` ```
Toast Length can be property | description
--------|------------
```dart msg | String (Not Null)(required)
Toast.LENGTH_SHORT toastLength| Toast.LENGTH_SHORT or Toast.LENGTH_LONG (optional)
gravity | ToastGravity.TOP (or) ToastGravity.CENTER (or) ToastGravity.BOTTOM
or timeInSecForIos | int (only for ios)
Toast.LENGTH_LONG
```
...@@ -13,33 +13,37 @@ class _MyAppState extends State<MyApp> { ...@@ -13,33 +13,37 @@ class _MyAppState extends State<MyApp> {
@override @override
initState() { initState() {
super.initState(); super.initState();
} }
void showLongToast() { void showLongToast() {
Fluttertoast.showToast( Fluttertoast.showToast(
msg: "This is Long Toast", msg: "This is Long Toast",
toastLength: Toast.LENGTH_LONG, toastLength: Toast.LENGTH_LONG,
); );
} }
void showShortToast() { void showShortToast() {
Fluttertoast.showToast( Fluttertoast.showToast(
msg: "This is Long Toast", msg: "This is Long Toast",
toastLength: Toast.LENGTH_SHORT, toastLength: Toast.LENGTH_SHORT,
timeInSecForIos: 1
); );
} }
void showTopShortToast() { void showTopShortToast() {
Fluttertoast.showToast( Fluttertoast.showToast(
msg: "This is Top Long Toast", msg: "This is Top Long Toast",
toastLength: Toast.LENGTH_SHORT, toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.TOP gravity: ToastGravity.TOP,
timeInSecForIos: 1
); );
} }
void showCenterShortToast() { void showCenterShortToast() {
Fluttertoast.showToast( Fluttertoast.showToast(
msg: "This is Center Short Toast", msg: "This is Center Short Toast",
toastLength: Toast.LENGTH_SHORT, toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER gravity: ToastGravity.CENTER,
timeInSecForIos: 1
); );
} }
...@@ -87,4 +91,4 @@ class _MyAppState extends State<MyApp> { ...@@ -87,4 +91,4 @@ class _MyAppState extends State<MyApp> {
), ),
); );
} }
} }
\ No newline at end of file
...@@ -26,22 +26,28 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast"; ...@@ -26,22 +26,28 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
NSString *gravity = call.arguments[@"gravity"]; NSString *gravity = call.arguments[@"gravity"];
NSString *durationTime = call.arguments[@"time"]; NSString *durationTime = call.arguments[@"time"];
if([gravity isEqualToString:@"top"]) {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg if((durationTime == (id)[NSNull null] || durationTime.length == 0 )) {
duration: [durationTime intValue]
position:CSToastPositionTop];
} else if([gravity isEqualToString:@"center"]) {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg [[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: [durationTime intValue] duration: 3
position:CSToastPositionCenter]; position:CSToastPositionBottom];
} else { } else {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg if([gravity isEqualToString:@"top"]) {
duration: [durationTime intValue] [[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
position:CSToastPositionBottom]; duration: [durationTime intValue]
position:CSToastPositionTop];
} else if([gravity isEqualToString:@"center"]) {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: [durationTime intValue]
position:CSToastPositionCenter];
} else {
[[UIApplication sharedApplication].delegate.window.rootViewController.view makeToast:msg
duration: [durationTime intValue]
position:CSToastPositionBottom];
}
} }
result(@"done");
_result = result;
} else { } else {
result(FlutterMethodNotImplemented); result(FlutterMethodNotImplemented);
} }
......
import 'dart:async';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
...@@ -17,14 +19,14 @@ enum ToastGravity { ...@@ -17,14 +19,14 @@ enum ToastGravity {
class Fluttertoast { class Fluttertoast {
static const MethodChannel _channel = static const MethodChannel _channel =
const MethodChannel('PonnamKarthik/fluttertoast'); const MethodChannel('PonnamKarthik/fluttertoast');
static void showToast({ static Future<String> showToast ({
@required String msg, @required String msg,
Toast toastLength, Toast toastLength,
int timeInSecForIos, int timeInSecForIos,
ToastGravity gravity ToastGravity gravity
}) { }) async {
String toast = "short"; String toast = "short";
if(toastLength == Toast.LENGTH_LONG) { if(toastLength == Toast.LENGTH_LONG) {
toast = "long"; toast = "long";
...@@ -45,8 +47,8 @@ class Fluttertoast { ...@@ -45,8 +47,8 @@ class Fluttertoast {
'time': timeInSecForIos, 'time': timeInSecForIos,
'gravity': gravityToast 'gravity': gravityToast
}; };
_channel.invokeMethod('showToast', params); String res = await _channel.invokeMethod('showToast', params);
return res;
} }
} }
\ No newline at end of file
name: fluttertoast name: fluttertoast
description: Toast Library for FLutter description: Toast Library for FLutter
version: 1.0.1 version: 2.0.1
author: Karthik Ponnam <ponnamkarthik3@gmail.com> author: Karthik Ponnam <ponnamkarthik3@gmail.com>
homepage: https://github.com/PonnamKarthik/FlutterToast homepage: https://github.com/PonnamKarthik/FlutterToast
......
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