Skip to content

Commit 92f6097

Browse files
committed
Add sign up arguments
1 parent df01545 commit 92f6097

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class SignUpArguments{
2+
String mobile;
3+
String countryCode;
4+
5+
SignUpArguments(this.mobile, this.countryCode);
6+
}

gogrocy/lib/core/services/api.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import 'package:gogrocy/service_locator.dart';
1111
import 'package:http/http.dart' as http;
1212

1313
const String baseUrl = "https://gogrocy.in/api/";
14-
const String TOKEN='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE1ODY5NzYxMjEsImlzcyI6Imh0dHBzOlwvXC9nb2dyb2N5LmluXC8iLCJuYmYiOjE1ODY5NzYxMzEsImRhdGEiOnsidXNlcl9pZCI6Ijg1IiwidXNlcl9yb2xlIjoiMSJ9fQ.3jwji_K1l07ttdUUjn4UJbJfuAbrC0msqk7jeftpSzDR7u2d8RCiGWz3ritX3hQIa0MGUe2fIaidErX-xtTQdA';
14+
const String TOKEN =
15+
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE1ODY5NzYxMjEsImlzcyI6Imh0dHBzOlwvXC9nb2dyb2N5LmluXC8iLCJuYmYiOjE1ODY5NzYxMzEsImRhdGEiOnsidXNlcl9pZCI6Ijg1IiwidXNlcl9yb2xlIjoiMSJ9fQ.3jwji_K1l07ttdUUjn4UJbJfuAbrC0msqk7jeftpSzDR7u2d8RCiGWz3ritX3hQIa0MGUe2fIaidErX-xtTQdA';
1516

1617
const String allProducts = baseUrl + "getProducts";
1718
const String singleProduct = baseUrl + "getProduct";
@@ -20,7 +21,7 @@ const String login = baseUrl + "login";
2021
const String signUp = baseUrl + "signup";
2122
const String verifyUser = baseUrl + "verifyUser";
2223
const String addAddress = baseUrl + "add_address";
23-
const String cartList=baseUrl+'getCartItems';
24+
const String cartList = baseUrl + 'getCartItems';
2425

2526
class Apis {
2627
final SharedPrefsService _sharedPrefsService = locator<SharedPrefsService>();
@@ -49,6 +50,7 @@ class Apis {
4950
"country": "India",
5051
};
5152
print(body);
53+
print("ADDDRESSSSSS " + jwt);
5254
http.Response result = await http.post(addAddress,
5355
headers: {HttpHeaders.authorizationHeader: "Bearer $jwt"}, body: body);
5456
print(result.body);
@@ -84,6 +86,7 @@ class Apis {
8486
mobile: mobile, countryCode: countryCode, password: password);
8587
print("login via sign up success");
8688
if (user.jwt != null) {
89+
print("LOGIN " + user.jwt);
8790
await verifyUserApi(user.jwt);
8891
await addAddressApi(
8992
name: name,
@@ -122,6 +125,7 @@ class Apis {
122125
return user;
123126
}
124127
}
128+
125129
Future<List<Product>> getAllProducts() async {
126130
var client = new http.Client();
127131
bool connectionState = await checkStatus();
@@ -144,8 +148,8 @@ class Apis {
144148
var client = new http.Client();
145149
bool connectionState = await checkStatus();
146150
if (connectionState) //TODO: Add a proper else return
147-
{
148-
var response = await client.post(cartList,headers: {
151+
{
152+
var response = await client.post(cartList, headers: {
149153
'Content-Type': 'application/json',
150154
'Accept': 'application/json',
151155
'Authorization': 'Bearer $TOKEN',
@@ -172,10 +176,10 @@ class Apis {
172176
Future<bool> verifyUserApi(String jwt) async {
173177
http.Response result = await http.post(verifyUser,
174178
headers: {HttpHeaders.authorizationHeader: "Bearer $jwt"});
175-
if ((json.decode(result.body))["success"]){
179+
if ((json.decode(result.body))["success"]) {
176180
print("VERIFIED USER");
177-
return true;}
178-
else
181+
return true;
182+
} else
179183
return false;
180184
}
181185
}

gogrocy/lib/core/services/authentication_service.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:firebase_auth/firebase_auth.dart';
22
import 'package:flutter/cupertino.dart';
3+
import 'package:gogrocy/core/models/sign_up_arguments.dart';
34
import 'package:gogrocy/core/services/navigation_service.dart';
45
import 'package:gogrocy/core/services/shared_prefs.dart';
56
import 'package:gogrocy/service_locator.dart';
@@ -17,10 +18,7 @@ class AuthenticationService {
1718
print('Verification Complete');
1819
await signInWithNumber(context, credential);
1920
print("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
20-
_navigationService.navigateTo('awesome', arguments:{
21-
"phoneNumber": phoneNumber,
22-
"countryCode": countryCode
23-
});
21+
_navigationService.navigateTo('awesome', arguments: SignUpArguments(phoneNumber, countryCode));
2422
};
2523

2624
final PhoneVerificationFailed verificationFailed =

gogrocy/lib/core/services/shared_prefs.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ class SharedPrefsService {
1717
}
1818

1919
Future<bool> hasUser() async {
20-
final SharedPreferences prefs = await SharedPreferences.getInstance();
20+
SharedPreferences prefs = await SharedPreferences.getInstance();
2121
return prefs.getBool("loggedIn")??false;
2222
}
2323
setCartPrice(String s) async{
24-
final SharedPreferences prefs = await SharedPreferences.getInstance();
24+
SharedPreferences prefs = await SharedPreferences.getInstance();
2525
prefs.setString("cart", s);
2626
}
2727

2828
Future<String> getCartPrice() async{
29-
final SharedPreferences prefs = await SharedPreferences.getInstance();
29+
SharedPreferences prefs = await SharedPreferences.getInstance();
3030
return prefs.getString('cart');
3131
}
3232

gogrocy/lib/core/viewModels/login_model.dart

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
22
import 'package:flutter/foundation.dart';
33
import 'package:flutter/material.dart';
44
import 'package:gogrocy/core/enums/viewstate.dart';
5+
import 'package:gogrocy/core/models/sign_up_arguments.dart';
56
import 'package:gogrocy/core/models/user.dart';
67
import 'package:gogrocy/core/services/api.dart';
78
import 'package:gogrocy/core/services/authentication_service.dart';
@@ -49,10 +50,7 @@ class LoginModel extends BaseModel {
4950
if (result is bool) {
5051
if (result) {
5152
print('login success with phone number');
52-
navigationService.navigateTo('awesome', arguments: {
53-
"phoneNumber": phoneNumber,
54-
"countryCode": countryCode
55-
});
53+
navigationService.navigateTo('awesome', arguments: SignUpArguments(phoneNumber, countryCode));
5654
} else {
5755
print('login unsuccessful with phone number');
5856
}
@@ -76,10 +74,7 @@ class LoginModel extends BaseModel {
7674
if (result is bool) {
7775
if (result) {
7876
print('login success with otp');
79-
navigationService.navigateTo('awesome', arguments: {
80-
"phoneNumber": phoneNumber,
81-
"countryCode": countryCode
82-
});
77+
navigationService.navigateTo('awesome', arguments: SignUpArguments(phoneNumber, countryCode));
8378
} else {
8479
print('login unsuccessful with otp');
8580
Scaffold.of(context).showSnackBar(

gogrocy/lib/ui/router.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/material.dart';
2+
import 'package:gogrocy/core/models/sign_up_arguments.dart';
23
import 'package:gogrocy/ui/views/signup_view.dart';
3-
import 'package:gogrocy/ui/views/home/home.dart';
44
import 'package:gogrocy/ui/views/landing_page.dart';
55
import 'package:gogrocy/ui/views/login_view.dart';
66

@@ -24,11 +24,14 @@ Route<dynamic> generateRoute(RouteSettings settings) {
2424
),
2525
);
2626
case 'awesome':
27-
Map<String,String> args = settings.arguments;
27+
SignUpArguments args = settings.arguments;
2828
return PageRouteBuilder(
2929
pageBuilder: (BuildContext context, Animation<double> animation,
3030
Animation<double> secondaryAnimation) {
31-
return SignUpView(mobile: args["phoneNumber"], countryCode: args["countryCode"],);
31+
return SignUpView(
32+
mobile: args.mobile,
33+
countryCode: args.countryCode,
34+
);
3235
},
3336
transitionsBuilder: (BuildContext context, Animation<double> animation,
3437
Animation<double> secondaryAnimation, Widget child) =>

0 commit comments

Comments
 (0)