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
5df60dca
Commit
5df60dca
authored
Feb 12, 2019
by
Karthik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
migrated to androidX
parent
f6fc0a87
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
129 additions
and
113 deletions
+129
-113
CHANGELOG.md
+4
-0
README.md
+2
-2
android/build.gradle
+3
-3
android/src/main/java/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.java
+107
-100
android/src/main/res/drawable/toast_bg.xml
+5
-4
example/android/app/build.gradle
+5
-3
example/android/gradle.properties
+2
-0
pubspec.yaml
+1
-1
No files found.
CHANGELOG.md
View file @
5df60dca
## [3.0.0]
*
Migrated to AndroidX
## [2.2.12]
## [2.2.12]
*
Incomplete Text Fix
*
Incomplete Text Fix
...
...
README.md
View file @
5df60dca
...
@@ -7,13 +7,13 @@ Android and iOS Toast Library for Flutter
...
@@ -7,13 +7,13 @@ Android and iOS Toast Library for Flutter
> * Android
> * Android
> * IOS
> * IOS
If you
r project uses androidx then use
`fluttertoast`
version
`2.2.4`
or
`2.2.5
`
If you
dont want to use androidx then use
`fluttertoast`
version
`2.2.12
`
## How to Use
## How to Use
```
yaml
```
yaml
# add this line to your dependencies
# add this line to your dependencies
fluttertoast
:
^
2.2.12
fluttertoast
:
^
3.0.0
```
```
```
dart
```
dart
...
...
android/build.gradle
View file @
5df60dca
...
@@ -26,7 +26,7 @@ android {
...
@@ -26,7 +26,7 @@ android {
defaultConfig
{
defaultConfig
{
minSdkVersion
16
minSdkVersion
16
testInstrumentationRunner
"android
.support
.test.runner.AndroidJUnitRunner"
testInstrumentationRunner
"android
x
.test.runner.AndroidJUnitRunner"
}
}
lintOptions
{
lintOptions
{
disable
'InvalidPackage'
disable
'InvalidPackage'
...
@@ -34,6 +34,6 @@ android {
...
@@ -34,6 +34,6 @@ android {
}
}
dependencies
{
dependencies
{
implementation
'com.android.support:appcompat-v7:27.1.
1'
implementation
'androidx.appcompat:appcompat:1.0.0-beta0
1'
implementation
'
com.android.support:support-compat:27.1.
1'
implementation
'
androidx.core:core:1.0.0-beta0
1'
}
}
android/src/main/java/io/github/ponnamkarthik/toast/fluttertoast/FluttertoastPlugin.java
View file @
5df60dca
...
@@ -11,7 +11,7 @@ import android.view.View;
...
@@ -11,7 +11,7 @@ import android.view.View;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
android
.support.v4
.content.ContextCompat
;
import
android
x.core
.content.ContextCompat
;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.MethodCall
;
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
;
...
@@ -21,109 +21,116 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
...
@@ -21,109 +21,116 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
/** FluttertoastPlugin */
/** FluttertoastPlugin */
public
class
FluttertoastPlugin
implements
MethodCallHandler
{
public
class
FluttertoastPlugin
implements
MethodCallHandler
{
Context
ctx
;
Context
ctx
;
Toast
toast
;
FluttertoastPlugin
(
Context
context
)
{
ctx
=
context
;
}
/** Plugin registration. */
public
static
void
registerWith
(
Registrar
registrar
)
{
final
MethodChannel
channel
=
new
MethodChannel
(
registrar
.
messenger
(),
"PonnamKarthik/fluttertoast"
);
channel
.
setMethodCallHandler
(
new
FluttertoastPlugin
(
registrar
.
context
()));
}
@Override
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"
);
final
Toast
toast
=
Toast
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
toast
.
setText
(
msg
);
if
(
length
.
equals
(
"long"
))
{
toast
.
setDuration
(
Toast
.
LENGTH_LONG
);
}
else
{
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
);
break
;
case
"center"
:
toast
.
setGravity
(
Gravity
.
CENTER
,
0
,
0
);
break
;
default
:
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
);
}
final
TextView
text
=
toast
.
getView
().
findViewById
(
android
.
R
.
id
.
message
);
FluttertoastPlugin
(
Context
context
)
{
text
.
setTextSize
(
textSize
.
floatValue
());
ctx
=
context
;
text
.
setMaxLines
(
1
);
}
/** Plugin registration. */
if
(
bgcolor
!=
null
)
{
public
static
void
registerWith
(
Registrar
registrar
)
{
Drawable
shapeDrawable
=
ContextCompat
.
getDrawable
(
ctx
,
R
.
drawable
.
toast_bg
);
final
MethodChannel
channel
=
new
MethodChannel
(
registrar
.
messenger
(),
"PonnamKarthik/fluttertoast"
);
channel
.
setMethodCallHandler
(
new
FluttertoastPlugin
(
registrar
.
context
()));
if
(
shapeDrawable
!=
null
)
{
}
shapeDrawable
.
setColorFilter
(
bgcolor
.
intValue
(),
PorterDuff
.
Mode
.
SRC_IN
);
if
(
Build
.
VERSION
.
SDK_INT
<=
27
)
{
toast
.
getView
().
setBackground
(
shapeDrawable
);
}
else
{
text
.
setBackground
(
shapeDrawable
);
}
}
}
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
;
@Override
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
.
makeText
(
ctx
,
msg
,
Toast
.
LENGTH_SHORT
);
toast
.
setText
(
msg
);
if
(
length
.
equals
(
"long"
))
{
toast
.
setDuration
(
Toast
.
LENGTH_LONG
);
}
else
{
toast
.
setDuration
(
Toast
.
LENGTH_SHORT
);
}
}
});
if
(
textcolor
!=
null
)
{
Boolean
sent
=
false
;
text
.
setTextColor
(
textcolor
.
intValue
());
// 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
);
break
;
case
"center"
:
toast
.
setGravity
(
Gravity
.
CENTER
,
0
,
0
);
break
;
default
:
toast
.
setGravity
(
Gravity
.
BOTTOM
,
0
,
100
);
}
toast
.
show
();
final
TextView
text
=
toast
.
getView
().
findViewById
(
android
.
R
.
id
.
message
);
handler
.
postDelayed
(
run
,
toast
.
getDuration
()*
1000
);
if
(
textSize
!=
null
)
text
.
setTextSize
(
textSize
.
floatValue
());
}
else
{
text
.
setMaxLines
(
1
);
result
.
notImplemented
();
if
(
bgcolor
!=
null
)
{
Drawable
shapeDrawable
=
ContextCompat
.
getDrawable
(
ctx
,
R
.
drawable
.
toast_bg
);
if
(
shapeDrawable
!=
null
)
{
shapeDrawable
.
setColorFilter
(
bgcolor
.
intValue
(),
PorterDuff
.
Mode
.
SRC_IN
);
if
(
Build
.
VERSION
.
SDK_INT
<=
27
)
{
toast
.
getView
().
setBackground
(
shapeDrawable
);
}
else
{
toast
.
getView
().
setBackground
(
null
);
text
.
setBackground
(
shapeDrawable
);
}
}
}
// 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
(
true
);
// handler.postDelayed(run,toast.getDuration()*1000);
}
else
if
(
call
.
method
.
equals
(
"cancel"
)){
if
(
toast
!=
null
)
toast
.
cancel
();
result
.
success
(
true
);
}
else
{
result
.
notImplemented
();
}
}
}
}
}
}
android/src/main/res/drawable/toast_bg.xml
View file @
5df60dca
...
@@ -7,8 +7,8 @@
...
@@ -7,8 +7,8 @@
android:color=
"#000000"
>
android:color=
"#000000"
>
</solid>
</solid>
<padding
<padding
android:left=
"1
0
dp"
android:left=
"1
6
dp"
android:top=
"
8
dp"
android:top=
"
12
dp"
android:right=
"1
0
dp"
android:right=
"1
6
dp"
android:bottom=
"
8
dp"
/>
android:bottom=
"
12
dp"
/>
</shape>
</shape>
\ No newline at end of file
example/android/app/build.gradle
View file @
5df60dca
...
@@ -38,7 +38,7 @@ android {
...
@@ -38,7 +38,7 @@ android {
targetSdkVersion
28
targetSdkVersion
28
versionCode
flutterVersionCode
.
toInteger
()
versionCode
flutterVersionCode
.
toInteger
()
versionName
flutterVersionName
versionName
flutterVersionName
testInstrumentationRunner
"android
.support
.test.runner.AndroidJUnitRunner"
testInstrumentationRunner
"android
x
.test.runner.AndroidJUnitRunner"
}
}
buildTypes
{
buildTypes
{
...
@@ -56,6 +56,8 @@ flutter {
...
@@ -56,6 +56,8 @@ flutter {
dependencies
{
dependencies
{
testImplementation
'junit:junit:4.12'
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation
'androidx.test.espresso:espresso-core:3.1.2-alpha01'
implementation
'androidx.appcompat:appcompat:1.0.2'
implementation
'androidx.legacy:legacy-support-v4:1.0.0'
}
}
example/android/gradle.properties
View file @
5df60dca
android.enableJetifier
=
true
android.useAndroidX
=
true
org.gradle.jvmargs
=
-Xmx1536M
org.gradle.jvmargs
=
-Xmx1536M
pubspec.yaml
View file @
5df60dca
name
:
fluttertoast
name
:
fluttertoast
description
:
Toast Library for FLutter
description
:
Toast Library for FLutter
version
:
2.2.12
version
:
3.0.0
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