astronote/lib/widgets/form_sign_in_widget.dart
2020-07-31 17:30:32 +02:00

110 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:astronote_app/providers/sign_in.dart';
class FormLogWidget extends StatefulWidget {
@override
_FormLogWidgetState createState() => _FormLogWidgetState();
}
class _FormLogWidgetState extends State<FormLogWidget> {
TextStyle style = TextStyle(fontFamily: 'Varela Round', fontSize: 20.0);
bool _obscurePassword = true;
final GlobalKey<FormState> _formKey = GlobalKey();
bool _isLoading = false;
TextEditingController urlController = new TextEditingController();
TextEditingController emailController = new TextEditingController();
TextEditingController passwordController = new TextEditingController();
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: Column(
children: <Widget>[
_urlFormField(),
SizedBox(height: MediaQuery.of(context).size.height * 0.03),
_emailFormField(),
SizedBox(height: MediaQuery.of(context).size.height * 0.03),
_passwordFormField(),
SizedBox(height: MediaQuery.of(context).size.height * 0.07),
_logButton()
],
),
);
}
Widget _urlFormField() {
return TextFormField(
controller: urlController,
style: style,
keyboardType: TextInputType.url,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
labelText: "Lien enDI",
suffixIcon: Icon(Icons.link,color: Colors.indigo[900]),
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
);
}
Widget _emailFormField() {
return TextFormField(
controller: emailController,
style: style,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
labelText: "E-mail",
suffixIcon: Icon(Icons.mail,color: Colors.indigo[900]),
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
);
}
Widget _passwordFormField() {
return TextFormField(
controller: passwordController,
style: style,
obscureText: _obscurePassword,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
labelText: "Mot de passe",
suffixIcon: IconButton(
icon: Icon(
_obscurePassword ? Icons.visibility : Icons.visibility_off,color: Colors.indigo[900]),
onPressed: () {
setState(() => _obscurePassword = !_obscurePassword);
}),
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
);
}
Widget _logButton() {
return Material(
elevation: 3.0,
borderRadius: BorderRadius.circular(30.0),
color: Colors.indigo[900],
child: MaterialButton(
// minWidth: MediaQuery.of(context).size.width,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
setState(() {
_isLoading = true;
});
SignIn().login(urlController.text, emailController.text, passwordController.text);
},
child: Text("Connexion",
textAlign: TextAlign.center,
style: style.copyWith(
color: Colors.white, fontWeight: FontWeight.bold)),
)
);
}
}