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

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;
}
}
}