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
ec1b3b26
Commit
ec1b3b26
authored
Jun 09, 2018
by
Ponnam Karthik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added color support for android
parent
dfa8c09c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
6 deletions
+85
-6
README.md
+6
-2
android/src/main/kotlin/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.kt
+39
-0
example/lib/main.dart
+16
-0
fluttertoast_android.iml
+3
-2
ios/Classes/FluttertoastPlugin.m
+15
-0
lib/fluttertoast.dart
+6
-2
No files found.
README.md
View file @
ec1b3b26
...
@@ -11,7 +11,7 @@ Android Toast Library for Flutter
...
@@ -11,7 +11,7 @@ Android Toast Library for Flutter
```
yaml
```
yaml
# add this line to your dependencies
# add this line to your dependencies
fluttertoast
:
^2.
0.3
fluttertoast
:
^2.
1.0
```
```
```
dart
```
dart
...
@@ -19,7 +19,9 @@ Fluttertoast.showToast(
...
@@ -19,7 +19,9 @@ 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
,
bgcolor:
"#e74c3c"
,
textcolor:
'#ffffff'
);
);
```
```
...
@@ -29,4 +31,6 @@ msg | String (Not Null)(required)
...
@@ -29,4 +31,6 @@ msg | String (Not Null)(required)
toastLength| Toast.LENGTH_SHORT or Toast.LENGTH_LONG (optional)
toastLength| Toast.LENGTH_SHORT or Toast.LENGTH_LONG (optional)
gravity | ToastGravity.TOP (or) ToastGravity.CENTER (or) ToastGravity.BOTTOM
gravity | ToastGravity.TOP (or) ToastGravity.CENTER (or) ToastGravity.BOTTOM
timeInSecForIos | int (only for ios)
timeInSecForIos | int (only for ios)
bgcolor | string (color in hex format)
textcolor: '#ffffff'
android/src/main/kotlin/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.kt
View file @
ec1b3b26
...
@@ -4,11 +4,22 @@ import android.content.Context
...
@@ -4,11 +4,22 @@ import android.content.Context
import
android.util.Log
import
android.util.Log
import
android.view.Gravity
import
android.view.Gravity
import
android.widget.Toast
import
android.widget.Toast
import
android.graphics.Color
import
android.graphics.drawable.ColorDrawable
import
android.graphics.drawable.Drawable
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
import
io.flutter.plugin.common.MethodChannel.Result
import
io.flutter.plugin.common.MethodChannel.Result
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.PluginRegistry.Registrar
import
io.flutter.plugin.common.PluginRegistry.Registrar
import
android.widget.TextView
import
android.graphics.Paint
import
android.graphics.drawable.ShapeDrawable
import
android.graphics.drawable.shapes.RoundRectShape
class
FluttertoastPlugin
(
context
:
Context
):
MethodCallHandler
{
class
FluttertoastPlugin
(
context
:
Context
):
MethodCallHandler
{
...
@@ -30,6 +41,8 @@ class FluttertoastPlugin(context: Context): MethodCallHandler {
...
@@ -30,6 +41,8 @@ class FluttertoastPlugin(context: Context): MethodCallHandler {
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"
)
val
gravity
:
String
=
call
.
argument
(
"gravity"
)
val
bgcolor
:
String
=
call
.
argument
(
"bgcolor"
)
val
textcolor
:
String
=
call
.
argument
(
"textcolor"
)
var
toast
:
Toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
var
toast
:
Toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
...
@@ -47,6 +60,32 @@ class FluttertoastPlugin(context: Context): MethodCallHandler {
...
@@ -47,6 +60,32 @@ class FluttertoastPlugin(context: Context): MethodCallHandler {
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
)
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
)
}
}
val
text
:
TextView
=
toast
.
view
.
findViewById
(
android
.
R
.
id
.
message
)
if
(
bgcolor
!=
"null"
)
{
try
{
val
rectShape
=
RoundRectShape
(
floatArrayOf
(
50f
,
50f
,
50f
,
50f
,
50f
,
50f
,
50f
,
50f
),
null
,
null
)
val
shapeDrawable
=
ShapeDrawable
(
rectShape
)
shapeDrawable
.
paint
.
color
=
Color
.
parseColor
(
bgcolor
)
shapeDrawable
.
paint
.
style
=
Paint
.
Style
.
FILL
shapeDrawable
.
paint
.
isAntiAlias
=
true
shapeDrawable
.
paint
.
flags
=
Paint
.
ANTI_ALIAS_FLAG
text
.
setBackgroundDrawable
(
shapeDrawable
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
if
(
textcolor
!=
"null"
)
{
try
{
text
.
setTextColor
(
Color
.
parseColor
(
textcolor
))
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
}
toast
.
show
()
toast
.
show
()
result
.
success
(
"Success"
)
result
.
success
(
"Success"
)
...
...
example/lib/main.dart
View file @
ec1b3b26
...
@@ -23,6 +23,15 @@ class _MyAppState extends State<MyApp> {
...
@@ -23,6 +23,15 @@ class _MyAppState extends State<MyApp> {
);
);
}
}
void
showColoredToast
()
{
Fluttertoast
.
showToast
(
msg:
"This is Colored Toast"
,
toastLength:
Toast
.
LENGTH_SHORT
,
bgcolor:
"#e74c3c"
,
textcolor:
'#ffffff'
);
}
void
showShortToast
()
{
void
showShortToast
()
{
Fluttertoast
.
showToast
(
Fluttertoast
.
showToast
(
msg:
"This is Short Toast"
,
msg:
"This is Short Toast"
,
...
@@ -85,6 +94,13 @@ class _MyAppState extends State<MyApp> {
...
@@ -85,6 +94,13 @@ class _MyAppState extends State<MyApp> {
onPressed:
showTopShortToast
onPressed:
showTopShortToast
),
),
),
),
new
Padding
(
padding:
const
EdgeInsets
.
all
(
10.0
),
child:
new
RaisedButton
(
child:
new
Text
(
'Show Colored Toast'
),
onPressed:
showColoredToast
),
),
],
],
),
),
),
),
...
...
fluttertoast_android.iml
View file @
ec1b3b26
...
@@ -22,8 +22,8 @@
...
@@ -22,8 +22,8 @@
<content
url=
"file://$MODULE_DIR$/example/android"
>
<content
url=
"file://$MODULE_DIR$/example/android"
>
<sourceFolder
url=
"file://$MODULE_DIR$/example/android/app/src/main/java"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/example/android/app/src/main/java"
isTestSource=
"false"
/>
</content>
</content>
<orderEntry
type=
"jdk"
jdkName=
"Android API 2
5
Platform"
jdkType=
"Android SDK"
/>
<orderEntry
type=
"jdk"
jdkName=
"Android API 2
7
Platform"
jdkType=
"Android SDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
<orderEntry
type=
"library"
name=
"Flutter for Android"
level=
"project"
/>
<orderEntry
type=
"library"
name=
"Flutter for Android"
level=
"project"
/>
</component>
</component>
</module>
</module>
\ No newline at end of file
ios/Classes/FluttertoastPlugin.m
View file @
ec1b3b26
...
@@ -61,4 +61,19 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
...
@@ -61,4 +61,19 @@ static NSString *const CHANNEL_NAME = @"PonnamKarthik/fluttertoast";
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
];
[[
UIApplication
sharedApplication
].
delegate
.
window
.
rootViewController
.
view
makeToast
:
msg
];
}
}
-
(
UIColor
*
)
getUIColorObjectFromHexString
:
(
NSString
*
)
hexStr
alpha
:
(
CGFloat
)
alpha
{
// Convert hex string to an integer
unsigned
int
hexint
=
[
self
intFromHexString
:
hexStr
];
// Create color object, specifying alpha as well
UIColor
*
color
=
[
UIColor
colorWithRed
:((
CGFloat
)
((
hexint
&
0xFF0000
)
>>
16
))
/
255
green
:((
CGFloat
)
((
hexint
&
0xFF00
)
>>
8
))
/
255
blue
:
((
CGFloat
)
(
hexint
&
0xFF
))
/
255
alpha
:
alpha
];
return
color
;
}
@end
@end
lib/fluttertoast.dart
View file @
ec1b3b26
...
@@ -25,7 +25,9 @@ class Fluttertoast {
...
@@ -25,7 +25,9 @@ class Fluttertoast {
@required
String
msg
,
@required
String
msg
,
Toast
toastLength
,
Toast
toastLength
,
int
timeInSecForIos
=
1
,
int
timeInSecForIos
=
1
,
ToastGravity
gravity
ToastGravity
gravity
,
String
bgcolor
=
"null"
,
String
textcolor
=
"null"
})
async
{
})
async
{
String
toast
=
"short"
;
String
toast
=
"short"
;
if
(
toastLength
==
Toast
.
LENGTH_LONG
)
{
if
(
toastLength
==
Toast
.
LENGTH_LONG
)
{
...
@@ -45,7 +47,9 @@ class Fluttertoast {
...
@@ -45,7 +47,9 @@ class Fluttertoast {
'msg'
:
msg
,
'msg'
:
msg
,
'length'
:
toast
,
'length'
:
toast
,
'time'
:
timeInSecForIos
,
'time'
:
timeInSecForIos
,
'gravity'
:
gravityToast
'gravity'
:
gravityToast
,
'bgcolor'
:
bgcolor
,
'textcolor'
:
textcolor
};
};
String
res
=
await
_channel
.
invokeMethod
(
'showToast'
,
params
);
String
res
=
await
_channel
.
invokeMethod
(
'showToast'
,
params
);
return
res
;
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