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>
<true/>
</dict>
<key>FB8CCC12204C8249002BBFDA</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

View File

@@ -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]) {

View File

@@ -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()

View File

@@ -98,7 +98,7 @@ abstract class BaseState<T extends StatefulWidget> extends State<T> {
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: {

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() {
@@ -62,7 +68,9 @@ class RegistrationScreenState extends BaseState<FinishRegistrationScreen> {
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 ) {

View File

@@ -46,11 +46,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
@override
void initState() {
setState(() {
requestAsyncData(user);
});
requestAsyncData(user);
super.initState();
}
@@ -66,7 +62,6 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
String loyalty = '';
String bonus = '';
List<Map> coupons = [];
bool dataRequested = false;
@override
Widget getScreenContent() {
@@ -88,8 +83,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
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<T> extends BaseState<PurchaseScreen> {
Resources.getPrimaryColor(app)
)
));
return new Column(children: <Widget>[
new Expanded(
child: new ListView(children: widgetList))
@@ -190,7 +185,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
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<T> extends BaseState<PurchaseScreen> {
}
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<T> extends BaseState<PurchaseScreen> {
new Future.delayed(const Duration(milliseconds: 200), () {
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,
user['first_name'] == null ? '' : user['first_name'],
helper,
@@ -415,8 +412,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
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();
});
});
}

View File

@@ -52,7 +52,7 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
}
@override Widget build(BuildContext context) {
if (currency == null) {
helper.getCurrency().then((currency) {
setState(() {
@@ -60,7 +60,7 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
});
});
}
if (this.details['sum_bonus'] is String) {
String regexString = r'(\d+) начислено, (\d+).*';
RegExp regExp = new RegExp(regexString);
@@ -124,7 +124,7 @@ class PurchaseSuccessScreenState<T> extends BaseState<PurchaseSuccessScreen> {
getScanButton() {
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) {
helper.createSession(merchantID, posID, parsedMap['token']).then((_) {
new Future.delayed(const Duration(milliseconds: 200), () {
var route = new MaterialPageRoute<bool>(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<String>(builder: (BuildContext context) => new FinishRegistrationScreen(helper, app), fullscreenDialog: true);
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) {
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();

View File

@@ -173,31 +173,39 @@ class _SplashScreenState extends BaseState<SplashScreen> {
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<Map> 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<Map> 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<SplashScreen> {
});
});
} 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<SplashScreen> {
});
}
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<Null>(
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;
}
}
}