Skip to content

Commit

Permalink
new address
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul-Vijay committed Aug 18, 2020
1 parent b26a94b commit 609f603
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 17 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ jobs:
# Check for any formatting issues in the code.
- run: flutter format --set-exit-if-changed .

# Statically analyze the Dart code for any errors.
- run: flutter analyze .

# Run widget tests for our flutter project.
- run: flutter test

Expand Down
26 changes: 26 additions & 0 deletions lib/classes/storage_sharedPrefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,38 @@ class StorageSharedPrefs {
await prefs.setString('username', username);
}

// set address status to storage
Future<void> setFarStatus(String far) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('far', far);
}

// set user email to storage
Future<void> setEmail(String email) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('email', email);
}

// set id to storage
Future<void> setId(String id) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('id', id);
}

// get Far status from storage
Future<String> getFarStatus() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String far = await prefs.get('far');
return far;
}

// get Far status from storage
Future<String> getEmail() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String email = await prefs.get('email');
return email;
}

// get token from storage
Future<String> getToken() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
Expand Down
2 changes: 1 addition & 1 deletion lib/constants/apiCalls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class APIService {
static final String loginMobile = "$_api/users/loginMobile/";
static final String verifyOTP = "$_api/users/loginMobile/verifyOTP/";
static final String registerAPI = "$_api/users/register/";
static final String registerAddressAPI = "$_api/users/register/address/";
static final String registerAddressAPI = "$_api/users/register/address/new";
static final String forgotMailerAPI = "$_api/users/forgotPassword-mailer/";
// shopping cart file - _getUserDetails function
static final String getUserAPI = "$_api/users/";
Expand Down
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:mvp/models/newCart.dart';
import 'package:mvp/screens/auth/login.dart';
import 'package:mvp/screens/auth/register.dart';
import 'package:mvp/screens/errors/notServing.dart';
import 'package:mvp/screens/landing/mainLanding.dart';
import 'package:mvp/screens/loading.dart';
import 'package:mvp/screens/orders/ordersScreen.dart';
Expand Down Expand Up @@ -58,7 +59,8 @@ class _SevaAppState extends State<SevaApp> {
"/login": (context) => LoginScreen(),
"/main": (context) => MainLandingScreen(),
"/shoppingCartNew": (context) => ShoppingCartNew(),
"/ordersNew": (context) => NewOrdersScreen()
"/ordersNew": (context) => NewOrdersScreen(),
"/notServing": (context) => NotServing()
},
),
);
Expand Down
3 changes: 3 additions & 0 deletions lib/screens/auth/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ class _LoginScreenState extends State<LoginScreen> {
await p.setUsername(jsonBdy["username"]);
await p.setToken(jsonBdy["token"]);
await p.setId(jsonBdy["id"]);
await p.setEmail(jsonBdy["email"]);
bool far = jsonBdy["far"];
await p.setFarStatus(far.toString());
// grant access to the app
Navigator.pushReplacementNamed(context, '/main');
} else if (response.statusCode == 400) {
Expand Down
52 changes: 52 additions & 0 deletions lib/screens/errors/notServing.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';
import 'package:mvp/constants/themeColours.dart';
import 'package:mvp/screens/location.dart';

class NotServing extends StatelessWidget {
final String userEmail;
NotServing({this.userEmail});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Container(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width * 0.8,
child: Text(
"We do not yet serve in your location. We are expanding everyday. Stay tuned!",
style: TextStyle(
color: ThemeColoursSeva().dkGreen,
fontSize: 24.0,
fontWeight: FontWeight.bold),
),
),
SizedBox(height: 30.0),
RaisedButton(
onPressed: () {
// back to page
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => GoogleLocationScreen(
userEmail: userEmail,
)));
},
child: Text(
"Change Address",
style: TextStyle(fontSize: 18.0),
),
color: Colors.white,
elevation: 0.0,
textColor: ThemeColoursSeva().dkGreen,
)
],
),
)),
);
}
}
24 changes: 19 additions & 5 deletions lib/screens/loading.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:http/http.dart' as http;
import 'package:mvp/classes/storage_sharedPrefs.dart';
import 'package:mvp/constants/apiCalls.dart';
import 'package:mvp/constants/themeColours.dart';
import 'package:mvp/screens/errors/notServing.dart';
// import 'package:mvp/screens/auth/login.dart';
import 'package:mvp/screens/introScreen.dart';
import 'package:mvp/screens/landing/mainLanding.dart';
Expand All @@ -18,6 +19,7 @@ class LoadingScreen extends StatefulWidget {
class _LoadingScreenState extends State<LoadingScreen> {
bool _showLoginScreen;
String _showText;
bool _connected = false;

@override
initState() {
Expand All @@ -31,11 +33,10 @@ class _LoadingScreenState extends State<LoadingScreen> {
try {
final result = await InternetAddress.lookup('google.com');
if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
print('connected');
_connected = true;
_checkForUserToken();
}
} on SocketException catch (_) {
print('not connected');
setState(() {
_showText = "Oops! No internet connection.";
});
Expand Down Expand Up @@ -82,18 +83,31 @@ class _LoadingScreenState extends State<LoadingScreen> {
}
}

_changePage() {
_changePage() async {
if (_showLoginScreen == true) {
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => IntroScreen()));
} else if (_showLoginScreen == false) {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => MainLandingScreen()));
StorageSharedPrefs p = new StorageSharedPrefs();
String far = await p.getFarStatus();
String email = await p.getEmail();
if (far == "false") {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => MainLandingScreen()));
} else if (far == "true") {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => NotServing(
userEmail: email,
)));
}
}
}

@override
Widget build(BuildContext context) {
if (!_connected) _checkConnection();
return Scaffold(
body: Container(
child: Center(
Expand Down
26 changes: 19 additions & 7 deletions lib/screens/userProfile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:mvp/constants/themeColours.dart';
import 'package:mvp/models/users.dart';
import 'package:mvp/screens/common/inputTextField.dart';
import 'package:http/http.dart' as http;
import 'package:mvp/screens/errors/notServing.dart';

class UserProfileScreen extends StatefulWidget {
final LatLng coords;
Expand All @@ -22,7 +23,7 @@ class _UserProfileScreenState extends State<UserProfileScreen> {
bool _loading = false;
TextEditingController _address = new TextEditingController();

_showLoading() {
_showLoading(context) {
if (_loading == true) {
return Container(
child: Center(
Expand Down Expand Up @@ -78,11 +79,11 @@ class _UserProfileScreenState extends State<UserProfileScreen> {
} else if (_address.text != '') {
// add to db
user.address = _address.text;
_submitToDb(user);
_submitToDb(user, context);
}
}

_submitToDb(UserModel user) async {
_submitToDb(UserModel user, context) async {
String url = APIService.registerAddressAPI;
String getJson = userModelAddress(user);
Map<String, String> headers = {"Content-Type": "application/json"};
Expand All @@ -93,9 +94,20 @@ class _UserProfileScreenState extends State<UserProfileScreen> {
await p.setToken(json.decode(response.body)["token"]);
await p.setUsername(json.decode(response.body)["username"]);
await p.setId(json.decode(response.body)["id"]);
// Navigator.pushReplacementNamed(context, '/stores');
Navigator.pushNamedAndRemoveUntil(
context, '/main', ModalRoute.withName('/main'));
bool far = json.decode(response.body)["far"];
await p.setFarStatus(far.toString());
await p.setEmail(json.decode(response.body)["email"]);
if (!far) {
Navigator.pushNamedAndRemoveUntil(
context, '/main', ModalRoute.withName('/main'));
} else {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) {
return NotServing(
userEmail: widget.userEmail,
);
}));
}
} else {
throw Exception('Server error');
}
Expand All @@ -114,7 +126,7 @@ class _UserProfileScreenState extends State<UserProfileScreen> {
_showEmptyError(),
],
),
floatingActionButton: _showLoading(),
floatingActionButton: _showLoading(context),
);
}
}

0 comments on commit 609f603

Please sign in to comment.