diff --git a/ios/Flutter/app.flx b/ios/Flutter/app.flx index 88f4fa0..3f94061 100644 Binary files a/ios/Flutter/app.flx and b/ios/Flutter/app.flx differ diff --git a/ios/Runner.xcodeproj/xcuserdata/kifio.xcuserdatad/xcschemes/xcschememanagement.plist b/ios/Runner.xcodeproj/xcuserdata/kifio.xcuserdatad/xcschemes/xcschememanagement.plist index 779c523..9649f80 100644 --- a/ios/Runner.xcodeproj/xcuserdata/kifio.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/ios/Runner.xcodeproj/xcuserdata/kifio.xcuserdatad/xcschemes/xcschememanagement.plist @@ -27,6 +27,11 @@ primary + FB8CCC12204C8249002BBFDA + + primary + + diff --git a/ios/Runner.xcworkspace/xcuserdata/kifio.xcuserdatad/UserInterfaceState.xcuserstate b/ios/Runner.xcworkspace/xcuserdata/kifio.xcuserdatad/UserInterfaceState.xcuserstate index 47a0be0..cf47919 100644 Binary files a/ios/Runner.xcworkspace/xcuserdata/kifio.xcuserdatad/UserInterfaceState.xcuserstate and b/ios/Runner.xcworkspace/xcuserdata/kifio.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ios/Runner/AppDelegate.m b/ios/Runner/AppDelegate.m index 406b536..69618bb 100644 --- a/ios/Runner/AppDelegate.m +++ b/ios/Runner/AppDelegate.m @@ -78,19 +78,14 @@ NSDictionary *buildSettings = settings[bundleIdentifier]; - NSLog(@"%@", bundleIdentifier); - if (!buildSettings) { NSLog(@"Settings for this bunndle id not defined (%@)", bundleIdentifier); abort(); } - [platformChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { NSLog(@"%@", call.method); - NSLog(@"%@", buildSettings[@"supportPhone"]); - if ([@"getLocale" isEqualToString:call.method]) { result(buildSettings[@"locale"]); } else if ([@"getFlavor" isEqualToString:call.method]) { diff --git a/ios/Runner/ScannerViewController.swift b/ios/Runner/ScannerViewController.swift index 49f95d0..f1aba55 100644 --- a/ios/Runner/ScannerViewController.swift +++ b/ios/Runner/ScannerViewController.swift @@ -61,15 +61,22 @@ import Flutter func getInputHint() -> String { switch self.buttonState { - case .card: return strings["enter_manual"]! - case .phone: return strings["enter_phone"]! + case .card: return strings["enter_manual"]! + case .phone: return strings["enter_phone"]! } } func getErrorText() -> String { switch self.buttonState { - case .card: return strings["user_card_not_found"]! - case .phone: return strings["user_phone_not_found"]! + case .card: return strings["user_card_not_found"]! + case .phone: return strings["user_phone_not_found"]! + } + } + + func setButtonState() { + switch self.buttonState { + case .card: self.buttonState = .phone + case .phone: self.buttonState = .card } } @@ -97,7 +104,7 @@ import Flutter settingButton.setImage(self.buttonState.icon, for: .normal) textField.placeholder = self.getInputHint() - + textField.text = "79087654321" } override func viewWillAppear(_ animated: Bool) { @@ -121,36 +128,29 @@ import Flutter } func buttonTouch(){ - - switch self.buttonState { - case .card: self.buttonState = .phone - case .phone: self.buttonState = .card - } + setButtonState() settingButton.setImage(self.buttonState.icon, for: .normal) textField.placeholder = self.getInputHint() } func textFieldShouldReturn(_ textField: UITextField) -> Bool { - + print("User from manual input: \(textField.text)") sendResult(textField.text!) - return true } func sendResult(_ str: String) { - print("result: \(str)") platformChannel?.invokeMethod("findUser", arguments: [str, buttonState.searchType], result: { (result: Any?) in if result is FlutterError { + print("Result is nil (ios code)"); self.showErrorAlert(str) } else { - + print("Result is not nil (ios code)"); self.dismiss(animated: true) { self.platformChannel?.invokeMethod("purchase", arguments: [result, str]) } } - print("result: \(result.debugDescription )") }) - } func showErrorAlert(_ str: String) { @@ -297,6 +297,7 @@ import Flutter location = "\(location) (\(transformedPoint.x), \(transformedPoint.y))" points.append(windowPointValue) } + print("User from scanner: \(result.text)") sendResult(result.text) print(result.text) self.capture.stop() diff --git a/lib/base/base_state.dart b/lib/base/base_state.dart index d25534f..78e7829 100644 --- a/lib/base/base_state.dart +++ b/lib/base/base_state.dart @@ -98,7 +98,7 @@ abstract class BaseState extends State { void onOptionsItemClick(int index) { switch (index) { case 0: { - pushRoute(context, new SettingsScreen(helper, app, false)); + pushRoute(context, new SettingsScreen(helper, app, false)); break; } case 1: { diff --git a/lib/screens/finish_registration.dart b/lib/screens/finish_registration.dart index f44736c..a0e8832 100644 --- a/lib/screens/finish_registration.dart +++ b/lib/screens/finish_registration.dart @@ -34,7 +34,13 @@ class RegistrationScreenState extends BaseState { }); }); } - return getMainWidget(); + return new WillPopScope(onWillPop: () => onWillPop(), child: getMainWidget()); + } + + onWillPop() { + if (Theme.of(context).platform != TargetPlatform.iOS) { + platform.invokeMethod('finish'); + } } @override String getTitle() { @@ -62,7 +68,9 @@ class RegistrationScreenState extends BaseState { handleTap() { print('tokenActive: $_tokenActive'); if (_tokenActive) { - Navigator.of(context).pop(true); + helper.getToken().then((token) { + Navigator.of(context).pop(token); + }); } else { platform.invokeMethod('isOnline').then((isOnline) { if (isOnline ) { diff --git a/lib/screens/purchase.dart b/lib/screens/purchase.dart index f109b99..93abe56 100644 --- a/lib/screens/purchase.dart +++ b/lib/screens/purchase.dart @@ -46,11 +46,7 @@ class PurchaseScreenState extends BaseState { @override void initState() { - - setState(() { - requestAsyncData(user); - }); - + requestAsyncData(user); super.initState(); } @@ -66,7 +62,6 @@ class PurchaseScreenState extends BaseState { String loyalty = ''; String bonus = ''; List coupons = []; - bool dataRequested = false; @override Widget getScreenContent() { @@ -88,8 +83,8 @@ class PurchaseScreenState extends BaseState { widgetList.add(getHintLabel()); widgetList.add(getInputField()); // Нельзя добавить еще одно поле таким же способом - if (app != 'autobonus') { - + if (app != 'autobonus') { + if (this.loyalityType == 'bonus') { widgetList.add(getBonusInputField()); } @@ -121,7 +116,7 @@ class PurchaseScreenState extends BaseState { Resources.getPrimaryColor(app) ) )); - + return new Column(children: [ new Expanded( child: new ListView(children: widgetList)) @@ -190,7 +185,7 @@ class PurchaseScreenState extends BaseState { height: buttonHeight, child: new FlatButton( child: new Text(title, style: new TextStyle(color: textColor)), - onPressed: () => Navigator.of(context).pop(true)), + onPressed: () => Navigator.of(context).pop()), decoration: new BoxDecoration( border: new Border.all( color: Resources.getButtonColor(app), width: 1.0), @@ -230,9 +225,11 @@ class PurchaseScreenState extends BaseState { } requestAsyncData(Map user) async { + setState(() { + loading = true; + }); bool showBonus = await platform.invokeMethod('showBonus'); - if (await platform.invokeMethod('isOnline') && !this.dataRequested) { - this.dataRequested = true; + if (await platform.invokeMethod('isOnline')) { var response, couponResponse; print(user['coupons_url']); try { @@ -407,7 +404,7 @@ class PurchaseScreenState extends BaseState { new Future.delayed(const Duration(milliseconds: 200), () { print('show purchase success!'); - var route = new MaterialPageRoute(builder: (BuildContext context) => new PurchaseSuccessScreen( + var route = new MaterialPageRoute(builder: (BuildContext context) => new PurchaseSuccessScreen( sumTotal, user['first_name'] == null ? '' : user['first_name'], helper, @@ -415,8 +412,8 @@ class PurchaseScreenState extends BaseState { purchase, coupons['results'] ), fullscreenDialog: true); - Navigator.of(context).push(route).then((b) { - print('finish registration closed: $b'); + Navigator.of(context).push(route).then((_) { + Navigator.of(context).pop(); }); }); } diff --git a/lib/screens/purchase_success.dart b/lib/screens/purchase_success.dart index a51f523..bbd7576 100644 --- a/lib/screens/purchase_success.dart +++ b/lib/screens/purchase_success.dart @@ -52,7 +52,7 @@ class PurchaseSuccessScreenState extends BaseState { } @override Widget build(BuildContext context) { - + if (currency == null) { helper.getCurrency().then((currency) { setState(() { @@ -60,7 +60,7 @@ class PurchaseSuccessScreenState extends BaseState { }); }); } - + if (this.details['sum_bonus'] is String) { String regexString = r'(\d+) начислено, (\d+).*'; RegExp regExp = new RegExp(regexString); @@ -124,7 +124,7 @@ class PurchaseSuccessScreenState extends BaseState { getScanButton() { String title = StringsLocalization.scan(); - return buildRaisedButton(title, () => Navigator.of(context).pop(true)); + return buildRaisedButton(title, () => Navigator.of(context).pop()); } diff --git a/lib/screens/registration.dart b/lib/screens/registration.dart index 208a166..e030d79 100644 --- a/lib/screens/registration.dart +++ b/lib/screens/registration.dart @@ -113,9 +113,10 @@ class RegistrationScreenState extends BaseState { if (response.statusCode == 201) { helper.createSession(merchantID, posID, parsedMap['token']).then((_) { new Future.delayed(const Duration(milliseconds: 200), () { - var route = new MaterialPageRoute(builder: (BuildContext context) => new FinishRegistrationScreen(helper, app), fullscreenDialog: true); - Navigator.of(context).push(route).then((b) { - print('finish registration closed: $b'); + print('start finish registration!'); + var route = new MaterialPageRoute(builder: (BuildContext context) => new FinishRegistrationScreen(helper, app), fullscreenDialog: true); + Navigator.of(context).push(route).then((token) { + Navigator.of(context).pop(token); }); }); }); diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index a68e9c6..41e8cfa 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -55,9 +55,6 @@ class SettingsState extends BaseState { @override Widget build(BuildContext ctx) { helper.getSettings(true).then((info) { setState(() { -// print('currency: ${info['currency']}'); -// print('locale: ${info['locale']}'); -// print('token: ${info['token']}'); menuItems[0].title = StringsLocalization.currency(); menuItems[1].title = StringsLocalization.locale(); menuItems[2].title = StringsLocalization.logout(); diff --git a/lib/screens/splash.dart b/lib/screens/splash.dart index 5e514c2..04771ee 100644 --- a/lib/screens/splash.dart +++ b/lib/screens/splash.dart @@ -173,31 +173,39 @@ class _SplashScreenState extends BaseState { SqliteHelper helper) { // Канал ловит вызовы методов из "нативной" части приложения. // Могут быть вызваны либо exit либо faq, либо purchase. - platform.setMethodCallHandler((MethodCall call) { + platform.setMethodCallHandler((MethodCall call) async { print(this.toString()); if (call.method == 'findUser') { - String cardPhone = call.arguments[0]; - var userResponse = getUser(call.arguments[1], cardPhone, token); - if (userResponse != null) { - userResponse.then((response) { - List users; + try { + Response userResponse; + switch (call.arguments[1]) { + case 'card': + userResponse = await getUserByCard(call.arguments[0], token); + break; + case 'phone': + userResponse = await getUserByPhone(call.arguments[0], token); + break; + } - try { - users = JSON.decode(response.body); - } catch (error) { - print(error); - } - + if (userResponse != null) { + print('I have user in method handler!'); + List users = JSON.decode(userResponse.body); if (users.length > 0) { return users[0]; } else { throw new FlutterError("Users not found"); } - }); + } else { + throw new FlutterError("Users not found"); + } + } catch (error) { + print(error.toString()); + throw new FlutterError("Users not found"); } + } else if (call.method == 'faq') { faq(helper, app, context, true); } else if (call.method == 'settings') { @@ -209,20 +217,12 @@ class _SplashScreenState extends BaseState { }); }); } else { - String userString; - - if (call.arguments[0] is String) { - userString = call.arguments[0]; - } else { - userString = JSON.encode(call.arguments[0]); - } - + String userString = call.arguments[0] is String + ? call.arguments[0] + : JSON.encode(call.arguments[0]); print(userString); - String card = call.arguments[1]; - print('$userString, $card'); - - startScanner(token, userString, card); + purchase(token, userString, card); } }); @@ -242,7 +242,7 @@ class _SplashScreenState extends BaseState { }); } - startScanner(String token, String userString, String card) { + purchase(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); @@ -251,22 +251,4 @@ class _SplashScreenState extends BaseState { }); }); } - - Future getUser(String type, String cardPhone, String token) { - try { - switch (type) { - case 'card': - return getUserByCard(cardPhone, token); - break; - case 'phone': - return getUserByPhone(cardPhone, token); - break; - default: - return null; - } - } catch (error) { - print(error.toString()); - return null; - } - } }