Skip to content

Commit 4d907e8

Browse files
committed
Merge remote-tracking branch 'smarak/development' into products_v5
# Conflicts: # gogrocy/lib/service_locator.dart # gogrocy/lib/ui/router.dart
2 parents 4b5aa00 + b0082f3 commit 4d907e8

File tree

8 files changed

+237
-103
lines changed

8 files changed

+237
-103
lines changed

gogrocy/lib/core/viewModels/login_model.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ class LoginModel extends BaseModel {
4242

4343
var finalNumber = countryCode + " " + phoneNumber;
4444

45-
var result =
46-
await authenticationService.verifyPhoneNumber(context, phoneNumber, countryCode);
45+
var result = await authenticationService.verifyPhoneNumber(
46+
context, phoneNumber, countryCode);
4747

4848
setState(ViewState.Idle);
4949

5050
if (result is bool) {
5151
if (result) {
5252
print('login success with phone number');
53-
navigationService.navigateTo('awesome', arguments: SignUpArguments(phoneNumber, countryCode));
53+
navigationService.navigateTo('awesome',
54+
arguments: SignUpArguments(phoneNumber, countryCode));
5455
} else {
5556
print('login unsuccessful with phone number');
5657
}
@@ -74,7 +75,8 @@ class LoginModel extends BaseModel {
7475
if (result is bool) {
7576
if (result) {
7677
print('login success with otp');
77-
navigationService.navigateTo('awesome', arguments: SignUpArguments(phoneNumber, countryCode));
78+
navigationService.navigateTo('awesome',
79+
arguments: SignUpArguments(phoneNumber, countryCode));
7880
} else {
7981
print('login unsuccessful with otp');
8082
Scaffold.of(context).showSnackBar(
@@ -98,6 +100,7 @@ class LoginModel extends BaseModel {
98100
@required String countryCode,
99101
@required String password}) async {
100102
setState(ViewState.Busy);
103+
var citySelected = (await _sharedPrefsService.getCity()) != null;
101104
var user = await _apiService.loginApi(
102105
mobile: phoneNumber, countryCode: countryCode, password: password);
103106
setState(ViewState.Idle);
@@ -107,7 +110,9 @@ class LoginModel extends BaseModel {
107110
FireStoreService.addUser(
108111
phoneNumber: phoneNumber, countryCode: countryCode);
109112
print(_sharedPrefsService.setLoggedIn(true));
110-
navigationService.navigateTo('home');
113+
citySelected
114+
? navigationService.navigateTo('home')
115+
: navigationService.navigateTo('city');
111116
} else {
112117
print(user.message);
113118
errorMessage = user.message;

gogrocy/lib/core/viewModels/signup_view_model.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class SignUpViewModel extends BaseModel {
8181
cPassword: cPasswordController.text,
8282
mobile: mobile, locality: addressController.text, city: cityController.text, zip: pinCodeController.text);
8383
if (signUp.success) {
84-
_navigationService.navigateTo('home');
84+
_navigationService.goBack();
85+
_navigationService.navigateTo('city');
8586
return true;
8687
} else {
8788
print(signUp.error);

gogrocy/lib/core/viewModels/startup_view_model.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ class StartupViewModel extends BaseModel {
1212
var hasLoggedInUser = await authenticationService.isUserLoggedIn();
1313
Future.delayed(Duration(seconds: 3), () {
1414
if (hasLoggedInUser) {
15+
//navigationService.goBack();
1516
navigationService.navigateTo('home');
1617
} else {
18+
//navigationService.goBack();
1719
navigationService.navigateTo('login');
1820
}
1921
});

gogrocy/lib/service_locator.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import 'package:gogrocy/core/viewModels/categoty_product_view_model.dart';
88
import 'package:gogrocy/core/viewModels/login_model.dart';
99
import 'package:gogrocy/core/viewModels/product_detail_model.dart';
1010
import 'package:gogrocy/core/viewModels/orderLis_model.dart';
11+
import 'package:gogrocy/core/viewModels/signup_view_model.dart';
1112
import 'package:gogrocy/core/viewModels/startup_view_model.dart';
1213
import 'package:gogrocy/ui/views/category/category_product_view.dart';
14+
import 'package:gogrocy/ui/views/city_selection.dart';
1315
import 'package:gogrocy/ui/views/signup_view.dart';
1416
import 'package:gogrocy/core/services/api.dart';
1517
import 'package:gogrocy/core/services/bottom_appbar_provider.dart';
@@ -19,6 +21,8 @@ GetIt locator = GetIt.instance;
1921

2022
void setupLocator() {
2123
locator.registerFactory<SharedPrefsService>(() => SharedPrefsService());
24+
//locator.registerFactory(()=>SignUpViewModel());
25+
locator.registerLazySingleton(() => CitySelectionModel());
2226
locator.registerFactory<StartupViewModel>(() => StartupViewModel());
2327
locator.registerFactory<NavigationService>(() => NavigationService());
2428
locator.registerFactory<AuthenticationService>(() => AuthenticationService());

gogrocy/lib/ui/router.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:gogrocy/core/models/sign_up_arguments.dart';
66
import 'package:gogrocy/ui/views/all_products_list.dart';
77
import 'package:gogrocy/ui/views/category/category_product_view.dart';
88
import 'package:gogrocy/ui/views/orders/order_details_view.dart';
9+
import 'package:gogrocy/ui/views/city_selection.dart';
910
import 'package:gogrocy/ui/views/product_detail_view.dart';
1011
import 'package:gogrocy/ui/views/signup_view.dart';
1112
import 'package:gogrocy/ui/views/landing_page.dart';
@@ -16,6 +17,8 @@ Route<dynamic> generateRoute(RouteSettings settings) {
1617
switch (settings.name) {
1718
case '/':
1819
return MaterialPageRoute(builder: (context) => LoginView());
20+
case 'city':
21+
return MaterialPageRoute(builder: (context) => CitySelectionView());
1922
case 'home':
2023
return MaterialPageRoute(builder: (context) => HomePageView());
2124
case 'login':
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import 'package:flushbar/flushbar.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:gogrocy/core/services/navigation_service.dart';
4+
import 'package:gogrocy/core/services/shared_prefs.dart';
5+
import 'package:gogrocy/core/viewModels/base_model.dart';
6+
import 'package:gogrocy/service_locator.dart';
7+
import 'package:gogrocy/ui/shared/colors.dart';
8+
import 'package:gogrocy/ui/shared/constants.dart' as constants;
9+
import 'package:gogrocy/ui/views/base_view.dart';
10+
import 'package:gogrocy/ui/widgets/vertical_spaces.dart';
11+
12+
class CitySelectionView extends StatelessWidget {
13+
final _navigationService = locator<NavigationService>();
14+
final _sharedPrefsService = locator<SharedPrefsService>();
15+
16+
@override
17+
Widget build(BuildContext context) {
18+
return BaseView<CitySelectionModel>(
19+
builder: (context, model, child) => SafeArea(
20+
child: Scaffold(
21+
backgroundColor: Colors.white,
22+
body: ListView(
23+
children: <Widget>[
24+
VerticalSpaces.small20,
25+
Center(
26+
child: Text('Select City', style: TextStyle(fontSize: 20.0 * constants.scaleRatio),),
27+
),
28+
RadioListTile(
29+
title: Text("Jeypore"),
30+
subtitle: Text("Odisha"),
31+
activeColor: PRIMARY_COLOR,
32+
onChanged: (value) {
33+
model.setSelectedCityTile(value);
34+
},
35+
groupValue: model.selectedCityTile,
36+
value: 1,
37+
),
38+
RadioListTile(
39+
title: Text("Sunabeda"),
40+
subtitle: Text("Odisha"),
41+
activeColor: PRIMARY_COLOR,
42+
onChanged: (value) {
43+
model.setSelectedCityTile(value);
44+
},
45+
groupValue: model.selectedCityTile,
46+
value: 2,
47+
),
48+
Padding(
49+
padding: EdgeInsets.symmetric(horizontal: 100.0 * constants.scaleRatio,vertical: 50.0 * constants.scaleRatio),
50+
child: RaisedButton(
51+
shape: RoundedRectangleBorder(
52+
borderRadius: BorderRadius.circular(10.0)),
53+
color: Colors.black,
54+
child: Text(
55+
'Done',
56+
style: TextStyle(
57+
color: Colors.white,
58+
fontFamily: 'Gilroy',
59+
fontWeight: FontWeight.bold),
60+
),
61+
onPressed: () async {
62+
if (model.selectedCityTile == 0) {
63+
Flushbar(
64+
messageText: Text(
65+
"Select a city",
66+
style: TextStyle(
67+
color: Colors.black, fontWeight: FontWeight.w500),
68+
),
69+
flushbarStyle: FlushbarStyle.FLOATING,
70+
duration: Duration(seconds: 2),
71+
icon: Icon(
72+
Icons.error_outline,
73+
color: Colors.red,
74+
),
75+
shouldIconPulse: false,
76+
barBlur: 0.9,
77+
margin: EdgeInsets.all(8.0),
78+
borderRadius: 8.0,
79+
backgroundColor: Colors.white,
80+
boxShadows: [
81+
BoxShadow(
82+
color: Colors.grey,
83+
offset: Offset(0.0, 0.0),
84+
blurRadius: 5.0,
85+
)
86+
],
87+
).show(context);
88+
} else {
89+
String city =
90+
model.selectedCityTile == 1 ? "Jeypore" : "Sunabeda";
91+
await _sharedPrefsService.setCity(city);
92+
_navigationService.navigateTo('home');
93+
}
94+
},
95+
),
96+
),
97+
],
98+
),
99+
),
100+
),
101+
);
102+
}
103+
}
104+
105+
class CitySelectionModel extends BaseModel {
106+
int selectedCityTile = 0;
107+
108+
setSelectedCityTile(int val) {
109+
selectedCityTile = val;
110+
notifyListeners();
111+
}
112+
}

0 commit comments

Comments
 (0)