168 lines
6.0 KiB
Dart
168 lines
6.0 KiB
Dart
import 'package:aitrainer_app/bloc/login_form_bloc.dart';
|
|
import 'package:aitrainer_app/bloc/account/account_bloc.dart';
|
|
import 'package:aitrainer_app/localization/app_localization.dart';
|
|
import 'package:aitrainer_app/repository/user_repository.dart';
|
|
import 'package:aitrainer_app/util/common.dart';
|
|
import 'package:aitrainer_app/util/trans.dart';
|
|
import 'package:aitrainer_app/widgets/app_bar_min.dart';
|
|
import 'package:aitrainer_app/widgets/splash.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
|
|
|
import '../library_keys.dart';
|
|
|
|
class LoginPage extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return LoginWidget();
|
|
}
|
|
}
|
|
|
|
class LoginWidget extends StatefulWidget {
|
|
LoginWidget();
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _LoginWidget();
|
|
}
|
|
|
|
class _LoginWidget extends State<LoginWidget> with Common, Trans {
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final accountBloc = BlocProvider.of<AccountBloc>(context);
|
|
setContext(context);
|
|
return BlocProvider(
|
|
create: (context) => LoginFormBloc(userRepository: UserRepository(), accountBloc: accountBloc),
|
|
child: Builder(builder: (context) {
|
|
final loginBloc = BlocProvider.of<LoginFormBloc>(context);
|
|
return Scaffold(
|
|
//key: _scaffoldKey,
|
|
appBar: AppBarMin(),
|
|
body: FormBlocListener<LoginFormBloc, String, String>(
|
|
onSubmitting: (context, state) {
|
|
LoadingDialog.show(context);
|
|
},
|
|
onSuccess: (context, state) {
|
|
LoadingDialog.hide(context);
|
|
Navigator.of(context).pushNamed('home');
|
|
},
|
|
onFailure: (context, state) {
|
|
LoadingDialog.hide(context);
|
|
showInSnackBar(t(state.failureResponse));
|
|
},
|
|
onLoaded: (context, state) {},
|
|
child: loadForm(loginBloc, accountBloc)),
|
|
);
|
|
}));
|
|
}
|
|
|
|
Widget loadForm(LoginFormBloc loginBloc, AccountBloc accountBloc) {
|
|
return SafeArea(
|
|
top: false,
|
|
bottom: false,
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage('asset/image/WT_login.png'),
|
|
fit: BoxFit.cover,
|
|
alignment: Alignment.center,
|
|
),
|
|
),
|
|
child: buildLoginForm(loginBloc, accountBloc),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget buildLoginForm(LoginFormBloc formBloc, AccountBloc accountBloc) {
|
|
return Form(
|
|
key: _scaffoldKey,
|
|
child: Container(
|
|
padding: const EdgeInsets.only(left: 15, right: 50),
|
|
child: ListView(shrinkWrap: false, padding: EdgeInsets.only(top: 150.0), children: <Widget>[
|
|
Divider(color: Colors.transparent),
|
|
/* FlatButton(
|
|
child: new Image.asset(
|
|
'asset/image/login_fb.png',
|
|
width: cWidth * .85,
|
|
),
|
|
onPressed: () => {
|
|
//_fbLogin(),
|
|
FirebaseApi().signInWithFacebook(),
|
|
print("Login with FB"),
|
|
},
|
|
),
|
|
Text(AppLocalizations.of(context).translate("OR")),*/
|
|
Divider(),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
new InkWell(
|
|
child: new Text(AppLocalizations.of(context).translate('Login'),
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24)),
|
|
),
|
|
],
|
|
),
|
|
Divider(),
|
|
TextFieldBlocBuilder(
|
|
key: LibraryKeys.loginEmailField,
|
|
textFieldBloc: formBloc.emailField,
|
|
decoration: InputDecoration(
|
|
fillColor: Colors.white,
|
|
filled: true,
|
|
labelText: 'Email',
|
|
),
|
|
),
|
|
Divider(
|
|
color: Colors.transparent,
|
|
),
|
|
TextFieldBlocBuilder(
|
|
key: LibraryKeys.loginPasswordField,
|
|
textFieldBloc: formBloc.passwordField,
|
|
decoration: InputDecoration(
|
|
fillColor: Colors.white,
|
|
filled: true,
|
|
labelText: 'Password',
|
|
),
|
|
suffixButton: SuffixButton.obscureText,
|
|
),
|
|
Divider(
|
|
color: Colors.transparent,
|
|
),
|
|
Row(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
|
|
new FlatButton(
|
|
key: LibraryKeys.loginOKButton,
|
|
child: Image.asset('asset/image/WT_OK.png', width: 100, height: 100),
|
|
onPressed: () => {formBloc.add(SubmitFormBloc())}),
|
|
]),
|
|
Divider(
|
|
color: Colors.transparent,
|
|
),
|
|
Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: <Widget>[
|
|
new InkWell(
|
|
child: new Text(AppLocalizations.of(context).translate('SignUp')),
|
|
onTap: () => Navigator.of(context).pushNamed('registration'),
|
|
),
|
|
Spacer(flex: 2),
|
|
new InkWell(
|
|
child: new Text(AppLocalizations.of(context).translate('I forgot the password')),
|
|
onTap: () => Navigator.of(context).pushNamed('resetPassword'),
|
|
),
|
|
Spacer(flex: 2),
|
|
new InkWell(
|
|
child: new Text(AppLocalizations.of(context).translate('Privacy')),
|
|
onTap: () => Navigator.of(context).pushNamed('gdpr'),
|
|
),
|
|
]),
|
|
])),
|
|
);
|
|
}
|
|
|
|
void showInSnackBar(String error) {
|
|
_scaffoldKey.currentState
|
|
.showSnackBar(SnackBar(backgroundColor: Colors.orange, content: Text(error, style: TextStyle(color: Colors.white))));
|
|
}
|
|
}
|