Commit 5df60dca by Karthik

migrated to androidX

parent f6fc0a87
## [3.0.0]
* Migrated to AndroidX
## [2.2.12] ## [2.2.12]
* Incomplete Text Fix * Incomplete Text Fix
......
...@@ -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 your 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
......
...@@ -26,7 +26,7 @@ android { ...@@ -26,7 +26,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion 16
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.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-beta01'
implementation 'com.android.support:support-compat:27.1.1' implementation 'androidx.core:core:1.0.0-beta01'
} }
...@@ -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 androidx.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;
...@@ -22,6 +22,7 @@ import io.flutter.plugin.common.PluginRegistry.Registrar; ...@@ -22,6 +22,7 @@ import io.flutter.plugin.common.PluginRegistry.Registrar;
public class FluttertoastPlugin implements MethodCallHandler { public class FluttertoastPlugin implements MethodCallHandler {
Context ctx; Context ctx;
Toast toast;
FluttertoastPlugin(Context context) { FluttertoastPlugin(Context context) {
ctx = context; ctx = context;
...@@ -44,7 +45,7 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -44,7 +45,7 @@ public class FluttertoastPlugin implements MethodCallHandler {
Number textSize = call.argument("fontSize"); Number textSize = call.argument("fontSize");
final Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT); toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
toast.setText(msg); toast.setText(msg);
...@@ -55,19 +56,19 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -55,19 +56,19 @@ public class FluttertoastPlugin implements MethodCallHandler {
} }
Boolean sent = false; Boolean sent = false;
final Handler handler = new Handler(); // final Handler handler = new Handler();
final Runnable run = new Runnable() { // final Runnable run = new Runnable() {
//
@Override // @Override
public void run() { // public void run() {
try { // try {
result.success(false); // result.success(false);
//
} catch (Exception e){ // } catch (Exception e){
e.printStackTrace(); // e.printStackTrace();
} // }
} // }
}; // };
switch (gravity) { switch (gravity) {
...@@ -82,6 +83,7 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -82,6 +83,7 @@ public class FluttertoastPlugin implements MethodCallHandler {
} }
final TextView text = toast.getView().findViewById(android.R.id.message); final TextView text = toast.getView().findViewById(android.R.id.message);
if(textSize != null)
text.setTextSize(textSize.floatValue()); text.setTextSize(textSize.floatValue());
text.setMaxLines(1); text.setMaxLines(1);
...@@ -94,34 +96,39 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -94,34 +96,39 @@ public class FluttertoastPlugin implements MethodCallHandler {
if (Build.VERSION.SDK_INT <= 27) { if (Build.VERSION.SDK_INT <= 27) {
toast.getView().setBackground(shapeDrawable); toast.getView().setBackground(shapeDrawable);
} else { } else {
toast.getView().setBackground(null);
text.setBackground(shapeDrawable); text.setBackground(shapeDrawable);
} }
} }
} }
text.setOnTouchListener(new View.OnTouchListener() { // text.setOnTouchListener(new View.OnTouchListener() {
@Override // @Override
public boolean onTouch(View v, MotionEvent event) { // public boolean onTouch(View v, MotionEvent event) {
handler.removeCallbacks(run); // handler.removeCallbacks(run);
text.setOnTouchListener(null); // text.setOnTouchListener(null);
toast.cancel(); // toast.cancel();
try { // try {
result.success(true); // result.success(true);
} catch (Exception e){ // } catch (Exception e){
e.printStackTrace(); // e.printStackTrace();
} // }
//
return false; // return false;
} // }
}); // });
if(textcolor != null) { if(textcolor != null) {
text.setTextColor(textcolor.intValue()); text.setTextColor(textcolor.intValue());
} }
toast.show(); toast.show();
handler.postDelayed(run,toast.getDuration()*1000); result.success(true);
// handler.postDelayed(run,toast.getDuration()*1000);
} else if(call.method.equals("cancel")){
if(toast != null)
toast.cancel();
result.success(true);
} else { } else {
result.notImplemented(); result.notImplemented();
} }
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
android:color="#000000"> android:color="#000000">
</solid> </solid>
<padding <padding
android:left="10dp" android:left="16dp"
android:top="8dp" android:top="12dp"
android:right="10dp" android:right="16dp"
android:bottom="8dp" /> android:bottom="12dp" />
</shape> </shape>
\ No newline at end of file
...@@ -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 "androidx.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'
} }
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment