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
ecfaee70
Commit
ecfaee70
authored
Apr 20, 2018
by
Ponnam Karthik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added iOS Support
parent
4cd5b4d1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
35 deletions
+102
-35
android/src/main/kotlin/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.kt
+16
-2
example/lib/main.dart
+36
-2
ios/Classes/FluttertoastPlugin.m
+24
-29
lib/fluttertoast.dart
+26
-2
No files found.
android/src/main/kotlin/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.kt
View file @
ecfaee70
...
@@ -2,6 +2,7 @@ package io.github.ponnamkarthik.toast.fluttertoast
...
@@ -2,6 +2,7 @@ package io.github.ponnamkarthik.toast.fluttertoast
import
android.content.Context
import
android.content.Context
import
android.util.Log
import
android.util.Log
import
android.view.Gravity
import
android.widget.Toast
import
android.widget.Toast
import
io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
...
@@ -28,13 +29,26 @@ class FluttertoastPlugin(context: Context): MethodCallHandler {
...
@@ -28,13 +29,26 @@ class FluttertoastPlugin(context: Context): MethodCallHandler {
if
(
call
.
method
.
equals
(
"showToast"
))
{
if
(
call
.
method
.
equals
(
"showToast"
))
{
val
msg
:
String
=
call
.
argument
(
"msg"
)
val
msg
:
String
=
call
.
argument
(
"msg"
)
val
length
:
String
=
call
.
argument
(
"length"
)
val
length
:
String
=
call
.
argument
(
"length"
)
val
gravity
:
String
=
call
.
argument
(
"gravity"
)
var
toast
:
Toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
if
(
length
.
equals
(
"long"
))
{
if
(
length
.
equals
(
"long"
))
{
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_LONG
).
show
()
toast
.
duration
=
Toast
.
LENGTH_LONG
}
else
{
}
else
{
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
).
show
()
toast
.
duration
=
Toast
.
LENGTH_SHORT
}
}
if
(
gravity
.
equals
(
"top"
))
{
toast
.
setGravity
(
Gravity
.
TOP
,
0
,
100
)
}
else
if
(
gravity
.
equals
(
"center"
))
{
toast
.
setGravity
(
Gravity
.
CENTER
,
0
,
0
)
}
else
{
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
)
}
toast
.
show
()
result
.
success
(
"Success"
)
result
.
success
(
"Success"
)
}
else
{
}
else
{
result
.
notImplemented
()
result
.
notImplemented
()
...
...
example/lib/main.dart
View file @
ecfaee70
...
@@ -16,11 +16,31 @@ class _MyAppState extends State<MyApp> {
...
@@ -16,11 +16,31 @@ class _MyAppState extends State<MyApp> {
}
}
void
showLongToast
()
{
void
showLongToast
()
{
Fluttertoast
.
showToast
(
"This is Long Toast"
,
Toast
.
LENGTH_LONG
);
Fluttertoast
.
showToast
(
msg:
"This is Long Toast"
,
toastLength:
Toast
.
LENGTH_LONG
,
);
}
}
void
showShortToast
()
{
void
showShortToast
()
{
Fluttertoast
.
showToast
(
"This is Short Toast"
,
Toast
.
LENGTH_SHORT
);
Fluttertoast
.
showToast
(
msg:
"This is Long Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
);
}
void
showTopShortToast
()
{
Fluttertoast
.
showToast
(
msg:
"This is Top Long Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
gravity:
ToastGravity
.
TOP
);
}
void
showCenterShortToast
()
{
Fluttertoast
.
showToast
(
msg:
"This is Center Short Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
gravity:
ToastGravity
.
CENTER
);
}
}
@override
@override
...
@@ -47,6 +67,20 @@ class _MyAppState extends State<MyApp> {
...
@@ -47,6 +67,20 @@ class _MyAppState extends State<MyApp> {
onPressed:
showShortToast
onPressed:
showShortToast
),
),
),
),
new
Padding
(
padding:
const
EdgeInsets
.
all
(
10.0
),
child:
new
RaisedButton
(
child:
new
Text
(
'Show Center Short Toast'
),
onPressed:
showCenterShortToast
),
),
new
Padding
(
padding:
const
EdgeInsets
.
all
(
10.0
),
child:
new
RaisedButton
(
child:
new
Text
(
'Show Top Short Toast'
),
onPressed:
showTopShortToast
),
),
],
],
),
),
),
),
...
...
ios/Classes/FluttertoastPlugin.m
View file @
ecfaee70
...
@@ -2,15 +2,10 @@
...
@@ -2,15 +2,10 @@
#import "UIView+Toast.h"
#import "UIView+Toast.h"
// #import <fluttertoast/fluttertoast-Swift.h>
// #import <fluttertoast/fluttertoast-Swift.h>
@interface
QRCodeReaderPlugin
()
static
NSString
*
const
CHANNEL_NAME
=
@"PonnamKarthik/fluttertoast"
;
@property
(
nonatomic
,
strong
)
UIView
*
toastview
;
@property
(
nonatomic
,
retain
)
UIViewController
*
viewController
;
@property
(
nonatomic
,
retain
)
UIViewController
*
toastViewController
;
@end
@implementation
FluttertoastPlugin
{
@implementation
FluttertoastPlugin
{
FlutterResult
_result
;
FlutterResult
_result
;
UIViewController
*
_viewController
;
}
}
...
@@ -18,44 +13,43 @@
...
@@ -18,44 +13,43 @@
FlutterMethodChannel
*
channel
=
[
FlutterMethodChannel
FlutterMethodChannel
*
channel
=
[
FlutterMethodChannel
methodChannelWithName
:
CHANNEL_NAME
methodChannelWithName
:
CHANNEL_NAME
binaryMessenger
:[
registrar
messenger
]];
binaryMessenger
:[
registrar
messenger
]];
// UIViewController *viewController = (UIViewController *)registrar.messenger;
UIViewController
*
viewController
=
UIViewController
*
viewController
=
[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
;
[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
;
FluttertoastPlugin
*
instance
=
[[
FluttertoastPlugin
alloc
]
init
WithViewController
:
viewController
];
FluttertoastPlugin
*
instance
=
[[
FluttertoastPlugin
alloc
]
init
];
[
registrar
addMethodCallDelegate
:
instance
channel
:
channel
];
[
registrar
addMethodCallDelegate
:
instance
channel
:
channel
];
}
}
-
(
void
)
handleMethodCall
:
(
FlutterMethodCall
*
)
call
result
:
(
FlutterResult
)
result
{
-
(
void
)
handleMethodCall
:
(
FlutterMethodCall
*
)
call
result
:
(
FlutterResult
)
result
{
if
([
@"showToast"
isEqualToString
:
call
.
method
])
{
if
([
@"showToast"
isEqualToString
:
call
.
method
])
{
[
self
showToastView
:
call
];
NSString
*
msg
=
call
.
arguments
[
@"msg"
];
_result
=
result
;
NSString
*
gravity
=
call
.
arguments
[
@"gravity"
];
NSString
*
durationTime
=
call
.
arguments
[
@"time"
];
if
([
gravity
isEqualToString
:
@"top"
])
{
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
duration
:
[
durationTime
intValue
]
position
:
CSToastPositionTop
];
}
else
if
([
gravity
isEqualToString
:
@"center"
])
{
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
duration
:
[
durationTime
intValue
]
position
:
CSToastPositionCenter
];
}
else
{
}
else
{
result
(
FlutterMethodNotImplemented
);
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
duration
:
[
durationTime
intValue
]
position
:
CSToastPositionBottom
];
}
}
}
-
(
instancetype
)
initWithViewController
:
(
UIViewController
*
)
viewController
{
self
=
[
super
init
];
_result
=
result
;
if
(
self
)
{
}
else
{
_viewController
=
viewController
;
result
(
FlutterMethodNotImplemented
);
//_viewController.view.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.0];
_viewController
.
view
.
backgroundColor
=
[
UIColor
clearColor
];
_viewController
.
view
.
opaque
=
NO
;
[[
NSNotificationCenter
defaultCenter
]
addObserver
:
self
selector
:
@selector
(
rotate
:
)
name
:
UIDeviceOrientationDidChangeNotification
object
:
nil
];
}
}
return
self
;
}
}
-
(
void
)
showToastView
:
(
FlutterMethodCall
*
)
call
{
_toastViewController
=
[[
UIViewController
alloc
]
init
];
[
_viewController
presentViewController
:
_toastViewController
animated
:
NO
completion
:
nil
];
_toastview
=
[[
UIView
alloc
]
init
];
_toastViewController
.
view
=
_toastview
;
[
self
.
view
makeToast
:
@"This is a piece of toast."
];
-
(
void
)
showToastView
:
(
FlutterMethodCall
*
)
call
:
(
NSString
*
)
msg
{
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
];
}
}
@end
@end
\ No newline at end of file
lib/fluttertoast.dart
View file @
ecfaee70
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
import
'package:meta/meta.dart'
;
enum
Toast
{
enum
Toast
{
...
@@ -6,20 +7,43 @@ enum Toast {
...
@@ -6,20 +7,43 @@ enum Toast {
LENGTH_LONG
LENGTH_LONG
}
}
enum
ToastGravity
{
TOP
,
BOTTOM
,
CENTER
}
class
Fluttertoast
{
class
Fluttertoast
{
static
const
MethodChannel
_channel
=
static
const
MethodChannel
_channel
=
const
MethodChannel
(
'PonnamKarthik/fluttertoast'
);
const
MethodChannel
(
'PonnamKarthik/fluttertoast'
);
static
void
showToast
(
String
msg
,
Toast
toastLength
)
{
static
void
showToast
({
@required
String
msg
,
Toast
toastLength
,
int
timeInSecForIos
,
ToastGravity
gravity
})
{
String
toast
=
"short"
;
String
toast
=
"short"
;
if
(
toastLength
==
Toast
.
LENGTH_LONG
)
{
if
(
toastLength
==
Toast
.
LENGTH_LONG
)
{
toast
=
"long"
;
toast
=
"long"
;
}
}
String
gravityToast
=
"bottom"
;
if
(
gravity
==
ToastGravity
.
TOP
)
{
gravityToast
=
"top"
;
}
else
if
(
gravity
==
ToastGravity
.
CENTER
)
{
gravityToast
=
"center"
;
}
else
{
gravityToast
=
"bottom"
;
}
final
Map
<
String
,
dynamic
>
params
=
<
String
,
dynamic
>
{
final
Map
<
String
,
dynamic
>
params
=
<
String
,
dynamic
>
{
'msg'
:
msg
,
'msg'
:
msg
,
'length'
:
toast
'length'
:
toast
,
'time'
:
timeInSecForIos
,
'gravity'
:
gravityToast
};
};
_channel
.
invokeMethod
(
'showToast'
,
params
);
_channel
.
invokeMethod
(
'showToast'
,
params
);
}
}
...
...
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