fix auth issue

logut
Elham Rababah 6 years ago
parent 2aab227e0c
commit 41c66fc8ff

@ -0,0 +1,3 @@
import 'package:driverapp/core/service/base_service.dart';
class UserDetailsService extends BaseService {}

@ -34,6 +34,7 @@ class BaseAppClient {
body['TokenID'] = token; body['TokenID'] = token;
body['MobileNo'] = doctorProfile?.mobileNumber; body['MobileNo'] = doctorProfile?.mobileNumber;
body['Channel'] = CHANNEL; body['Channel'] = CHANNEL;
body['VersionID'] = 8.3;
} }

@ -1,22 +1,58 @@
import 'package:driverapp/config/shared_pref_kay.dart'; import 'package:driverapp/config/shared_pref_kay.dart';
import 'package:driverapp/core/enum/viewstate.dart'; import 'package:driverapp/core/model/authentication/authenticated_user.dart';
import 'package:driverapp/core/model/authentication/login_request.dart'; import 'package:driverapp/core/model/authentication/login_request.dart';
import 'package:driverapp/core/service/authentication_service.dart'; import 'package:driverapp/core/service/authentication_service.dart';
import 'package:driverapp/core/service/client/base_app_client.dart'; import 'package:driverapp/core/service/client/base_app_client.dart';
import 'package:driverapp/core/viewModels/base_view_model.dart'; import 'package:flutter/cupertino.dart';
import '../../locator.dart'; import '../../locator.dart';
enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED } enum APP_STATUS { LOADING, UNAUTHENTICATED, AUTHENTICATED }
class AuthenticationViewModel extends BaseViewModel { class AuthenticationViewModel with ChangeNotifier {
AuthenticationService _authenticationService = locator<AuthenticationService>(); AuthenticationService _authenticationService =
locator<AuthenticationService>();
AuthenticatedUser user;
bool isLogin = false;
bool isLoading = false;
bool isError = false;
String error;
AuthenticationViewModel() {
getUser();
}
getUser() async {
var asd = "";
if (user == null) {
isLoading = true;
notifyListeners();
var userProfile = await sharedPref.getObject(USER_PROFILE);
if (userProfile != null) {
user = AuthenticatedUser.fromJson(
await sharedPref.getObject(USER_PROFILE));
isLogin = true;
isLoading = false;
notifyListeners();
} else {
isLogin = false;
isLoading = false;
notifyListeners();
}
}
// else
// {
// isLogin = true;
// isLoading = false;
// notifyListeners();
// }
}
APP_STATUS get status { APP_STATUS get status {
if (state == ViewState.Busy || state == ViewState.BusyLocal) { if (isLoading) {
return APP_STATUS.LOADING; return APP_STATUS.LOADING;
} else { } else {
if ( user != null) { if (isLogin) {
return APP_STATUS.AUTHENTICATED; return APP_STATUS.AUTHENTICATED;
} else { } else {
return APP_STATUS.UNAUTHENTICATED; return APP_STATUS.UNAUTHENTICATED;
@ -25,16 +61,20 @@ class AuthenticationViewModel extends BaseViewModel {
} }
login(LoginRequest loginRequest) async { login(LoginRequest loginRequest) async {
setState(ViewState.BusyLocal); isLoading = true;
notifyListeners();
await _authenticationService.login(loginRequest); await _authenticationService.login(loginRequest);
if (_authenticationService.hasError) { if (_authenticationService.hasError) {
error = _authenticationService.error; error = _authenticationService.error;
setState(ViewState.ErrorLocal); isLoading = false;
isError = true;
notifyListeners();
} else { } else {
sharedPref.setObject( sharedPref.setObject(
USER_PROFILE, _authenticationService.authenticatedUser); USER_PROFILE, _authenticationService.authenticatedUser);
sharedPref.setString(TOKEN, _authenticationService.token); sharedPref.setString(TOKEN, _authenticationService.token);
setState(ViewState.Idle); user = _authenticationService.authenticatedUser;
notifyListeners();
} }
} }
} }

@ -20,4 +20,6 @@ void setupLocator() {
locator.registerFactory(() => HospitalViewModel()); locator.registerFactory(() => HospitalViewModel());
locator.registerFactory(() => AuthenticationViewModel()); locator.registerFactory(() => AuthenticationViewModel());
locator.registerFactory(() => OrdersViewModel()); locator.registerFactory(() => OrdersViewModel());
//locator.registerSingleton(AuthenticatedUser(),instanceName: "user",signalsReady: true);
// locator.registerSingleton(() => BaseViewModel());
} }

@ -5,6 +5,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'config/size_config.dart'; import 'config/size_config.dart';
import 'core/viewModels/authentication_view_model.dart';
import 'core/viewModels/project_view_model.dart'; import 'core/viewModels/project_view_model.dart';
import 'locator.dart'; import 'locator.dart';
@ -25,7 +26,15 @@ class MyApp extends StatelessWidget {
providers: [ providers: [
ChangeNotifierProvider<ProjectViewModel>( ChangeNotifierProvider<ProjectViewModel>(
create: (context) => ProjectViewModel(), create: (context) => ProjectViewModel(),
) ),
ChangeNotifierProvider<AuthenticationViewModel>(
create: (context) => AuthenticationViewModel(),
),
// ChangeNotifierProxyProvider<ProjectViewModel, AuthenticationViewModel>(
// update: (_, auth, payments) => payments..getUser(),
// create: (_) => AuthenticationViewModel(),
// ),
], ],
child: Consumer<ProjectViewModel>( child: Consumer<ProjectViewModel>(
builder: (context, projectProvider, child) => MaterialApp( builder: (context, projectProvider, child) => MaterialApp(

@ -1,9 +1,7 @@
import 'package:driverapp/app-icons/driver_app_icons.dart'; import 'package:driverapp/app-icons/driver_app_icons.dart';
import 'package:driverapp/core/enum/viewstate.dart';
import 'package:driverapp/core/model/authentication/login_request.dart'; import 'package:driverapp/core/model/authentication/login_request.dart';
import 'package:driverapp/core/viewModels/authentication_view_model.dart'; import 'package:driverapp/core/viewModels/authentication_view_model.dart';
import 'package:driverapp/core/viewModels/project_view_model.dart'; import 'package:driverapp/core/viewModels/project_view_model.dart';
import 'package:driverapp/pages/base/base_view.dart';
import 'package:driverapp/pages/dashboard/dashboard_screen.dart'; import 'package:driverapp/pages/dashboard/dashboard_screen.dart';
import 'package:driverapp/uitl/translations_delegate_base.dart'; import 'package:driverapp/uitl/translations_delegate_base.dart';
import 'package:driverapp/uitl/utils.dart'; import 'package:driverapp/uitl/utils.dart';
@ -21,15 +19,15 @@ class LoginPage extends StatelessWidget {
LoginRequest loginRequest = LoginRequest(); LoginRequest loginRequest = LoginRequest();
final loginFormKey = GlobalKey<FormState>(); final loginFormKey = GlobalKey<FormState>();
ProjectViewModel projectViewModel; ProjectViewModel projectViewModel;
AuthenticationViewModel authenticationViewModel;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
projectViewModel = Provider.of(context); projectViewModel = Provider.of(context);
authenticationViewModel = Provider.of(context);
return AnimatedSwitcher( return AnimatedSwitcher(
duration: Duration(microseconds: 350), duration: Duration(microseconds: 350),
child: BaseView<AuthenticationViewModel>( child: AppScaffold(
builder: (_, model, widget) =>
AppScaffold(
isShowAppBar: false, isShowAppBar: false,
body: SingleChildScrollView( body: SingleChildScrollView(
child: Center( child: Center(
@ -148,7 +146,8 @@ class LoginPage extends StatelessWidget {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Text( child: Text(
TranslationBase.of(context).enterCredentialsMsg, TranslationBase.of(context)
.enterCredentialsMsg,
style: TextStyle( style: TextStyle(
fontSize: 13, color: Colors.grey), fontSize: 13, color: Colors.grey),
), ),
@ -222,7 +221,8 @@ class LoginPage extends StatelessWidget {
), ),
SizedBox( SizedBox(
height: 10, height: 10,
),Container( ),
Container(
margin: EdgeInsets.all(10), margin: EdgeInsets.all(10),
height: MediaQuery.of(context).size.height * 0.22, height: MediaQuery.of(context).size.height * 0.22,
child: Column( child: Column(
@ -230,10 +230,10 @@ class LoginPage extends StatelessWidget {
SecondaryButton( SecondaryButton(
label: TranslationBase.of(context).login, label: TranslationBase.of(context).login,
onTap: () { onTap: () {
login(model, context); login(context);
}, },
disabled: model.state == ViewState.BusyLocal, disabled: authenticationViewModel.isLoading,
loading: model.state == ViewState.BusyLocal, loading: authenticationViewModel.isLoading,
), ),
SizedBox( SizedBox(
height: 30, height: 30,
@ -244,21 +244,20 @@ class LoginPage extends StatelessWidget {
), ),
), ),
), ),
),
), ),
); );
} }
login(AuthenticationViewModel model, BuildContext context) async { login(BuildContext context) async {
if (loginFormKey.currentState.validate()) { if (loginFormKey.currentState.validate()) {
loginFormKey.currentState.save(); loginFormKey.currentState.save();
await model.login(loginRequest); await authenticationViewModel.login(loginRequest);
if (model.state == ViewState.ErrorLocal) { if (authenticationViewModel.isError) {
Utils.showErrorToast(model.error); Utils.showErrorToast(authenticationViewModel.error);
} else { } else {
Navigator.push( Navigator.push(
context, MaterialPageRoute(builder: (context) => DashboardScreen())); context,
MaterialPageRoute(builder: (context) => DashboardScreen()));
} }
} }
} }

@ -1,6 +1,8 @@
import 'package:barcode_scan/platform_wrapper.dart'; import 'package:barcode_scan/platform_wrapper.dart';
import 'package:driverapp/config/size_config.dart';
import 'package:driverapp/core/enum/viewstate.dart'; import 'package:driverapp/core/enum/viewstate.dart';
import 'package:driverapp/core/model/scan_qr/scan_qr_request_model.dart'; import 'package:driverapp/core/model/scan_qr/scan_qr_request_model.dart';
import 'package:driverapp/core/viewModels/authentication_view_model.dart';
import 'package:driverapp/core/viewModels/orders_view_model.dart'; import 'package:driverapp/core/viewModels/orders_view_model.dart';
import 'package:driverapp/pages/delivery/information_page.dart'; import 'package:driverapp/pages/delivery/information_page.dart';
import 'package:driverapp/pages/orders/pending_orders_page.dart'; import 'package:driverapp/pages/orders/pending_orders_page.dart';
@ -14,7 +16,8 @@ import 'package:driverapp/widgets/others/rounded_container.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
import 'package:driverapp/config/size_config.dart'; import 'package:provider/provider.dart';
import '../base/base_view.dart'; import '../base/base_view.dart';
class DashboardScreen extends StatefulWidget { class DashboardScreen extends StatefulWidget {
@ -23,13 +26,29 @@ class DashboardScreen extends StatefulWidget {
} }
class _DashboardScreenState extends State<DashboardScreen> { class _DashboardScreenState extends State<DashboardScreen> {
bool isInit = false;
AuthenticationViewModel authenticationViewModel;
@override
void didChangeDependencies() {
if (!isInit) {
authenticationViewModel = Provider.of(context);
setState(() {
isInit = !isInit;
});
}
super.didChangeDependencies();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
int orderId; int orderId;
return BaseView<OrdersViewModel>( return BaseView<OrdersViewModel>(
onModelReady: (model) => model.getPendingOrders(), onModelReady: (model) => model.getPendingOrders(),
builder: (BuildContext context, OrdersViewModel model, Widget child) => builder: (BuildContext context, OrdersViewModel model, Widget child) =>
AppScaffold( AppScaffold(
// baseViewModel: model,
body: Container( body: Container(
height: MediaQuery.of(context).size.height * .95, height: MediaQuery.of(context).size.height * .95,
child: ListView( child: ListView(
@ -47,7 +66,9 @@ class _DashboardScreenState extends State<DashboardScreen> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text( Text(
TranslationBase.of(context).haveGreatDay, TranslationBase
.of(context)
.haveGreatDay,
style: TextStyle( style: TextStyle(
fontSize: 14.5, fontSize: 14.5,
color: Color(0xff636363), color: Color(0xff636363),
@ -56,8 +77,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
Padding( Padding(
padding: EdgeInsets.only(top: 4.5), padding: EdgeInsets.only(top: 4.5),
child: Text( child: Text(
'Drive Name', // 'Drive Name',
//model.user.userName, authenticationViewModel.user.userName,
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
fontSize: 25.0), fontSize: 25.0),
@ -100,11 +121,22 @@ class _DashboardScreenState extends State<DashboardScreen> {
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0), padding: EdgeInsets.symmetric(horizontal: 10.0),
child: Container( child: Container(
height: MediaQuery.of(context).orientation == height: MediaQuery
.of(context)
.orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context).size.height * 0.16 ? MediaQuery
: MediaQuery.of(context).size.height * 0.30, .of(context)
width: MediaQuery.of(context).size.width * 0.44, .size
.height * 0.16
: MediaQuery
.of(context)
.size
.height * 0.30,
width: MediaQuery
.of(context)
.size
.width * 0.44,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0), borderRadius: BorderRadius.circular(15.0),
gradient: LinearGradient(colors: [ gradient: LinearGradient(colors: [
@ -113,7 +145,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
]), ]),
), ),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment
.spaceBetween,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Padding( child: Padding(
@ -123,7 +156,9 @@ class _DashboardScreenState extends State<DashboardScreen> {
MainAxisAlignment.spaceEvenly, MainAxisAlignment.spaceEvenly,
children: <Widget>[ children: <Widget>[
Text( Text(
TranslationBase.of(context).youHave, TranslationBase
.of(context)
.youHave,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: fontSize:
@ -139,7 +174,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
4.0), 4.0),
), ),
Text( Text(
TranslationBase.of(context) TranslationBase
.of(context)
.undeliveredPackages, .undeliveredPackages,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
@ -165,18 +201,22 @@ class _DashboardScreenState extends State<DashboardScreen> {
children: <Widget>[ children: <Widget>[
Image.asset( Image.asset(
'assets/images/closed_box.png', 'assets/images/closed_box.png',
height: MediaQuery.of(context) height: MediaQuery
.of(context)
.orientation == .orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context) ? MediaQuery
.of(context)
.size .size
.height * .height *
0.10 0.10
: MediaQuery.of(context) : MediaQuery
.of(context)
.size .size
.height * .height *
0.20, 0.20,
width: MediaQuery.of(context) width: MediaQuery
.of(context)
.size .size
.width * .width *
0.20, 0.20,
@ -200,11 +240,22 @@ class _DashboardScreenState extends State<DashboardScreen> {
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0), padding: EdgeInsets.symmetric(horizontal: 10.0),
child: Container( child: Container(
height: MediaQuery.of(context).orientation == height: MediaQuery
.of(context)
.orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context).size.height * 0.16 ? MediaQuery
: MediaQuery.of(context).size.height * 0.30, .of(context)
width: MediaQuery.of(context).size.width * 0.45, .size
.height * 0.16
: MediaQuery
.of(context)
.size
.height * 0.30,
width: MediaQuery
.of(context)
.size
.width * 0.45,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0), borderRadius: BorderRadius.circular(15.0),
gradient: LinearGradient(colors: [ gradient: LinearGradient(colors: [
@ -213,7 +264,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
]), ]),
), ),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment
.spaceBetween,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Padding( child: Padding(
@ -223,7 +275,9 @@ class _DashboardScreenState extends State<DashboardScreen> {
MainAxisAlignment.spaceEvenly, MainAxisAlignment.spaceEvenly,
children: <Widget>[ children: <Widget>[
Text( Text(
TranslationBase.of(context).youHave, TranslationBase
.of(context)
.youHave,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: fontSize:
@ -239,7 +293,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
4.0), 4.0),
), ),
Text( Text(
TranslationBase.of(context) TranslationBase
.of(context)
.deliveredPackages, .deliveredPackages,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
@ -265,18 +320,22 @@ class _DashboardScreenState extends State<DashboardScreen> {
children: <Widget>[ children: <Widget>[
Image.asset( Image.asset(
'assets/images/opend_box.png', 'assets/images/opend_box.png',
height: MediaQuery.of(context) height: MediaQuery
.of(context)
.orientation == .orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context) ? MediaQuery
.of(context)
.size .size
.height * .height *
0.10 0.10
: MediaQuery.of(context) : MediaQuery
.of(context)
.size .size
.height * .height *
0.20, 0.20,
width: MediaQuery.of(context) width: MediaQuery
.of(context)
.size .size
.width * .width *
0.20, 0.20,
@ -297,17 +356,29 @@ class _DashboardScreenState extends State<DashboardScreen> {
], ],
), ),
Padding( Padding(
padding: EdgeInsets.symmetric(vertical: 16.0, horizontal: 15.0), padding: EdgeInsets.symmetric(
vertical: 16.0, horizontal: 15.0),
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: InkWell( child: InkWell(
child: Container( child: Container(
height: MediaQuery.of(context).orientation == height: MediaQuery
.of(context)
.orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context).size.height * 0.18 ? MediaQuery
: MediaQuery.of(context).size.height * 0.30, .of(context)
width: MediaQuery.of(context).size.width * 0.50, .size
.height * 0.18
: MediaQuery
.of(context)
.size
.height * 0.30,
width: MediaQuery
.of(context)
.size
.width * 0.50,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0), borderRadius: BorderRadius.circular(15.0),
gradient: LinearGradient( gradient: LinearGradient(
@ -318,21 +389,32 @@ class _DashboardScreenState extends State<DashboardScreen> {
), ),
), ),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment
.spaceEvenly,
children: <Widget>[ children: <Widget>[
Column( Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Image.asset( Image.asset(
'assets/images/qr_code.png', 'assets/images/qr_code.png',
width: MediaQuery.of(context).size.width * width: MediaQuery
.of(context)
.size
.width *
0.26, 0.26,
height: MediaQuery.of(context) height: MediaQuery
.of(context)
.orientation == .orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context).size.height * ? MediaQuery
.of(context)
.size
.height *
0.14 0.14
: MediaQuery.of(context).size.height * : MediaQuery
.of(context)
.size
.height *
0.28, 0.28,
fit: BoxFit.contain, fit: BoxFit.contain,
) )
@ -341,7 +423,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
Column( Column(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.spaceEvenly, MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment
.start,
children: <Widget>[ children: <Widget>[
InkWell( InkWell(
onTap: () { onTap: () {
@ -350,7 +433,9 @@ class _DashboardScreenState extends State<DashboardScreen> {
child: Padding( child: Padding(
padding: EdgeInsets.only(top: 8.0), padding: EdgeInsets.only(top: 8.0),
child: Text( child: Text(
TranslationBase.of(context).scan, TranslationBase
.of(context)
.scan,
style: TextStyle( style: TextStyle(
fontSize: fontSize:
SizeConfig.textMultiplier * 6.0, SizeConfig.textMultiplier * 6.0,
@ -363,7 +448,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
Padding( Padding(
padding: EdgeInsets.only(top: 0.0), padding: EdgeInsets.only(top: 0.0),
child: Text( child: Text(
TranslationBase.of(context) TranslationBase
.of(context)
.toAddPackageToQue, .toAddPackageToQue,
style: TextStyle( style: TextStyle(
fontSize: fontSize:
@ -395,7 +481,9 @@ class _DashboardScreenState extends State<DashboardScreen> {
Column( Column(
children: <Widget>[ children: <Widget>[
Text( Text(
TranslationBase.of(context).nearestDropOffs, TranslationBase
.of(context)
.nearestDropOffs,
style: TextStyle( style: TextStyle(
fontSize: 21.0, fontSize: 21.0,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
@ -410,9 +498,12 @@ class _DashboardScreenState extends State<DashboardScreen> {
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Text( Text(
TranslationBase.of(context).seeAll, TranslationBase
.of(context)
.seeAll,
style: TextStyle( style: TextStyle(
fontSize: 14.5, color: Color(0xff42B6AD)), fontSize: 14.5,
color: Color(0xff42B6AD)),
), ),
Icon( Icon(
Icons.arrow_forward_ios, Icons.arrow_forward_ios,
@ -421,10 +512,12 @@ class _DashboardScreenState extends State<DashboardScreen> {
), ),
], ],
), ),
onTap: () => Navigator.push( onTap: () =>
Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => OrdersListScreen()), builder: (context) =>
OrdersListScreen()),
), ),
), ),
], ],
@ -447,17 +540,27 @@ class _DashboardScreenState extends State<DashboardScreen> {
child: InkWell( child: InkWell(
child: RoundedContainer( child: RoundedContainer(
raduis: 25.0, raduis: 25.0,
height: MediaQuery.of(context).orientation == height: MediaQuery
.of(context)
.orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context).size.height * 0.109 ? MediaQuery
: MediaQuery.of(context).size.height * 0.209, .of(context)
.size
.height * 0.109
: MediaQuery
.of(context)
.size
.height * 0.209,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment
.spaceBetween,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
flex: 1, flex: 1,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment
.start,
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment.start, CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
@ -466,25 +569,31 @@ class _DashboardScreenState extends State<DashboardScreen> {
left: 15.0, top: 14.0), left: 15.0, top: 14.0),
child: Image.asset( child: Image.asset(
'assets/images/location.png', 'assets/images/location.png',
height: MediaQuery.of(context) height: MediaQuery
.of(context)
.orientation == .orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context) ? MediaQuery
.of(context)
.size .size
.height * .height *
0.06 0.06
: MediaQuery.of(context) : MediaQuery
.of(context)
.size .size
.height * .height *
0.11, 0.11,
width: MediaQuery.of(context) width: MediaQuery
.of(context)
.orientation == .orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context) ? MediaQuery
.of(context)
.size .size
.width * .width *
0.05 0.05
: MediaQuery.of(context) : MediaQuery
.of(context)
.size .size
.width * .width *
0.09, 0.09,
@ -501,12 +610,15 @@ class _DashboardScreenState extends State<DashboardScreen> {
CrossAxisAlignment.start, CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Padding( Padding(
padding: EdgeInsets.only(top: 20.0), padding: EdgeInsets.only(
top: 20.0),
child: Text( child: Text(
model.orders[index].firstName + model.orders[index].firstName +
' ' + ' ' +
model.orders[index].lastName, model.orders[index]
style: TextStyle(fontSize: 18.0), .lastName,
style: TextStyle(
fontSize: 18.0),
), ),
), ),
Text( Text(
@ -524,7 +636,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
padding: EdgeInsets.all(8.0), padding: EdgeInsets.all(8.0),
child: CircleContainer( child: CircleContainer(
child: Text( child: Text(
model.orders[index].distanceInKilometers model.orders[index]
.distanceInKilometers
.toString() + .toString() +
' K.m\naway', ' K.m\naway',
style: TextStyle( style: TextStyle(
@ -542,7 +655,8 @@ class _DashboardScreenState extends State<DashboardScreen> {
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => builder: (context) =>
InformationPage(model.orders[index]))); InformationPage(
model.orders[index])));
}, },
), ),
); );

File diff suppressed because one or more lines are too long

@ -1,34 +1,35 @@
import 'package:driverapp/pages/authentication/login_page.dart'; import 'package:driverapp/pages/authentication/login_page.dart';
import 'package:driverapp/pages/base/base_view.dart'; import 'package:driverapp/pages/dashboard/dashboard_screen.dart';
import 'package:driverapp/pages/landing/landing_page.dart'; import 'package:driverapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart';
import 'package:driverapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:driverapp/pages/dashboard/dashboard_screen.dart'; import 'package:provider/provider.dart';
import 'core/viewModels/authentication_view_model.dart'; import 'core/viewModels/authentication_view_model.dart';
class RootPage extends StatelessWidget { class RootPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget buildRoot(APP_STATUS status) { AuthenticationViewModel authenticationViewModel = Provider.of(context);
APP_STATUS status = authenticationViewModel.status;
Widget buildRoot() {
switch (status) { switch (status) {
case APP_STATUS.UNAUTHENTICATED: case APP_STATUS.UNAUTHENTICATED:
return LoginPage (); return LoginPage();
break; break;
case APP_STATUS.AUTHENTICATED: case APP_STATUS.AUTHENTICATED:
return DashboardScreen(); return DashboardScreen();
break; break;
case APP_STATUS.LOADING:
return Center(child: AppCircularProgressIndicator());
break;
} }
} }
return AnimatedSwitcher( return AnimatedSwitcher(
duration: Duration(microseconds: 350), duration: Duration(microseconds: 350),
child: BaseView<AuthenticationViewModel>( child: Scaffold(
builder: (_, model, widget) => AppScaffold( body: buildRoot(),
baseViewModel: model,
body: buildRoot((model.status)),
),
), ),
); );
} }

Loading…
Cancel
Save