Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fluttertoast
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
songyanzhi
fluttertoast
Commits
bf984e85
Commit
bf984e85
authored
Jan 25, 2019
by
Karthik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2.2.8
parent
f5904128
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
111 additions
and
83 deletions
+111
-83
CHANGELOG.md
+5
-0
README.md
+8
-2
android/src/main/java/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.java
+60
-46
example/lib/main.dart
+16
-5
ios/Classes/FluttertoastPlugin.m
+7
-20
lib/fluttertoast.dart
+14
-9
pubspec.yaml
+1
-1
No files found.
CHANGELOG.md
View file @
bf984e85
## [2.2.8]
*
`Fluttertoast.cancel()`
added
*
FlutterToast Implementation revert back to previous
## [2.2.7]
## [2.2.7]
*
FontSize Can be changed
*
FontSize Can be changed
...
...
README.md
View file @
bf984e85
...
@@ -13,7 +13,7 @@ If your project uses androidx then use `fluttertoast` version `2.2.4` or `2.2.5`
...
@@ -13,7 +13,7 @@ If your project uses androidx then use `fluttertoast` version `2.2.4` or `2.2.5`
```
yaml
```
yaml
# add this line to your dependencies
# add this line to your dependencies
fluttertoast
:
^2.2.
7
fluttertoast
:
^2.2.
8
```
```
```
dart
```
dart
...
@@ -21,7 +21,7 @@ import 'package:fluttertoast/fluttertoast.dart';
...
@@ -21,7 +21,7 @@ import 'package:fluttertoast/fluttertoast.dart';
```
```
```
dart
```
dart
Fluttertoast
.
instance
.
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
,
...
@@ -43,6 +43,12 @@ textcolor| Colors.white
...
@@ -43,6 +43,12 @@ textcolor| Colors.white
fontSize | 16.0 (float)
fontSize | 16.0 (float)
### To cancel all the toasts call
```
dart
Fluttertoast
.
cancel
()
```
## Preview Images
## Preview Images
<img
src=
"https://raw.githubusercontent.com/PonnamKarthik/FlutterToast/master/screenshot/1.png"
width=
"320px"
/>
<img
src=
"https://raw.githubusercontent.com/PonnamKarthik/FlutterToast/master/screenshot/1.png"
width=
"320px"
/>
...
...
android/src/main/java/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.java
View file @
bf984e85
...
@@ -21,9 +21,10 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
...
@@ -21,9 +21,10 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
/** FluttertoastPlugin */
/** FluttertoastPlugin */
public
class
FluttertoastPlugin
implements
MethodCallHandler
{
public
class
FluttertoastPlugin
implements
MethodCallHandler
{
Context
ctx
;
private
Context
ctx
;
private
Toast
toast
=
null
;
FluttertoastPlugin
(
Context
context
)
{
private
FluttertoastPlugin
(
Context
context
)
{
ctx
=
context
;
ctx
=
context
;
}
}
...
@@ -35,7 +36,23 @@ public class FluttertoastPlugin implements MethodCallHandler {
...
@@ -35,7 +36,23 @@ public class FluttertoastPlugin implements MethodCallHandler {
@Override
@Override
public
void
onMethodCall
(
MethodCall
call
,
final
Result
result
)
{
public
void
onMethodCall
(
MethodCall
call
,
final
Result
result
)
{
if
(
call
.
method
.
equals
(
"showToast"
))
{
switch
(
call
.
method
)
{
case
"showToast"
:
showToast
(
call
,
result
);
break
;
case
"cancel"
:
if
(
toast
!=
null
)
{
toast
.
cancel
();
}
result
.
success
(
true
);
break
;
default
:
result
.
notImplemented
();
break
;
}
}
private
void
showToast
(
MethodCall
call
,
Result
result
)
{
String
msg
=
call
.
argument
(
"msg"
).
toString
();
String
msg
=
call
.
argument
(
"msg"
).
toString
();
String
length
=
call
.
argument
(
"length"
).
toString
();
String
length
=
call
.
argument
(
"length"
).
toString
();
String
gravity
=
call
.
argument
(
"gravity"
).
toString
();
String
gravity
=
call
.
argument
(
"gravity"
).
toString
();
...
@@ -44,33 +61,32 @@ public class FluttertoastPlugin implements MethodCallHandler {
...
@@ -44,33 +61,32 @@ public class FluttertoastPlugin implements MethodCallHandler {
Number
textSize
=
call
.
argument
(
"fontSize"
);
Number
textSize
=
call
.
argument
(
"fontSize"
);
final
Toast
toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
//Added to see if
toast
.
setText
(
msg
);
toast
.
setText
(
msg
);
if
(
length
.
equals
(
"long"
))
{
if
(
length
.
equals
(
"long"
))
{
toast
.
setDuration
(
Toast
.
LENGTH_LONG
);
toast
.
setDuration
(
Toast
.
LENGTH_LONG
);
}
else
{
}
else
{
toast
.
setDuration
(
Toast
.
LENGTH_SHORT
);
toast
.
setDuration
(
Toast
.
LENGTH_SHORT
);
}
}
Boolean
sent
=
false
;
// later
final
Handler
handler
=
new
Handler
();
// Boolean sent = false;
final
Runnable
run
=
new
Runnable
()
{
// final Handler handler = new Handler();
// final Runnable run = new Runnable() {
@Override
//
public
void
run
()
{
// @Override
try
{
// public void run() {
result
.
success
(
false
);
// try {
// result.success(false);
//
// } catch (Exception e){
// e.printStackTrace();
// }
// }
// };
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
};
switch
(
gravity
)
{
switch
(
gravity
)
{
case
"top"
:
case
"top"
:
...
@@ -81,14 +97,14 @@ public class FluttertoastPlugin implements MethodCallHandler {
...
@@ -81,14 +97,14 @@ public class FluttertoastPlugin implements MethodCallHandler {
break
;
break
;
default
:
default
:
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
);
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
);
}
}
final
TextView
text
=
toast
.
getView
().
findViewById
(
android
.
R
.
id
.
message
);
final
TextView
text
=
toast
.
getView
().
findViewById
(
android
.
R
.
id
.
message
);
text
.
setTextSize
(
textSize
.
floatValue
());
text
.
setTextSize
(
textSize
.
floatValue
());
text
.
setMaxLines
(
1
);
text
.
setMaxLines
(
1
);
if
(
bgcolor
!=
null
)
{
if
(
bgcolor
!=
null
)
{
Drawable
shapeDrawable
=
ContextCompat
.
getDrawable
(
ctx
,
R
.
drawable
.
toast_bg
);
Drawable
shapeDrawable
=
ContextCompat
.
getDrawable
(
ctx
,
R
.
drawable
.
toast_bg
);
if
(
shapeDrawable
!=
null
)
{
if
(
shapeDrawable
!=
null
)
{
...
@@ -101,33 +117,31 @@ public class FluttertoastPlugin implements MethodCallHandler {
...
@@ -101,33 +117,31 @@ public class FluttertoastPlugin implements MethodCallHandler {
}
}
}
}
text
.
setOnTouchListener
(
new
View
.
OnTouchListener
()
{
//later
@Override
// text.setOnTouchListener(new View.OnTouchListener() {
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
// @Override
handler
.
removeCallbacks
(
run
);
// public boolean onTouch(View v, MotionEvent event) {
text
.
setOnTouchListener
(
null
);
// handler.removeCallbacks(run);
toast
.
cancel
();
// text.setOnTouchListener(null);
try
{
// toast.cancel();
// try {
result
.
success
(
true
);
//
// result.success(true);
}
catch
(
Exception
e
){
//
e
.
printStackTrace
();
// } catch (Exception e){
}
// e.printStackTrace();
// }
return
false
;
//
}
// return false;
});
// }
// });
if
(
textcolor
!=
null
)
{
if
(
textcolor
!=
null
)
{
text
.
setTextColor
(
textcolor
.
intValue
());
text
.
setTextColor
(
textcolor
.
intValue
());
}
}
toast
.
show
();
toast
.
show
();
handler
.
postDelayed
(
run
,
toast
.
getDuration
()*
1000
);
result
.
success
(
true
);
// handler.postDelayed(run,toast.getDuration()*1000);
}
else
{
result
.
notImplemented
();
}
}
}
}
}
example/lib/main.dart
View file @
bf984e85
...
@@ -15,14 +15,14 @@ class _MyAppState extends State<MyApp> {
...
@@ -15,14 +15,14 @@ class _MyAppState extends State<MyApp> {
}
}
void
showLongToast
()
{
void
showLongToast
()
{
Fluttertoast
.
instance
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Long Toast"
,
msg:
"This is Long Toast"
,
toastLength:
Toast
.
LENGTH_LONG
,
toastLength:
Toast
.
LENGTH_LONG
,
);
);
}
}
void
showColoredToast
()
{
void
showColoredToast
()
{
Fluttertoast
.
instance
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Colored Toast"
,
msg:
"This is Colored Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
toastLength:
Toast
.
LENGTH_SHORT
,
backgroundColor:
Colors
.
red
,
backgroundColor:
Colors
.
red
,
...
@@ -30,14 +30,14 @@ class _MyAppState extends State<MyApp> {
...
@@ -30,14 +30,14 @@ class _MyAppState extends State<MyApp> {
}
}
void
showShortToast
()
{
void
showShortToast
()
{
Fluttertoast
.
instance
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Short Toast"
,
msg:
"This is Short Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
toastLength:
Toast
.
LENGTH_SHORT
,
timeInSecForIos:
1
);
timeInSecForIos:
1
);
}
}
void
showTopShortToast
()
{
void
showTopShortToast
()
{
Fluttertoast
.
instance
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Top Short Toast"
,
msg:
"This is Top Short Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
toastLength:
Toast
.
LENGTH_SHORT
,
gravity:
ToastGravity
.
TOP
,
gravity:
ToastGravity
.
TOP
,
...
@@ -45,13 +45,17 @@ class _MyAppState extends State<MyApp> {
...
@@ -45,13 +45,17 @@ class _MyAppState extends State<MyApp> {
}
}
void
showCenterShortToast
()
{
void
showCenterShortToast
()
{
Fluttertoast
.
instance
.
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
);
timeInSecForIos:
1
);
}
}
void
cancelToast
()
{
Fluttertoast
.
cancel
();
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
new
MaterialApp
(
return
new
MaterialApp
(
...
@@ -92,6 +96,13 @@ class _MyAppState extends State<MyApp> {
...
@@ -92,6 +96,13 @@ class _MyAppState extends State<MyApp> {
child:
new
Text
(
'Show Colored Toast'
),
child:
new
Text
(
'Show Colored Toast'
),
onPressed:
showColoredToast
),
onPressed:
showColoredToast
),
),
),
new
Padding
(
padding:
const
EdgeInsets
.
all
(
10.0
),
child:
new
RaisedButton
(
child:
new
Text
(
'Cancel Toasts'
),
onPressed:
cancelToast
,
),
),
],
],
),
),
),
),
...
...
ios/Classes/FluttertoastPlugin.m
View file @
bf984e85
#import "FluttertoastPlugin.h"
#import "FluttertoastPlugin.h"
#import "UIView+Toast.h"
#import "UIView+Toast.h"
// #import <fluttertoast/fluttertoast-Swift.h>
static
NSString
*
const
CHANNEL_NAME
=
@"PonnamKarthik/fluttertoast"
;
static
NSString
*
const
CHANNEL_NAME
=
@"PonnamKarthik/fluttertoast"
;
...
@@ -37,7 +36,9 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
...
@@ -37,7 +36,9 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
}
}
-
(
void
)
handleMethodCall
:
(
FlutterMethodCall
*
)
call
result
:
(
FlutterResult
)
result
{
-
(
void
)
handleMethodCall
:
(
FlutterMethodCall
*
)
call
result
:
(
FlutterResult
)
result
{
if
([
@"showToast"
isEqualToString
:
call
.
method
])
{
if
([
@"cancel"
isEqualToString
:
call
.
method
])
{
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
hideAllToasts
];
}
else
if
([
@"showToast"
isEqualToString
:
call
.
method
])
{
NSString
*
msg
=
call
.
arguments
[
@"msg"
];
NSString
*
msg
=
call
.
arguments
[
@"msg"
];
NSString
*
gravity
=
call
.
arguments
[
@"gravity"
];
NSString
*
gravity
=
call
.
arguments
[
@"gravity"
];
NSString
*
durationTime
=
call
.
arguments
[
@"time"
];
NSString
*
durationTime
=
call
.
arguments
[
@"time"
];
...
@@ -68,35 +69,21 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
...
@@ -68,35 +69,21 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
duration
:
time
duration
:
time
position
:
CSToastPositionTop
position
:
CSToastPositionTop
style
:
style
style
:
style
completion
:^
(
BOOL
didTap
){
];
NSNumber
*
boolNumber
=
[
NSNumber
numberWithBool
:
didTap
];
result
(
boolNumber
);
}];
}
else
if
([
gravity
isEqualToString
:
@"center"
])
{
}
else
if
([
gravity
isEqualToString
:
@"center"
])
{
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
duration
:
time
duration
:
time
position
:
CSToastPositionCenter
position
:
CSToastPositionCenter
style
:
style
style
:
style
completion
:^
(
BOOL
didTap
){
];
NSNumber
*
boolNumber
=
[
NSNumber
numberWithBool
:
didTap
];
result
(
boolNumber
);
}];
}
else
{
}
else
{
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
duration
:
time
duration
:
time
position
:
CSToastPositionBottom
position
:
CSToastPositionBottom
style
:
style
style
:
style
completion
:^
(
BOOL
didTap
){
];
NSNumber
*
boolNumber
=
[
NSNumber
numberWithBool
:
didTap
];
result
(
boolNumber
);
}];
}
}
result
(
true
)
}
else
{
}
else
{
result
(
FlutterMethodNotImplemented
);
result
(
FlutterMethodNotImplemented
);
...
...
lib/fluttertoast.dart
View file @
bf984e85
...
@@ -13,22 +13,27 @@ class Fluttertoast {
...
@@ -13,22 +13,27 @@ class Fluttertoast {
static
const
MethodChannel
_channel
=
static
const
MethodChannel
_channel
=
const
MethodChannel
(
'PonnamKarthik/fluttertoast'
);
const
MethodChannel
(
'PonnamKarthik/fluttertoast'
);
static
Fluttertoast
_instance
;
// for Version 3.x.x
static
Fluttertoast
get
instance
{
// static Fluttertoast _instance;
if
(
_instance
==
null
)
{
_instance
=
Fluttertoast
.
_create
();
}
return
_instance
;
}
// static Fluttertoast get instance {
// if (_instance == null) {
// _instance =Fluttertoast._create();
// }
// return _instance;
// }
// Fluttertoast._create(){
// }
Fluttertoast
.
_create
(){
static
Future
<
bool
>
cancel
()
async
{
bool
res
=
await
_channel
.
invokeMethod
(
"cancel"
);
return
res
;
}
}
Future
<
bool
>
showToast
({
static
Future
<
bool
>
showToast
({
@required
String
msg
,
@required
String
msg
,
Toast
toastLength
,
Toast
toastLength
,
int
timeInSecForIos
=
1
,
int
timeInSecForIos
=
1
,
...
...
pubspec.yaml
View file @
bf984e85
name
:
fluttertoast
name
:
fluttertoast
description
:
Toast Library for FLutter
description
:
Toast Library for FLutter
version
:
2.2.
7
version
:
2.2.
8
author
:
Karthik Ponnam <ponnamkarthik3@gmail.com>
author
:
Karthik Ponnam <ponnamkarthik3@gmail.com>
homepage
:
https://github.com/PonnamKarthik/FlutterToast
homepage
:
https://github.com/PonnamKarthik/FlutterToast
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment