mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Display basic login form
This commit is contained in:
parent
c1a667b84b
commit
b315b5ad77
@ -14,6 +14,7 @@ class ComunicApplication extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
// We need to know whether the user is signed in or not to continue
|
// We need to know whether the user is signed in or not to continue
|
||||||
home: FutureBuilder(
|
home: FutureBuilder(
|
||||||
future: AccountCredentialsHelper().signedIn(),
|
future: AccountCredentialsHelper().signedIn(),
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'package:comunic/utils/input_utils.dart';
|
||||||
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// Login route
|
/// Login route
|
||||||
@ -10,8 +12,81 @@ class LoginRoute extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LoginRouteState extends State<LoginRoute> {
|
class _LoginRouteState extends State<LoginRoute> {
|
||||||
|
String _currEmail;
|
||||||
|
String _currPassword;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_currEmail = "";
|
||||||
|
_currPassword = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void _emailChanged(String newEmail) {
|
||||||
|
setState(() {
|
||||||
|
_currEmail = newEmail;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _passwordChanged(String newValue) {
|
||||||
|
setState(() {
|
||||||
|
_currPassword = newValue;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Call this whenever the user request to perform login
|
||||||
|
void _submitForm() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build login form
|
||||||
|
Widget _buildLoginForm(){
|
||||||
|
return SingleChildScrollView(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
Text(tr("Please sign into your Comunic account: ")),
|
||||||
|
//Email address
|
||||||
|
TextField(
|
||||||
|
keyboardType: TextInputType.emailAddress,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: tr("Email address"),
|
||||||
|
alignLabelWithHint: true,
|
||||||
|
errorText:
|
||||||
|
_currEmail.length > 0 && !validateEmail(_currEmail)
|
||||||
|
? tr("Invalid email address!")
|
||||||
|
: null),
|
||||||
|
onChanged: _emailChanged,
|
||||||
|
),
|
||||||
|
|
||||||
|
//Password
|
||||||
|
TextField(
|
||||||
|
obscureText: true,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: tr("Password"),
|
||||||
|
alignLabelWithHint: true,
|
||||||
|
),
|
||||||
|
onChanged: _passwordChanged,
|
||||||
|
),
|
||||||
|
|
||||||
|
RaisedButton(
|
||||||
|
child: Text(tr("Sign in")),
|
||||||
|
onPressed: !validateEmail(_currEmail) || _currPassword.length < 3 ? null : _submitForm,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Text("Hello world");
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text("Comunic"),
|
||||||
|
),
|
||||||
|
body: _buildLoginForm()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
13
lib/utils/input_utils.dart
Normal file
13
lib/utils/input_utils.dart
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/// Input utilities
|
||||||
|
///
|
||||||
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
/// Check out whether a given email address is valid or not
|
||||||
|
///
|
||||||
|
/// Taken from https://medium.com/@nitishk72/form-validation-in-flutter-d762fbc9212c
|
||||||
|
bool validateEmail(String value) {
|
||||||
|
Pattern pattern =
|
||||||
|
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
|
||||||
|
RegExp regex = new RegExp(pattern);
|
||||||
|
return regex.hasMatch(value);
|
||||||
|
}
|
11
lib/utils/intl_utils.dart
Normal file
11
lib/utils/intl_utils.dart
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/// Internationalization utilities
|
||||||
|
///
|
||||||
|
/// @author Pierre HUBERT
|
||||||
|
|
||||||
|
/// Translate a string
|
||||||
|
///
|
||||||
|
/// Translate a given [string] into the current language, if available
|
||||||
|
String tr(String string) {
|
||||||
|
//TODO : create translation system
|
||||||
|
return string;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user