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]
*
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`
```
yaml
# add this line to your dependencies
fluttertoast
:
^2.2.
7
fluttertoast
:
^2.2.
8
```
```
dart
...
...
@@ -21,7 +21,7 @@ import 'package:fluttertoast/fluttertoast.dart';
```
```
dart
Fluttertoast
.
instance
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Center Short Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
gravity:
ToastGravity
.
CENTER
,
...
...
@@ -43,6 +43,12 @@ textcolor| Colors.white
fontSize | 16.0 (float)
### To cancel all the toasts call
```
dart
Fluttertoast
.
cancel
()
```
## Preview Images
<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;
/** FluttertoastPlugin */
public
class
FluttertoastPlugin
implements
MethodCallHandler
{
Context
ctx
;
private
Context
ctx
;
private
Toast
toast
=
null
;
FluttertoastPlugin
(
Context
context
)
{
private
FluttertoastPlugin
(
Context
context
)
{
ctx
=
context
;
}
...
...
@@ -35,7 +36,23 @@ public class FluttertoastPlugin implements MethodCallHandler {
@Override
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
length
=
call
.
argument
(
"length"
).
toString
();
String
gravity
=
call
.
argument
(
"gravity"
).
toString
();
...
...
@@ -44,33 +61,32 @@ public class FluttertoastPlugin implements MethodCallHandler {
Number
textSize
=
call
.
argument
(
"fontSize"
);
final
Toast
toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
//Added to see if
toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
toast
.
setText
(
msg
);
if
(
length
.
equals
(
"long"
))
{
toast
.
setDuration
(
Toast
.
LENGTH_LONG
);
toast
.
setDuration
(
Toast
.
LENGTH_LONG
);
}
else
{
toast
.
setDuration
(
Toast
.
LENGTH_SHORT
);
toast
.
setDuration
(
Toast
.
LENGTH_SHORT
);
}
Boolean
sent
=
false
;
final
Handler
handler
=
new
Handler
();
final
Runnable
run
=
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
result
.
success
(
false
);
// later
// Boolean sent = false;
// final Handler handler = new Handler();
// final Runnable run = new Runnable() {
//
// @Override
// public void run() {
// try {
// result.success(false);
//
// } catch (Exception e){
// e.printStackTrace();
// }
// }
// };
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
};
switch
(
gravity
)
{
case
"top"
:
...
...
@@ -81,14 +97,14 @@ public class FluttertoastPlugin implements MethodCallHandler {
break
;
default
:
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
);
}
}
final
TextView
text
=
toast
.
getView
().
findViewById
(
android
.
R
.
id
.
message
);
text
.
setTextSize
(
textSize
.
floatValue
());
text
.
setMaxLines
(
1
);
if
(
bgcolor
!=
null
)
{
if
(
bgcolor
!=
null
)
{
Drawable
shapeDrawable
=
ContextCompat
.
getDrawable
(
ctx
,
R
.
drawable
.
toast_bg
);
if
(
shapeDrawable
!=
null
)
{
...
...
@@ -101,33 +117,31 @@ public class FluttertoastPlugin implements MethodCallHandler {
}
}
text
.
setOnTouchListener
(
new
View
.
OnTouchListener
()
{
@Override
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
handler
.
removeCallbacks
(
run
);
text
.
setOnTouchListener
(
null
);
toast
.
cancel
();
try
{
result
.
success
(
true
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
false
;
}
});
//later
// text.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// handler.removeCallbacks(run);
// text.setOnTouchListener(null);
// toast.cancel();
// try {
//
// result.success(true);
//
// } catch (Exception e){
// e.printStackTrace();
// }
//
// return false;
// }
// });
if
(
textcolor
!=
null
)
{
text
.
setTextColor
(
textcolor
.
intValue
());
}
toast
.
show
();
handler
.
postDelayed
(
run
,
toast
.
getDuration
()*
1000
);
}
else
{
result
.
notImplemented
();
}
result
.
success
(
true
);
// handler.postDelayed(run,toast.getDuration()*1000);
}
}
example/lib/main.dart
View file @
bf984e85
...
...
@@ -15,14 +15,14 @@ class _MyAppState extends State<MyApp> {
}
void
showLongToast
()
{
Fluttertoast
.
instance
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Long Toast"
,
toastLength:
Toast
.
LENGTH_LONG
,
);
}
void
showColoredToast
()
{
Fluttertoast
.
instance
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Colored Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
backgroundColor:
Colors
.
red
,
...
...
@@ -30,14 +30,14 @@ class _MyAppState extends State<MyApp> {
}
void
showShortToast
()
{
Fluttertoast
.
instance
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Short Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
timeInSecForIos:
1
);
}
void
showTopShortToast
()
{
Fluttertoast
.
instance
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Top Short Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
gravity:
ToastGravity
.
TOP
,
...
...
@@ -45,13 +45,17 @@ class _MyAppState extends State<MyApp> {
}
void
showCenterShortToast
()
{
Fluttertoast
.
instance
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Center Short Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
gravity:
ToastGravity
.
CENTER
,
timeInSecForIos:
1
);
}
void
cancelToast
()
{
Fluttertoast
.
cancel
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
new
MaterialApp
(
...
...
@@ -92,6 +96,13 @@ class _MyAppState extends State<MyApp> {
child:
new
Text
(
'Show Colored Toast'
),
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 "UIView+Toast.h"
// #import <fluttertoast/fluttertoast-Swift.h>
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
{
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
*
gravity
=
call
.
arguments
[
@"gravity"
];
NSString
*
durationTime
=
call
.
arguments
[
@"time"
];
...
...
@@ -68,35 +69,21 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
duration
:
time
position
:
CSToastPositionTop
style
:
style
completion
:^
(
BOOL
didTap
){
NSNumber
*
boolNumber
=
[
NSNumber
numberWithBool
:
didTap
];
result
(
boolNumber
);
}];
];
}
else
if
([
gravity
isEqualToString
:
@"center"
])
{
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
duration
:
time
position
:
CSToastPositionCenter
style
:
style
completion
:^
(
BOOL
didTap
){
NSNumber
*
boolNumber
=
[
NSNumber
numberWithBool
:
didTap
];
result
(
boolNumber
);
}];
];
}
else
{
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
duration
:
time
position
:
CSToastPositionBottom
style
:
style
completion
:^
(
BOOL
didTap
){
NSNumber
*
boolNumber
=
[
NSNumber
numberWithBool
:
didTap
];
result
(
boolNumber
);
}];
];
}
result
(
true
)
}
else
{
result
(
FlutterMethodNotImplemented
);
...
...
lib/fluttertoast.dart
View file @
bf984e85
...
...
@@ -13,22 +13,27 @@ class Fluttertoast {
static
const
MethodChannel
_channel
=
const
MethodChannel
(
'PonnamKarthik/fluttertoast'
);
static
Fluttertoast
_instance
;
// for Version 3.x.x
static
Fluttertoast
get
instance
{
if
(
_instance
==
null
)
{
_instance
=
Fluttertoast
.
_create
();
}
return
_instance
;
}
// static Fluttertoast _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
,
Toast
toastLength
,
int
timeInSecForIos
=
1
,
...
...
pubspec.yaml
View file @
bf984e85
name
:
fluttertoast
description
:
Toast Library for FLutter
version
:
2.2.
7
version
:
2.2.
8
author
:
Karthik Ponnam <ponnamkarthik3@gmail.com>
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