All done. Need fix logout.

This commit is contained in:
Ivan Murashov
2018-03-11 12:28:13 +03:00
parent c229ea8c9e
commit 47b45eecbf
12 changed files with 78 additions and 92 deletions

Binary file not shown.

View File

@@ -27,6 +27,11 @@
<key>primary</key> <key>primary</key>
<true/> <true/>
</dict> </dict>
<key>FB8CCC12204C8249002BBFDA</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict> </dict>
</dict> </dict>
</plist> </plist>

View File

@@ -78,19 +78,14 @@
NSDictionary *buildSettings = settings[bundleIdentifier]; NSDictionary *buildSettings = settings[bundleIdentifier];
NSLog(@"%@", bundleIdentifier);
if (!buildSettings) { if (!buildSettings) {
NSLog(@"Settings for this bunndle id not defined (%@)", bundleIdentifier); NSLog(@"Settings for this bunndle id not defined (%@)", bundleIdentifier);
abort(); abort();
} }
[platformChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { [platformChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
NSLog(@"%@", call.method); NSLog(@"%@", call.method);
NSLog(@"%@", buildSettings[@"supportPhone"]);
if ([@"getLocale" isEqualToString:call.method]) { if ([@"getLocale" isEqualToString:call.method]) {
result(buildSettings[@"locale"]); result(buildSettings[@"locale"]);
} else if ([@"getFlavor" isEqualToString:call.method]) { } else if ([@"getFlavor" isEqualToString:call.method]) {

View File

@@ -61,15 +61,22 @@ import Flutter
func getInputHint() -> String { func getInputHint() -> String {
switch self.buttonState { switch self.buttonState {
case .card: return strings["enter_manual"]! case .card: return strings["enter_manual"]!
case .phone: return strings["enter_phone"]! case .phone: return strings["enter_phone"]!
} }
} }
func getErrorText() -> String { func getErrorText() -> String {
switch self.buttonState { switch self.buttonState {
case .card: return strings["user_card_not_found"]! case .card: return strings["user_card_not_found"]!
case .phone: return strings["user_phone_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) settingButton.setImage(self.buttonState.icon, for: .normal)
textField.placeholder = self.getInputHint() textField.placeholder = self.getInputHint()
textField.text = "79087654321"
} }
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
@@ -121,36 +128,29 @@ import Flutter
} }
func buttonTouch(){ func buttonTouch(){
setButtonState()
switch self.buttonState {
case .card: self.buttonState = .phone
case .phone: self.buttonState = .card
}
settingButton.setImage(self.buttonState.icon, for: .normal) settingButton.setImage(self.buttonState.icon, for: .normal)
textField.placeholder = self.getInputHint() textField.placeholder = self.getInputHint()
} }
func textFieldShouldReturn(_ textField: UITextField) -> Bool { func textFieldShouldReturn(_ textField: UITextField) -> Bool {
print("User from manual input: \(textField.text)")
sendResult(textField.text!) sendResult(textField.text!)
return true return true
} }
func sendResult(_ str: String) { func sendResult(_ str: String) {
print("result: \(str)")
platformChannel?.invokeMethod("findUser", arguments: [str, buttonState.searchType], result: { (result: Any?) in platformChannel?.invokeMethod("findUser", arguments: [str, buttonState.searchType], result: { (result: Any?) in
if result is FlutterError { if result is FlutterError {
print("Result is nil (ios code)");
self.showErrorAlert(str) self.showErrorAlert(str)
} else { } else {
print("Result is not nil (ios code)");
self.dismiss(animated: true) { self.dismiss(animated: true) {
self.platformChannel?.invokeMethod("purchase", arguments: [result, str]) self.platformChannel?.invokeMethod("purchase", arguments: [result, str])
} }
} }
print("result: \(result.debugDescription )")
}) })
} }
func showErrorAlert(_ str: String) { func showErrorAlert(_ str: String) {
@@ -297,6 +297,7 @@ import Flutter
location = "\(location) (\(transformedPoint.x), \(transformedPoint.y))" location = "\(location) (\(transformedPoint.x), \(transformedPoint.y))"
points.append(windowPointValue) points.append(windowPointValue)
} }
print("User from scanner: \(result.text)")
sendResult(result.text) sendResult(result.text)
print(result.text) print(result.text)
self.capture.stop() self.capture.stop()

View File

@@ -98,7 +98,7 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
void onOptionsItemClick(int index) { void onOptionsItemClick(int index) {
switch (index) { switch (index) {
case 0: { case 0: {
pushRoute(context, new SettingsScreen(helper, app, false)); pushRoute(context, new SettingsScreen(helper, app, false));
break; break;
} }
case 1: { case 1: {

View File

@@ -34,7 +34,13 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
}); });
}); });
} }
return getMainWidget(); return new WillPopScope(onWillPop: () => onWillPop(), child: getMainWidget());
}
onWillPop() {
if (Theme.of(context).platform != TargetPlatform.iOS) {
platform.invokeMethod('finish');
}
} }
@override String getTitle() { @override String getTitle() {
@@ -62,7 +68,9 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
handleTap() { handleTap() {
print('tokenActive: $_tokenActive'); print('tokenActive: $_tokenActive');
if (_tokenActive) { if (_tokenActive) {
Navigator.of(context).pop(true); helper.getToken().then((token) {
Navigator.of(context).pop(token);
});
} else { } else {
platform.invokeMethod('isOnline').then((isOnline) { platform.invokeMethod('isOnline').then((isOnline) {
if (isOnline ) { if (isOnline ) {

View File

@@ -46,11 +46,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
@override @override
void initState() { void initState() {
requestAsyncData(user);
setState(() {
requestAsyncData(user);
});
super.initState(); super.initState();
} }
@@ -66,7 +62,6 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
String loyalty = ''; String loyalty = '';
String bonus = ''; String bonus = '';
List<Map> coupons = []; List<Map> coupons = [];
bool dataRequested = false;
@override @override
Widget getScreenContent() { Widget getScreenContent() {
@@ -190,7 +185,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
height: buttonHeight, height: buttonHeight,
child: new FlatButton( child: new FlatButton(
child: new Text(title, style: new TextStyle(color: textColor)), child: new Text(title, style: new TextStyle(color: textColor)),
onPressed: () => Navigator.of(context).pop(true)), onPressed: () => Navigator.of(context).pop()),
decoration: new BoxDecoration( decoration: new BoxDecoration(
border: new Border.all( border: new Border.all(
color: Resources.getButtonColor(app), width: 1.0), color: Resources.getButtonColor(app), width: 1.0),
@@ -230,9 +225,11 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
} }
requestAsyncData(Map user) async { requestAsyncData(Map user) async {
setState(() {
loading = true;
});
bool showBonus = await platform.invokeMethod('showBonus'); bool showBonus = await platform.invokeMethod('showBonus');
if (await platform.invokeMethod('isOnline') && !this.dataRequested) { if (await platform.invokeMethod('isOnline')) {
this.dataRequested = true;
var response, couponResponse; var response, couponResponse;
print(user['coupons_url']); print(user['coupons_url']);
try { try {
@@ -407,7 +404,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
new Future.delayed(const Duration(milliseconds: 200), () { new Future.delayed(const Duration(milliseconds: 200), () {
print('show purchase success!'); print('show purchase success!');
var route = new MaterialPageRoute<bool>(builder: (BuildContext context) => new PurchaseSuccessScreen( var route = new MaterialPageRoute<Null>(builder: (BuildContext context) => new PurchaseSuccessScreen(
sumTotal, sumTotal,
user['first_name'] == null ? '' : user['first_name'], user['first_name'] == null ? '' : user['first_name'],
helper, helper,
@@ -415,8 +412,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
purchase, purchase,
coupons['results'] coupons['results']
), fullscreenDialog: true); ), fullscreenDialog: true);
Navigator.of(context).push(route).then((b) { Navigator.of(context).push(route).then((_) {
print('finish registration closed: $b'); Navigator.of(context).pop();
}); });
}); });
} }

View File

@@ -124,7 +124,7 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
getScanButton() { getScanButton() {
String title = StringsLocalization.scan(); String title = StringsLocalization.scan();
return buildRaisedButton(title, () => Navigator.of(context).pop(true)); return buildRaisedButton(title, () => Navigator.of(context).pop());
} }

View File

@@ -113,9 +113,10 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
if (response.statusCode == 201) { if (response.statusCode == 201) {
helper.createSession(merchantID, posID, parsedMap['token']).then((_) { helper.createSession(merchantID, posID, parsedMap['token']).then((_) {
new Future.delayed(const Duration(milliseconds: 200), () { new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<bool>(builder: (BuildContext context) => new FinishRegistrationScreen(helper, app), fullscreenDialog: true); print('start finish registration!');
Navigator.of(context).push(route).then((b) { var route = new MaterialPageRoute<String>(builder: (BuildContext context) => new FinishRegistrationScreen(helper, app), fullscreenDialog: true);
print('finish registration closed: $b'); Navigator.of(context).push(route).then((token) {
Navigator.of(context).pop(token);
}); });
}); });
}); });

View File

@@ -55,9 +55,6 @@ class SettingsState extends BaseState<SettingsScreen> {
@override Widget build(BuildContext ctx) { @override Widget build(BuildContext ctx) {
helper.getSettings(true).then((info) { helper.getSettings(true).then((info) {
setState(() { setState(() {
// print('currency: ${info['currency']}');
// print('locale: ${info['locale']}');
// print('token: ${info['token']}');
menuItems[0].title = StringsLocalization.currency(); menuItems[0].title = StringsLocalization.currency();
menuItems[1].title = StringsLocalization.locale(); menuItems[1].title = StringsLocalization.locale();
menuItems[2].title = StringsLocalization.logout(); menuItems[2].title = StringsLocalization.logout();

View File

@@ -173,31 +173,39 @@ class _SplashScreenState extends BaseState<SplashScreen> {
SqliteHelper helper) { SqliteHelper helper) {
// Канал ловит вызовы методов из "нативной" части приложения. // Канал ловит вызовы методов из "нативной" части приложения.
// Могут быть вызваны либо exit либо faq, либо purchase. // Могут быть вызваны либо exit либо faq, либо purchase.
platform.setMethodCallHandler((MethodCall call) { platform.setMethodCallHandler((MethodCall call) async {
print(this.toString()); print(this.toString());
if (call.method == 'findUser') { if (call.method == 'findUser') {
String cardPhone = call.arguments[0];
var userResponse = getUser(call.arguments[1], cardPhone, token);
if (userResponse != null) { try {
userResponse.then((response) {
List<Map> users;
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 { if (userResponse != null) {
users = JSON.decode(response.body); print('I have user in method handler!');
} catch (error) { List<Map> users = JSON.decode(userResponse.body);
print(error);
}
if (users.length > 0) { if (users.length > 0) {
return users[0]; return users[0];
} else { } else {
throw new FlutterError("Users not found"); 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') { } else if (call.method == 'faq') {
faq(helper, app, context, true); faq(helper, app, context, true);
} else if (call.method == 'settings') { } else if (call.method == 'settings') {
@@ -209,20 +217,12 @@ class _SplashScreenState extends BaseState<SplashScreen> {
}); });
}); });
} else { } else {
String userString; String userString = call.arguments[0] is String
? call.arguments[0]
if (call.arguments[0] is String) { : JSON.encode(call.arguments[0]);
userString = call.arguments[0];
} else {
userString = JSON.encode(call.arguments[0]);
}
print(userString); print(userString);
String card = call.arguments[1]; String card = call.arguments[1];
print('$userString, $card'); purchase(token, userString, card);
startScanner(token, userString, card);
} }
}); });
@@ -242,7 +242,7 @@ class _SplashScreenState extends BaseState<SplashScreen> {
}); });
} }
startScanner(String token, String userString, String card) { purchase(String token, String userString, String card) {
new Future.delayed(const Duration(milliseconds: 200), () { new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<Null>( var route = new MaterialPageRoute<Null>(
builder: (BuildContext context) => new PurchaseScreen(helper, app, userString, card), fullscreenDialog: true); builder: (BuildContext context) => new PurchaseScreen(helper, app, userString, card), fullscreenDialog: true);
@@ -251,22 +251,4 @@ class _SplashScreenState extends BaseState<SplashScreen> {
}); });
}); });
} }
Future<Response> 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;
}
}
} }