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
00c74faa
Unverified
Commit
00c74faa
authored
Jan 21, 2019
by
Karthik Ponnam
Committed by
GitHub
Jan 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #50 from cqhchan/master
Added ability to register touch events and change font size
parents
d4bba0db
11503f43
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
130 additions
and
18 deletions
+130
-18
android/src/main/java/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.java
+46
-5
android/src/main/res/drawable/toast_bg.xml
+5
-4
ios/Classes/FluttertoastPlugin.m
+30
-5
ios/Classes/UIView+Toast.h
+20
-0
ios/Classes/UIView+Toast.m
+7
-2
lib/fluttertoast.dart
+22
-2
No files found.
android/src/main/java/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.java
View file @
00c74faa
...
...
@@ -4,7 +4,10 @@ import android.content.Context;
import
android.graphics.PorterDuff
;
import
android.graphics.drawable.Drawable
;
import
android.os.Build
;
import
android.os.Handler
;
import
android.view.Gravity
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.widget.TextView
;
import
android.widget.Toast
;
...
...
@@ -31,16 +34,19 @@ public class FluttertoastPlugin implements MethodCallHandler {
}
@Override
public
void
onMethodCall
(
MethodCall
call
,
Result
result
)
{
public
void
onMethodCall
(
MethodCall
call
,
final
Result
result
)
{
if
(
call
.
method
.
equals
(
"showToast"
))
{
String
msg
=
call
.
argument
(
"msg"
).
toString
();
String
length
=
call
.
argument
(
"length"
).
toString
();
String
gravity
=
call
.
argument
(
"gravity"
).
toString
();
Number
bgcolor
=
call
.
argument
(
"bgcolor"
);
Number
textcolor
=
call
.
argument
(
"textcolor"
);
Number
textSize
=
call
.
argument
(
"fontSize"
);
Toast
toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
final
Toast
toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
//Added to see if
toast
.
setText
(
msg
);
...
...
@@ -50,6 +56,22 @@ public class FluttertoastPlugin implements MethodCallHandler {
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
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
};
switch
(
gravity
)
{
case
"top"
:
toast
.
setGravity
(
Gravity
.
TOP
,
0
,
100
);
...
...
@@ -61,7 +83,10 @@ public class FluttertoastPlugin implements MethodCallHandler {
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
);
}
TextView
text
=
toast
.
getView
().
findViewById
(
android
.
R
.
id
.
message
);
final
TextView
text
=
toast
.
getView
().
findViewById
(
android
.
R
.
id
.
message
);
text
.
setTextSize
(
textSize
.
floatValue
());
text
.
setMaxLines
(
1
);
if
(
bgcolor
!=
null
)
{
Drawable
shapeDrawable
=
ContextCompat
.
getDrawable
(
ctx
,
R
.
drawable
.
toast_bg
);
...
...
@@ -76,14 +101,30 @@ 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
;
}
});
if
(
textcolor
!=
null
)
{
text
.
setTextColor
(
textcolor
.
intValue
());
}
toast
.
show
();
result
.
success
(
"Success"
);
handler
.
postDelayed
(
run
,
toast
.
getDuration
()*
1000
);
}
else
{
result
.
notImplemented
();
...
...
android/src/main/res/drawable/toast_bg.xml
View file @
00c74faa
...
...
@@ -7,8 +7,8 @@
android:color=
"#000000"
>
</solid>
<padding
android:left=
"
24
dp"
android:top=
"
15
dp"
android:right=
"
24
dp"
android:bottom=
"
15
dp"
/>
android:left=
"
10
dp"
android:top=
"
8
dp"
android:right=
"
10
dp"
android:bottom=
"
8
dp"
/>
</shape>
\ No newline at end of file
ios/Classes/FluttertoastPlugin.m
View file @
00c74faa
...
...
@@ -4,9 +4,13 @@
static
NSString
*
const
CHANNEL_NAME
=
@"PonnamKarthik/fluttertoast"
;
@interface
FluttertoastPlugin
()
@property
(
nonatomic
,
retain
)
FlutterMethodChannel
*
channel
;
@end
@implementation
FluttertoastPlugin
{
FlutterResult
_result
;
}
+
(
void
)
registerWithRegistrar
:
(
NSObject
<
FlutterPluginRegistrar
>
*
)
registrar
{
...
...
@@ -16,6 +20,7 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
UIViewController
*
viewController
=
[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
;
FluttertoastPlugin
*
instance
=
[[
FluttertoastPlugin
alloc
]
init
];
instance
.
channel
=
channel
;
[
registrar
addMethodCallDelegate
:
instance
channel
:
channel
];
}
...
...
@@ -38,7 +43,10 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
NSString
*
durationTime
=
call
.
arguments
[
@"time"
];
NSNumber
*
bgcolor
=
call
.
arguments
[
@"bgcolor"
];
NSNumber
*
textcolor
=
call
.
arguments
[
@"textcolor"
];
NSNumber
*
size
=
call
.
arguments
[
@"size"
];
NSNumber
*
fontSize
=
call
.
arguments
[
@"fontSize"
];
CGFloat
cgf
=
[
fontSize
doubleValue
];
int
time
=
1
;
@try
{
time
=
[
durationTime
intValue
];
...
...
@@ -51,7 +59,7 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
CSToastStyle
*
style
=
[[
CSToastStyle
alloc
]
initWithDefaultStyle
];
style
.
messageFont
=
[
UIFont
systemFontOfSize
:
cgf
];
style
.
backgroundColor
=
[
self
colorWithHex
:
bgcolor
.
unsignedIntegerValue
];
style
.
messageColor
=
[
self
colorWithHex
:
textcolor
.
unsignedIntegerValue
];
...
...
@@ -59,20 +67,37 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
duration
:
time
position
:
CSToastPositionTop
style
:
style
];
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
];
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
];
style
:
style
completion
:^
(
BOOL
didTap
){
NSNumber
*
boolNumber
=
[
NSNumber
numberWithBool
:
didTap
];
result
(
boolNumber
);
}];
}
result
(
@"done"
);
}
else
{
result
(
FlutterMethodNotImplemented
);
}
...
...
ios/Classes/UIView+Toast.h
View file @
00c74faa
...
...
@@ -89,6 +89,26 @@ extern const NSString * CSToastPositionBottom;
@param duration The toast duration
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param style The style. The shared style will be used when nil
@param completion The completion block, executed after the toast view disappears.
didTap will be `YES` if the toast view was dismissed from a tap.
*/
-
(
void
)
makeToast
:(
NSString
*
)
message
duration
:(
NSTimeInterval
)
duration
position
:(
id
)
position
style
:(
CSToastStyle
*
)
style
completion
:(
void
(
^
)(
BOOL
didTap
))
completion
;
/**
Creates and presents a new toast view with a message, title, and image. Duration,
position, and style can be set explicitly. The completion block executes when the
toast view completes. `didTap` will be `YES` if the toast view was dismissed from
a tap.
@param message The message to be displayed
@param duration The toast duration
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param title The title
@param image The image
@param style The style. The shared style will be used when nil
...
...
ios/Classes/UIView+Toast.m
View file @
00c74faa
...
...
@@ -80,6 +80,11 @@ static const NSString * CSToastQueueKey = @"CSToastQueueKey";
[
self
showToast
:
toast
duration
:
duration
position
:
position
completion
:
nil
];
}
-
(
void
)
makeToast
:(
NSString
*
)
message
duration
:(
NSTimeInterval
)
duration
position
:(
id
)
position
style
:(
CSToastStyle
*
)
style
completion
:(
void
(
^
)(
BOOL
didTap
))
completion
{
UIView
*
toast
=
[
self
toastViewForMessage
:
message
title
:
nil
image
:
nil
style
:
style
];
[
self
showToast
:
toast
duration
:
duration
position
:
position
completion
:
completion
];
}
-
(
void
)
makeToast
:(
NSString
*
)
message
duration
:(
NSTimeInterval
)
duration
position
:(
id
)
position
title
:(
NSString
*
)
title
image
:(
UIImage
*
)
image
style
:(
CSToastStyle
*
)
style
completion
:(
void
(
^
)(
BOOL
didTap
))
completion
{
UIView
*
toast
=
[
self
toastViewForMessage
:
message
title
:
title
image
:
image
style
:
style
];
[
self
showToast
:
toast
duration
:
duration
position
:
position
completion
:
completion
];
...
...
@@ -470,14 +475,14 @@ static const NSString * CSToastQueueKey = @"CSToastQueueKey";
self
.
maxWidthPercentage
=
0
.
8
;
self
.
maxHeightPercentage
=
0
.
8
;
self
.
horizontalPadding
=
10
.
0
;
self
.
verticalPadding
=
10
.
0
;
self
.
verticalPadding
=
8
.
0
;
self
.
cornerRadius
=
10
.
0
;
self
.
titleFont
=
[
UIFont
boldSystemFontOfSize
:
16
.
0
];
self
.
messageFont
=
[
UIFont
systemFontOfSize
:
16
.
0
];
self
.
titleAlignment
=
NSTextAlignmentLeft
;
self
.
messageAlignment
=
NSTextAlignmentLeft
;
self
.
titleNumberOfLines
=
0
;
self
.
messageNumberOfLines
=
0
;
self
.
messageNumberOfLines
=
1
;
self
.
displayShadow
=
NO
;
self
.
shadowOpacity
=
0
.
8
;
self
.
shadowRadius
=
6
.
0
;
...
...
lib/fluttertoast.dart
View file @
00c74faa
...
...
@@ -13,14 +13,32 @@ class Fluttertoast {
static
const
MethodChannel
_channel
=
const
MethodChannel
(
'PonnamKarthik/fluttertoast'
);
static
Future
<
String
>
showToast
({
static
Fluttertoast
_instance
;
static
Fluttertoast
get
instance
{
if
(
_instance
==
null
)
{
_instance
=
Fluttertoast
.
_create
();
}
return
_instance
;
}
Fluttertoast
.
_create
(){
}
Future
<
bool
>
showToast
({
@required
String
msg
,
Toast
toastLength
,
int
timeInSecForIos
=
1
,
double
fontSize
=
16.0
,
ToastGravity
gravity
,
Color
backgroundColor
,
Color
textColor
,
// Function(bool) didTap,
})
async
{
// this.didTap = didTap;
String
toast
=
"short"
;
if
(
toastLength
==
Toast
.
LENGTH_LONG
)
{
toast
=
"long"
;
...
...
@@ -48,9 +66,11 @@ class Fluttertoast {
'gravity'
:
gravityToast
,
'bgcolor'
:
backgroundColor
!=
null
?
backgroundColor
.
value
:
null
,
'textcolor'
:
textColor
!=
null
?
textColor
.
value
:
null
,
'fontSize'
:
fontSize
,
};
String
res
=
await
_channel
.
invokeMethod
(
'showToast'
,
params
);
bool
res
=
await
_channel
.
invokeMethod
(
'showToast'
,
params
);
return
res
;
}
}
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