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