completed velocity integration
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:qpay/http/http.dart';
|
||||
import 'package:qpay/models/api_response.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class LoginScreenModel {
|
||||
@@ -20,19 +21,7 @@ class LoginController extends ChangeNotifier {
|
||||
|
||||
LoginController(this.context);
|
||||
|
||||
void _showErrorSnackBar(String? message) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message.toString()),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
backgroundColor: Colors.deepOrange,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<LoginScreenModel> login(String username, String password) async {
|
||||
Future<ApiResponse<LoginScreenModel>> login(String username, String password) async {
|
||||
try {
|
||||
model.isLoading = true;
|
||||
notifyListeners();
|
||||
@@ -45,6 +34,9 @@ class LoginController extends ChangeNotifier {
|
||||
});
|
||||
logger.i(response.toString());
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
|
||||
if (response.containsKey('token')) {
|
||||
model.status = 'SUCCESS';
|
||||
|
||||
@@ -57,26 +49,25 @@ class LoginController extends ChangeNotifier {
|
||||
prefs.setString('userId', response['uuid']);
|
||||
prefs.setString('initials', response['firstName'].substring(0, 1) + response['lastName'].substring(0, 1));
|
||||
|
||||
return model;
|
||||
return ApiResponse.success(model);
|
||||
} else {
|
||||
model.errorMessage =
|
||||
response['errorMessage'] ??
|
||||
"Problem with the transaction. Please try again or contact support";
|
||||
_showErrorSnackBar(model.errorMessage);
|
||||
return ApiResponse.failure(model.errorMessage!);
|
||||
}
|
||||
} on DioException catch (e, s) {
|
||||
logger.e(s);
|
||||
_showErrorSnackBar(e.response?.data['errors'][0] ?? "Unknown error");
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.failure(e.response?.data['errors'][0] ?? "Unknown error");
|
||||
} catch (e, s) {
|
||||
logger.e(s);
|
||||
_showErrorSnackBar(
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.failure(
|
||||
"Problem processing that transaction. Please try again or contact support",
|
||||
);
|
||||
}
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qpay/abstracts/AbstractController.dart';
|
||||
import 'package:qpay/http/http.dart';
|
||||
import 'package:qpay/models/api_response.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../onboarding_controller.dart';
|
||||
@@ -37,7 +36,7 @@ class PhoneController extends AbstractController {
|
||||
}
|
||||
|
||||
|
||||
Future<void> register() async {
|
||||
Future<ApiResponse<Map<String, dynamic>>> register() async {
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
|
||||
Map user = {
|
||||
@@ -62,19 +61,26 @@ class PhoneController extends AbstractController {
|
||||
if(response['state'] == 'failed') {
|
||||
model.errorMessage = response['message'];
|
||||
showErrorSnackBar(model.errorMessage);
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.failure(response['message'] ?? "Registration failed");
|
||||
}
|
||||
Map body = response['body'];
|
||||
body['workflowId'] = response['workflowId'];
|
||||
onboardingController.updateModel(body);
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.success(Map<String, dynamic>.from(body));
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
showErrorSnackBar(
|
||||
"Problem during registration, please try again or contact support?",
|
||||
);
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.failure("Problem during registration, please try again or contact support?");
|
||||
}
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -85,12 +85,13 @@ class _PhoneScreenState extends State<PhoneScreen> {
|
||||
key: _formKey,
|
||||
child: Center(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final maxWidth = constraints.maxWidth > ResponsivePolicy.md
|
||||
? ResponsivePolicy.md.toDouble()
|
||||
: constraints.maxWidth;
|
||||
return SizedBox(
|
||||
width: maxWidth,
|
||||
builder: (context, constraints) {
|
||||
final maxWidth =
|
||||
constraints.maxWidth > ResponsivePolicy.md
|
||||
? ResponsivePolicy.md.toDouble()
|
||||
: constraints.maxWidth;
|
||||
return SizedBox(
|
||||
width: maxWidth,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
@@ -101,10 +102,7 @@ class _PhoneScreenState extends State<PhoneScreen> {
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Theme
|
||||
.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
@@ -119,7 +117,9 @@ class _PhoneScreenState extends State<PhoneScreen> {
|
||||
_buildPhoneField(),
|
||||
SizedBox(height: 30),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 25),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 25,
|
||||
),
|
||||
child: Skeletonizer(
|
||||
enabled: phoneController.model.isLoading,
|
||||
child: Row(
|
||||
@@ -127,18 +127,25 @@ class _PhoneScreenState extends State<PhoneScreen> {
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
if (_formKey.currentState!
|
||||
.validate()) {
|
||||
String fullPhoneNumber =
|
||||
selectedCountryCode + _phoneController.text;
|
||||
_phoneController.text;
|
||||
|
||||
phoneController.updatePhone(fullPhoneNumber);
|
||||
phoneController.updatePhone(
|
||||
fullPhoneNumber,
|
||||
);
|
||||
await phoneController.register();
|
||||
if(phoneController.model.status != 'failed') {
|
||||
if (phoneController.model.status !=
|
||||
'failed') {
|
||||
context.go('/onboarding/verify');
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Text('Send Code', style: TextStyle(fontSize: 16)),
|
||||
child: Text(
|
||||
'Send Code',
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 16),
|
||||
@@ -162,19 +169,22 @@ class _PhoneScreenState extends State<PhoneScreen> {
|
||||
onPressed: () {
|
||||
context.go('/');
|
||||
},
|
||||
child: Text('Continue as guest?', style: TextStyle(fontSize: 14)),
|
||||
child: Text(
|
||||
'Continue as guest?',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -201,8 +211,7 @@ class _PhoneScreenState extends State<PhoneScreen> {
|
||||
isExpanded: true,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
items:
|
||||
countryCodes.map((country) {
|
||||
items: countryCodes.map((country) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: country['code'],
|
||||
child: Row(
|
||||
@@ -272,5 +281,4 @@ class _PhoneScreenState extends State<PhoneScreen> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qpay/abstracts/AbstractController.dart';
|
||||
import 'package:qpay/http/http.dart';
|
||||
import 'package:qpay/models/api_response.dart';
|
||||
import 'package:qpay/screens/onboarding/onboarding_controller.dart';
|
||||
|
||||
class VerifyModel {
|
||||
@@ -30,7 +31,7 @@ class VerifyController extends AbstractController {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> verifyOtp () async {
|
||||
Future<ApiResponse<Map<String, dynamic>>> verifyOtp () async {
|
||||
Map user = {
|
||||
"username": onboardingController.model.googleUser?.email,
|
||||
"otpCode": model.code,
|
||||
@@ -47,22 +48,25 @@ class VerifyController extends AbstractController {
|
||||
user
|
||||
);
|
||||
model.status = response['state'];
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
|
||||
if(response['state'] == 'failed') {
|
||||
model.errorMessage = response['message'];
|
||||
showErrorSnackBar(model.errorMessage);
|
||||
return ApiResponse.failure(response['message'] ?? "Verification failed");
|
||||
}
|
||||
return ApiResponse.success(Map<String, dynamic>.from(response));
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
showErrorSnackBar(
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.failure(
|
||||
"Problem during registration, please try again or contact support?",
|
||||
);
|
||||
}
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> resendOtp () async {
|
||||
Future<ApiResponse<Map<String, dynamic>>> resendOtp () async {
|
||||
Map user = {
|
||||
"username": onboardingController.model.googleUser?.email,
|
||||
"phone": onboardingController.model.phone,
|
||||
@@ -78,18 +82,21 @@ class VerifyController extends AbstractController {
|
||||
user
|
||||
);
|
||||
model.status = response['state'];
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
|
||||
if(response['state'] == 'failed') {
|
||||
model.errorMessage = response['message'];
|
||||
showErrorSnackBar(model.errorMessage);
|
||||
return ApiResponse.failure(response['message'] ?? "Resend failed");
|
||||
}
|
||||
return ApiResponse.success(Map<String, dynamic>.from(response));
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
showErrorSnackBar(
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
return ApiResponse.failure(
|
||||
"Problem during registration, please try again or contact support?",
|
||||
);
|
||||
}
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user