Skip to content

Commit

Permalink
Merge remote-tracking branch 'smarak/development' into products_v5
Browse files Browse the repository at this point in the history
# Conflicts:
#	gogrocy/lib/service_locator.dart
#	gogrocy/lib/ui/router.dart
  • Loading branch information
Chinmay-KB committed Apr 29, 2020
2 parents 4b5aa00 + b0082f3 commit 4d907e8
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 103 deletions.
15 changes: 10 additions & 5 deletions gogrocy/lib/core/viewModels/login_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ class LoginModel extends BaseModel {

var finalNumber = countryCode + " " + phoneNumber;

var result =
await authenticationService.verifyPhoneNumber(context, phoneNumber, countryCode);
var result = await authenticationService.verifyPhoneNumber(
context, phoneNumber, countryCode);

setState(ViewState.Idle);

if (result is bool) {
if (result) {
print('login success with phone number');
navigationService.navigateTo('awesome', arguments: SignUpArguments(phoneNumber, countryCode));
navigationService.navigateTo('awesome',
arguments: SignUpArguments(phoneNumber, countryCode));
} else {
print('login unsuccessful with phone number');
}
Expand All @@ -74,7 +75,8 @@ class LoginModel extends BaseModel {
if (result is bool) {
if (result) {
print('login success with otp');
navigationService.navigateTo('awesome', arguments: SignUpArguments(phoneNumber, countryCode));
navigationService.navigateTo('awesome',
arguments: SignUpArguments(phoneNumber, countryCode));
} else {
print('login unsuccessful with otp');
Scaffold.of(context).showSnackBar(
Expand All @@ -98,6 +100,7 @@ class LoginModel extends BaseModel {
@required String countryCode,
@required String password}) async {
setState(ViewState.Busy);
var citySelected = (await _sharedPrefsService.getCity()) != null;
var user = await _apiService.loginApi(
mobile: phoneNumber, countryCode: countryCode, password: password);
setState(ViewState.Idle);
Expand All @@ -107,7 +110,9 @@ class LoginModel extends BaseModel {
FireStoreService.addUser(
phoneNumber: phoneNumber, countryCode: countryCode);
print(_sharedPrefsService.setLoggedIn(true));
navigationService.navigateTo('home');
citySelected
? navigationService.navigateTo('home')
: navigationService.navigateTo('city');
} else {
print(user.message);
errorMessage = user.message;
Expand Down
3 changes: 2 additions & 1 deletion gogrocy/lib/core/viewModels/signup_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class SignUpViewModel extends BaseModel {
cPassword: cPasswordController.text,
mobile: mobile, locality: addressController.text, city: cityController.text, zip: pinCodeController.text);
if (signUp.success) {
_navigationService.navigateTo('home');
_navigationService.goBack();
_navigationService.navigateTo('city');
return true;
} else {
print(signUp.error);
Expand Down
2 changes: 2 additions & 0 deletions gogrocy/lib/core/viewModels/startup_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class StartupViewModel extends BaseModel {
var hasLoggedInUser = await authenticationService.isUserLoggedIn();
Future.delayed(Duration(seconds: 3), () {
if (hasLoggedInUser) {
//navigationService.goBack();
navigationService.navigateTo('home');
} else {
//navigationService.goBack();
navigationService.navigateTo('login');
}
});
Expand Down
4 changes: 4 additions & 0 deletions gogrocy/lib/service_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import 'package:gogrocy/core/viewModels/categoty_product_view_model.dart';
import 'package:gogrocy/core/viewModels/login_model.dart';
import 'package:gogrocy/core/viewModels/product_detail_model.dart';
import 'package:gogrocy/core/viewModels/orderLis_model.dart';
import 'package:gogrocy/core/viewModels/signup_view_model.dart';
import 'package:gogrocy/core/viewModels/startup_view_model.dart';
import 'package:gogrocy/ui/views/category/category_product_view.dart';
import 'package:gogrocy/ui/views/city_selection.dart';
import 'package:gogrocy/ui/views/signup_view.dart';
import 'package:gogrocy/core/services/api.dart';
import 'package:gogrocy/core/services/bottom_appbar_provider.dart';
Expand All @@ -19,6 +21,8 @@ GetIt locator = GetIt.instance;

void setupLocator() {
locator.registerFactory<SharedPrefsService>(() => SharedPrefsService());
//locator.registerFactory(()=>SignUpViewModel());
locator.registerLazySingleton(() => CitySelectionModel());
locator.registerFactory<StartupViewModel>(() => StartupViewModel());
locator.registerFactory<NavigationService>(() => NavigationService());
locator.registerFactory<AuthenticationService>(() => AuthenticationService());
Expand Down
3 changes: 3 additions & 0 deletions gogrocy/lib/ui/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:gogrocy/core/models/sign_up_arguments.dart';
import 'package:gogrocy/ui/views/all_products_list.dart';
import 'package:gogrocy/ui/views/category/category_product_view.dart';
import 'package:gogrocy/ui/views/orders/order_details_view.dart';
import 'package:gogrocy/ui/views/city_selection.dart';
import 'package:gogrocy/ui/views/product_detail_view.dart';
import 'package:gogrocy/ui/views/signup_view.dart';
import 'package:gogrocy/ui/views/landing_page.dart';
Expand All @@ -16,6 +17,8 @@ Route<dynamic> generateRoute(RouteSettings settings) {
switch (settings.name) {
case '/':
return MaterialPageRoute(builder: (context) => LoginView());
case 'city':
return MaterialPageRoute(builder: (context) => CitySelectionView());
case 'home':
return MaterialPageRoute(builder: (context) => HomePageView());
case 'login':
Expand Down
112 changes: 112 additions & 0 deletions gogrocy/lib/ui/views/city_selection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import 'package:flushbar/flushbar.dart';
import 'package:flutter/material.dart';
import 'package:gogrocy/core/services/navigation_service.dart';
import 'package:gogrocy/core/services/shared_prefs.dart';
import 'package:gogrocy/core/viewModels/base_model.dart';
import 'package:gogrocy/service_locator.dart';
import 'package:gogrocy/ui/shared/colors.dart';
import 'package:gogrocy/ui/shared/constants.dart' as constants;
import 'package:gogrocy/ui/views/base_view.dart';
import 'package:gogrocy/ui/widgets/vertical_spaces.dart';

class CitySelectionView extends StatelessWidget {
final _navigationService = locator<NavigationService>();
final _sharedPrefsService = locator<SharedPrefsService>();

@override
Widget build(BuildContext context) {
return BaseView<CitySelectionModel>(
builder: (context, model, child) => SafeArea(
child: Scaffold(
backgroundColor: Colors.white,
body: ListView(
children: <Widget>[
VerticalSpaces.small20,
Center(
child: Text('Select City', style: TextStyle(fontSize: 20.0 * constants.scaleRatio),),
),
RadioListTile(
title: Text("Jeypore"),
subtitle: Text("Odisha"),
activeColor: PRIMARY_COLOR,
onChanged: (value) {
model.setSelectedCityTile(value);
},
groupValue: model.selectedCityTile,
value: 1,
),
RadioListTile(
title: Text("Sunabeda"),
subtitle: Text("Odisha"),
activeColor: PRIMARY_COLOR,
onChanged: (value) {
model.setSelectedCityTile(value);
},
groupValue: model.selectedCityTile,
value: 2,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 100.0 * constants.scaleRatio,vertical: 50.0 * constants.scaleRatio),
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
color: Colors.black,
child: Text(
'Done',
style: TextStyle(
color: Colors.white,
fontFamily: 'Gilroy',
fontWeight: FontWeight.bold),
),
onPressed: () async {
if (model.selectedCityTile == 0) {
Flushbar(
messageText: Text(
"Select a city",
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.w500),
),
flushbarStyle: FlushbarStyle.FLOATING,
duration: Duration(seconds: 2),
icon: Icon(
Icons.error_outline,
color: Colors.red,
),
shouldIconPulse: false,
barBlur: 0.9,
margin: EdgeInsets.all(8.0),
borderRadius: 8.0,
backgroundColor: Colors.white,
boxShadows: [
BoxShadow(
color: Colors.grey,
offset: Offset(0.0, 0.0),
blurRadius: 5.0,
)
],
).show(context);
} else {
String city =
model.selectedCityTile == 1 ? "Jeypore" : "Sunabeda";
await _sharedPrefsService.setCity(city);
_navigationService.navigateTo('home');
}
},
),
),
],
),
),
),
);
}
}

class CitySelectionModel extends BaseModel {
int selectedCityTile = 0;

setSelectedCityTile(int val) {
selectedCityTile = val;
notifyListeners();
}
}
Loading

0 comments on commit 4d907e8

Please sign in to comment.