217 lines
9.1 KiB
Dart
217 lines
9.1 KiB
Dart
import 'package:aitrainer_app/bloc/account/account_bloc.dart';
|
|
import 'package:aitrainer_app/bloc/registration_form_bloc.dart';
|
|
import 'package:aitrainer_app/localization/app_localization.dart';
|
|
import 'package:aitrainer_app/util/common.dart';
|
|
import 'package:aitrainer_app/repository/customer_repository.dart';
|
|
import 'package:aitrainer_app/repository/user_repository.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_facebook_login/flutter_facebook_login.dart';
|
|
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
|
|
|
|
import '../library_keys.dart';
|
|
|
|
class RegistrationPage extends StatelessWidget {
|
|
final UserRepository userRepository = UserRepository();
|
|
final CustomerRepository customerRepository = CustomerRepository();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return RegistrationWidget(
|
|
userRepository: userRepository, customerRepository: customerRepository);
|
|
}
|
|
}
|
|
|
|
class RegistrationWidget extends StatefulWidget {
|
|
final UserRepository userRepository;
|
|
final CustomerRepository customerRepository;
|
|
|
|
RegistrationWidget({this.userRepository, this.customerRepository});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _RegistrationWidget();
|
|
}
|
|
|
|
class _RegistrationWidget extends State<RegistrationWidget> {
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cWidth = Common.mediaSizeWidth(context);
|
|
// ignore: close_sinks
|
|
final accountBloc = BlocProvider.of<AccountBloc>(context);
|
|
return BlocProvider(
|
|
create: (context) => RegistrationFormBloc(
|
|
userRepository: UserRepository(),
|
|
accountBloc: accountBloc),
|
|
child: Builder(builder: (context) {
|
|
// ignore: close_sinks
|
|
final registrationBloc = BlocProvider.of<RegistrationFormBloc>(context);
|
|
|
|
return Scaffold(
|
|
key: _scaffoldKey,
|
|
body: FormBlocListener<RegistrationFormBloc, String, String>(
|
|
onSubmitting: (context, state) {
|
|
LoadingDialog.show(context);
|
|
},
|
|
onSuccess: (context, state) {
|
|
LoadingDialog.hide(context);
|
|
Navigator.of(context).pushNamed('customerModifyPage');
|
|
},
|
|
onFailure: (context, state) {
|
|
LoadingDialog.hide(context);
|
|
showInSnackBar(state.failureResponse);
|
|
},
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage('asset/image/WT_login.png'),
|
|
fit: BoxFit.cover,
|
|
//height: double.infinity,
|
|
//width: double.infinity,
|
|
alignment: Alignment.center,
|
|
),
|
|
),
|
|
child: Form(
|
|
key: _formKey,
|
|
child: Container(
|
|
padding: const EdgeInsets.only(left: 25, right: 100),
|
|
child: ListView(
|
|
shrinkWrap: false,
|
|
padding: EdgeInsets.only(top: 120.0),
|
|
//mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: <Widget>[
|
|
//Spacer(flex:4),
|
|
|
|
FlatButton(
|
|
child: new Image.asset(
|
|
'asset/image/login_fb.png',
|
|
width: cWidth * .85,
|
|
),
|
|
onPressed: () => {
|
|
_fbLogin(),
|
|
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('SignUp'),
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 24)),
|
|
),
|
|
],
|
|
),
|
|
Divider(),
|
|
TextFieldBlocBuilder(
|
|
key: LibraryKeys.loginEmailField,
|
|
textFieldBloc: registrationBloc.emailField,
|
|
decoration: InputDecoration(
|
|
fillColor: Colors.white,
|
|
filled: true,
|
|
labelText: 'Email',
|
|
),
|
|
),
|
|
Divider(
|
|
color: Colors.transparent,
|
|
),
|
|
TextFieldBlocBuilder(
|
|
key: LibraryKeys.loginPasswordField,
|
|
textFieldBloc: registrationBloc.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(
|
|
child: Image.asset(
|
|
'asset/image/WT_OK.png',
|
|
width: 100,
|
|
height: 100),
|
|
onPressed: () => {
|
|
registrationBloc.add(SubmitFormBloc())
|
|
}),
|
|
]),
|
|
Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.spaceAround,
|
|
children: <Widget>[
|
|
new InkWell(
|
|
child: new Text(AppLocalizations.of(context)
|
|
.translate('Login')),
|
|
onTap: () => Navigator.of(context)
|
|
.pushNamed('login'),
|
|
),
|
|
Spacer(flex: 1),
|
|
new InkWell(
|
|
child: new Text(AppLocalizations.of(context)
|
|
.translate('Privacy')),
|
|
onTap: () =>
|
|
Navigator.of(context).pushNamed('gdpr'),
|
|
),
|
|
Spacer(flex: 2),
|
|
]),
|
|
//Spacer(flex:2),
|
|
])),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}));
|
|
}
|
|
|
|
void showInSnackBar(String error) {
|
|
_scaffoldKey.currentState.showSnackBar(SnackBar(
|
|
backgroundColor: Colors.orange,
|
|
content: Text(
|
|
AppLocalizations.of(context)
|
|
.translate("There is an error: during registration:") +
|
|
" " +
|
|
error,
|
|
style: TextStyle(color: Colors.white))));
|
|
}
|
|
|
|
Future<Null> _fbLogin() async {
|
|
final FacebookLogin facebookSignIn = new FacebookLogin();
|
|
final FacebookLoginResult result = await facebookSignIn.logIn(['email']);
|
|
|
|
switch (result.status) {
|
|
case FacebookLoginStatus.loggedIn:
|
|
final FacebookAccessToken accessToken = result.accessToken;
|
|
showInSnackBar('''
|
|
Logged in!
|
|
Token: ${accessToken.token}
|
|
User id: ${accessToken.userId}
|
|
Expires: ${accessToken.expires}
|
|
Permissions: ${accessToken.permissions}
|
|
Declined permissions: ${accessToken.declinedPermissions}
|
|
''');
|
|
break;
|
|
case FacebookLoginStatus.cancelledByUser:
|
|
showInSnackBar('Login cancelled by the user.');
|
|
break;
|
|
case FacebookLoginStatus.error:
|
|
showInSnackBar('Something went wrong with the login process.\n'
|
|
'Here\'s the error Facebook gave us: ${result.errorMessage}');
|
|
break;
|
|
}
|
|
}
|
|
}
|