|
|
|
|
@ -1,9 +1,7 @@
|
|
|
|
|
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/viewModels/authentication_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/uitl/translations_delegate_base.dart';
|
|
|
|
|
import 'package:driverapp/uitl/utils.dart';
|
|
|
|
|
@ -21,14 +19,15 @@ class LoginPage extends StatelessWidget {
|
|
|
|
|
LoginRequest loginRequest = LoginRequest();
|
|
|
|
|
final loginFormKey = GlobalKey<FormState>();
|
|
|
|
|
ProjectViewModel projectViewModel;
|
|
|
|
|
AuthenticationViewModel authenticationViewModel;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
projectViewModel = Provider.of(context);
|
|
|
|
|
authenticationViewModel = Provider.of(context);
|
|
|
|
|
return AnimatedSwitcher(
|
|
|
|
|
duration: Duration(microseconds: 350),
|
|
|
|
|
child: BaseView<AuthenticationViewModel>(
|
|
|
|
|
builder: (_, model, widget) => AppScaffold(
|
|
|
|
|
child: AppScaffold(
|
|
|
|
|
isShowAppBar: false,
|
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
|
child: Center(
|
|
|
|
|
@ -229,26 +228,26 @@ class LoginPage extends StatelessWidget {
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 10,
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
margin: EdgeInsets.all(10),
|
|
|
|
|
height: MediaQuery.of(context).size.height * 0.22,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
SecondaryButton(
|
|
|
|
|
label: TranslationBase.of(context).login,
|
|
|
|
|
onTap: () {
|
|
|
|
|
login(model, context);
|
|
|
|
|
},
|
|
|
|
|
disabled: model.state == ViewState.BusyLocal,
|
|
|
|
|
loading: model.state == ViewState.BusyLocal,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 30,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
Container(
|
|
|
|
|
margin: EdgeInsets.all(10),
|
|
|
|
|
height: MediaQuery.of(context).size.height * 0.22,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
SecondaryButton(
|
|
|
|
|
label: TranslationBase.of(context).login,
|
|
|
|
|
onTap: () {
|
|
|
|
|
login(context);
|
|
|
|
|
},
|
|
|
|
|
disabled: authenticationViewModel.isLoading,
|
|
|
|
|
loading: authenticationViewModel.isLoading,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 30,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
@ -256,14 +255,15 @@ class LoginPage extends StatelessWidget {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
login(AuthenticationViewModel model, BuildContext context) async {
|
|
|
|
|
login(BuildContext context) async {
|
|
|
|
|
if (loginFormKey.currentState.validate()) {
|
|
|
|
|
loginFormKey.currentState.save();
|
|
|
|
|
await model.login(loginRequest);
|
|
|
|
|
if (model.state == ViewState.ErrorLocal) {
|
|
|
|
|
Utils.showErrorToast(model.error);
|
|
|
|
|
await authenticationViewModel.login(loginRequest);
|
|
|
|
|
if (authenticationViewModel.isError) {
|
|
|
|
|
Utils.showErrorToast(authenticationViewModel.error);
|
|
|
|
|
} else {
|
|
|
|
|
Navigator.push(context,
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (context) => DashboardScreen()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|