From ff72bd5403b136aa85b91385f85cccad13a1da53 Mon Sep 17 00:00:00 2001 From: Ivan Murashov Date: Fri, 9 Mar 2018 08:30:07 +0300 Subject: [PATCH] Navigation between screens without previous states showing. --- android/app/build.gradle | 12 +++--- android/app/src/main/res/layout/a_zbar.xml | 6 +-- android/build.gradle | 4 +- lib/screens/purchase.dart | 11 ++++- lib/screens/splash.dart | 48 ++++++++++++++-------- 5 files changed, 53 insertions(+), 28 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index c6d02fc..576e141 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -15,15 +15,15 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 25 - buildToolsVersion '25.0.0' + compileSdkVersion 27 + buildToolsVersion '27.0.3' lintOptions { disable 'InvalidPackage' } defaultConfig { - targetSdkVersion 21 + targetSdkVersion 27 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" applicationId "com.dinect.checker" } @@ -38,7 +38,9 @@ android { } } - // Не смог разобраться, как коомбинировать flavors в flutter при запуске + flavorDimensions "checker" + + // Не смог разобраться, как коомбинировать flavors в flutter при запуске productFlavors { @@ -185,7 +187,7 @@ flutter { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:25.3.1' + compile 'com.android.support:appcompat-v7:27.1.0' compile 'com.squareup.okhttp3:okhttp:3.8.1' compile 'com.squareup.okio:okio:1.13.0' compile 'me.dm7.barcodescanner:zxing:1.9.8' diff --git a/android/app/src/main/res/layout/a_zbar.xml b/android/app/src/main/res/layout/a_zbar.xml index 0fb2abb..f544a72 100644 --- a/android/app/src/main/res/layout/a_zbar.xml +++ b/android/app/src/main/res/layout/a_zbar.xml @@ -15,15 +15,13 @@ android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginBottom="56dp" - android:layout_weight="0.5" - android:background="#с0000000" /> + android:layout_weight="0.5"/> + android:layout_weight="0.5" /> diff --git a/android/build.gradle b/android/build.gradle index ebe4957..6331892 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,16 +1,18 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.0.1' } } allprojects { repositories { jcenter() + google() maven { url "https://maven.google.com" } diff --git a/lib/screens/purchase.dart b/lib/screens/purchase.dart index c25213d..a40d61f 100644 --- a/lib/screens/purchase.dart +++ b/lib/screens/purchase.dart @@ -39,10 +39,17 @@ class PurchaseScreenState extends BaseState { } @override - Widget build(BuildContext ctx) { + void initState() { + setState(() { requestAsyncData(user); }); + + super.initState(); + } + + @override + Widget build(BuildContext ctx) { return getMainWidget(); } @@ -172,7 +179,7 @@ class PurchaseScreenState extends BaseState { child: new FlatButton( child: new Text(title, style: new TextStyle(color: textColor)), // FIXME: onPressed: () => startScanner(context, app, helper)), - onPressed: () => print('startScanner')), + onPressed: () => Navigator.of(context).pop(true)), decoration: new BoxDecoration( border: new Border.all( color: Resources.getButtonColor(app), width: 1.0), diff --git a/lib/screens/splash.dart b/lib/screens/splash.dart index b94b201..9445a8b 100644 --- a/lib/screens/splash.dart +++ b/lib/screens/splash.dart @@ -28,13 +28,28 @@ class SplashScreen extends BaseScreen { class _SplashScreenState extends BaseState { _SplashScreenState(SqliteHelper helper, String app) : super(helper, app); + bool a = false; + + @override + void initState() { + + print('init state!'); + + new Future.delayed(const Duration(milliseconds: 1000), () { + showNextScreen(); + a = true; + }); + + super.initState(); + } @override Widget build(BuildContext ctx) { - new Future.delayed(const Duration(milliseconds: 1000), () { - showNextScreen(); - }); - return getScreenContent(); + return a ? new Container( + decoration: new BoxDecoration( + image: new DecorationImage( + image: new ExactAssetImage(Resources.getSplash(nullq)), + fit: BoxFit.cover))) : getScreenContent(); } @override @@ -151,6 +166,7 @@ class _SplashScreenState extends BaseState { // Канал ловит вызовы методов из "нативной" части приложения. // Могут быть вызваны либо exit либо faq, либо purchase. platform.setMethodCallHandler((MethodCall call) { + print(this.toString()); if (call.method == 'findUser') { String cardPhone = call.arguments[0]; var userResponse = getUser(call.arguments[1], cardPhone, token); @@ -190,18 +206,7 @@ class _SplashScreenState extends BaseState { String card = call.arguments[1]; print('$userString, $card'); - new Future.delayed(const Duration(milliseconds: 200), () { - var route = new MaterialPageRoute( - builder: (BuildContext context) => new PurchaseScreen(helper, app, userString, card), - fullscreenDialog: true); - Navigator.of(context).push(route).then((b) { - if (b) { - setState(() { - print('restart scanner!'); - }); - } - }); - }); + startScanner(token, userString, card); } }); @@ -221,6 +226,17 @@ class _SplashScreenState extends BaseState { }); } + startScanner(String token, String userString, String card) { + new Future.delayed(const Duration(milliseconds: 200), () { + var route = new MaterialPageRoute( + builder: (BuildContext context) => new PurchaseScreen(helper, app, userString, card), fullscreenDialog: true); + Navigator.of(context).push(route).then((b) { + print('purchase closed: $b'); + _initAndStartScanner(context, app, token, helper); + }); + }); + } + Future getUser(String type, String cardPhone, String token) { try { switch (type) {