|
|
|
@ -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(
|
|
|
|
@ -55,10 +53,12 @@ class LoginPage extends StatelessWidget {
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
right: projectViewModel.isArabic
|
|
|
|
right: projectViewModel.isArabic
|
|
|
|
? 0
|
|
|
|
? 0
|
|
|
|
: MediaQuery.of(context).size.width * 0.15,
|
|
|
|
: MediaQuery.of(context).size.width *
|
|
|
|
|
|
|
|
0.15,
|
|
|
|
left: !projectViewModel.isArabic
|
|
|
|
left: !projectViewModel.isArabic
|
|
|
|
? 0
|
|
|
|
? 0
|
|
|
|
: MediaQuery.of(context).size.width * 0.15),
|
|
|
|
: MediaQuery.of(context).size.width *
|
|
|
|
|
|
|
|
0.15),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
@ -88,50 +88,52 @@ class LoginPage extends StatelessWidget {
|
|
|
|
SizedBox(
|
|
|
|
SizedBox(
|
|
|
|
height: 30,
|
|
|
|
height: 30,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
// Row(
|
|
|
|
children: <Widget>[
|
|
|
|
// mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
CircleContainer(
|
|
|
|
// children: <Widget>[
|
|
|
|
onTap: () => projectViewModel.changeLanguage('en'),
|
|
|
|
// CircleContainer(
|
|
|
|
child: Text(
|
|
|
|
// onTap: () =>
|
|
|
|
TranslationBase.of(context).lanEnglish,
|
|
|
|
// projectViewModel.changeLanguage('en'),
|
|
|
|
style: TextStyle(
|
|
|
|
// child: Text(
|
|
|
|
fontSize: 12,
|
|
|
|
// TranslationBase.of(context).lanEnglish,
|
|
|
|
color: projectViewModel.isArabic
|
|
|
|
// style: TextStyle(
|
|
|
|
? Colors.black
|
|
|
|
// fontSize: 12,
|
|
|
|
: Colors.white),
|
|
|
|
// color: projectViewModel.isArabic
|
|
|
|
),
|
|
|
|
// ? Colors.black
|
|
|
|
color: projectViewModel.isArabic
|
|
|
|
// : Colors.white),
|
|
|
|
? Colors.transparent
|
|
|
|
// ),
|
|
|
|
: Theme.of(context).primaryColor,
|
|
|
|
// color: projectViewModel.isArabic
|
|
|
|
borderWidth: projectViewModel.isArabic ? 3 : 0,
|
|
|
|
// ? Colors.transparent
|
|
|
|
borderColor: projectViewModel.isArabic
|
|
|
|
// : Theme.of(context).primaryColor,
|
|
|
|
? Theme.of(context).primaryColor
|
|
|
|
// borderWidth: projectViewModel.isArabic ? 3 : 0,
|
|
|
|
: Colors.transparent,
|
|
|
|
// borderColor: projectViewModel.isArabic
|
|
|
|
),
|
|
|
|
// ? Theme.of(context).primaryColor
|
|
|
|
SizedBox(
|
|
|
|
// : Colors.transparent,
|
|
|
|
width: 20,
|
|
|
|
// ),
|
|
|
|
),
|
|
|
|
// SizedBox(
|
|
|
|
CircleContainer(
|
|
|
|
// width: 20,
|
|
|
|
onTap: () =>
|
|
|
|
// ),
|
|
|
|
projectViewModel.changeLanguage('ar'),
|
|
|
|
// CircleContainer(
|
|
|
|
child: Text(
|
|
|
|
// onTap: () =>
|
|
|
|
TranslationBase.of(context).lanArabic,
|
|
|
|
// projectViewModel.changeLanguage('ar'),
|
|
|
|
style: TextStyle(
|
|
|
|
// child: Text(
|
|
|
|
fontSize: 12,
|
|
|
|
// TranslationBase.of(context).lanArabic,
|
|
|
|
color: !projectViewModel.isArabic
|
|
|
|
// style: TextStyle(
|
|
|
|
? Colors.black
|
|
|
|
// fontSize: 12,
|
|
|
|
: Colors.white),
|
|
|
|
// color: !projectViewModel.isArabic
|
|
|
|
),
|
|
|
|
// ? Colors.black
|
|
|
|
color: !projectViewModel.isArabic
|
|
|
|
// : Colors.white),
|
|
|
|
? Colors.transparent
|
|
|
|
// ),
|
|
|
|
: Theme.of(context).primaryColor,
|
|
|
|
// color: !projectViewModel.isArabic
|
|
|
|
borderWidth: !projectViewModel.isArabic ? 3 : 0,
|
|
|
|
// ? Colors.transparent
|
|
|
|
borderColor: !projectViewModel.isArabic
|
|
|
|
// : Theme.of(context).primaryColor,
|
|
|
|
? Theme.of(context).primaryColor
|
|
|
|
// borderWidth: !projectViewModel.isArabic ? 3 : 0,
|
|
|
|
: Colors.transparent),
|
|
|
|
// borderColor: !projectViewModel.isArabic
|
|
|
|
],
|
|
|
|
// ? Theme.of(context).primaryColor
|
|
|
|
),
|
|
|
|
// : Colors.transparent),
|
|
|
|
|
|
|
|
// ],
|
|
|
|
|
|
|
|
// ),
|
|
|
|
SizedBox(
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
@ -148,7 +150,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),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
@ -173,7 +176,8 @@ class LoginPage extends StatelessWidget {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onSaved: (value) {
|
|
|
|
onSaved: (value) {
|
|
|
|
loginRequest.userID = int.parse(value.trim());
|
|
|
|
loginRequest.userID =
|
|
|
|
|
|
|
|
int.parse(value.trim());
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
@ -195,6 +199,7 @@ class LoginPage extends StatelessWidget {
|
|
|
|
onSaved: (value) {
|
|
|
|
onSaved: (value) {
|
|
|
|
loginRequest.password = value;
|
|
|
|
loginRequest.password = value;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
type: 'password',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
SizedBox(
|
|
|
|
@ -222,7 +227,9 @@ 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 +237,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,23 +251,21 @@ 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()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|