2022-04-09 05:40:56 +00:00
|
|
|
import 'package:email_validator/email_validator.dart';
|
2021-03-30 11:08:41 +00:00
|
|
|
import 'package:flutter/gestures.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:photos/core/configuration.dart';
|
|
|
|
import 'package:photos/services/user_service.dart';
|
2022-07-03 10:09:01 +00:00
|
|
|
import 'package:photos/ui/common/dynamic_fab.dart';
|
2022-07-01 14:18:05 +00:00
|
|
|
import 'package:photos/ui/common/web_page.dart';
|
2022-04-09 05:40:56 +00:00
|
|
|
|
2021-03-30 11:08:41 +00:00
|
|
|
class LoginPage extends StatefulWidget {
|
|
|
|
LoginPage({Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
2022-07-03 09:45:00 +00:00
|
|
|
State<LoginPage> createState() => _LoginPageState();
|
2021-03-30 11:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _LoginPageState extends State<LoginPage> {
|
|
|
|
final _config = Configuration.instance;
|
2022-04-09 05:40:56 +00:00
|
|
|
bool _emailIsValid = false;
|
2021-03-30 11:08:41 +00:00
|
|
|
String _email;
|
2022-07-03 07:47:15 +00:00
|
|
|
Color _emailInputFieldColor;
|
2021-03-30 11:08:41 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_email = _config.getEmail();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-06-15 06:48:23 +00:00
|
|
|
final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100;
|
2022-04-09 05:40:56 +00:00
|
|
|
|
|
|
|
FloatingActionButtonLocation fabLocation() {
|
|
|
|
if (isKeypadOpen) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return FloatingActionButtonLocation.centerFloat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 11:48:08 +00:00
|
|
|
return Scaffold(
|
2022-06-15 06:48:23 +00:00
|
|
|
resizeToAvoidBottomInset: isKeypadOpen,
|
2022-05-30 15:43:33 +00:00
|
|
|
appBar: AppBar(
|
|
|
|
elevation: 0,
|
|
|
|
leading: IconButton(
|
|
|
|
icon: Icon(Icons.arrow_back),
|
|
|
|
color: Theme.of(context).iconTheme.color,
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
2022-04-09 05:40:56 +00:00
|
|
|
},
|
|
|
|
),
|
2022-05-30 15:43:33 +00:00
|
|
|
),
|
|
|
|
body: _getBody(),
|
|
|
|
floatingActionButton: DynamicFAB(
|
|
|
|
isKeypadOpen: isKeypadOpen,
|
|
|
|
isFormValid: _emailIsValid,
|
|
|
|
buttonText: 'Log in',
|
|
|
|
onPressedFunction: () {
|
2022-06-23 13:06:35 +00:00
|
|
|
UserService.instance.setEmail(_email);
|
2022-07-03 09:49:33 +00:00
|
|
|
UserService.instance
|
|
|
|
.getOtt(context, _email, isCreateAccountScreen: false);
|
2022-06-15 12:44:23 +00:00
|
|
|
FocusScope.of(context).unfocus();
|
2022-05-30 15:43:33 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
floatingActionButtonLocation: fabLocation(),
|
|
|
|
floatingActionButtonAnimator: NoScalingAnimation(),
|
|
|
|
);
|
2021-03-30 11:08:41 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 11:48:08 +00:00
|
|
|
Widget _getBody() {
|
2021-03-30 11:08:41 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
2022-04-09 05:40:56 +00:00
|
|
|
Expanded(
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
Padding(
|
2022-07-03 09:49:33 +00:00
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
|
2022-06-11 08:23:52 +00:00
|
|
|
child: Text(
|
|
|
|
'Welcome back!',
|
|
|
|
style: Theme.of(context).textTheme.headline4,
|
|
|
|
),
|
2021-03-30 11:08:41 +00:00
|
|
|
),
|
2022-04-09 05:40:56 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.fromLTRB(20, 24, 20, 0),
|
|
|
|
child: TextFormField(
|
2022-05-30 11:08:15 +00:00
|
|
|
autofillHints: const [AutofillHints.email],
|
2022-04-09 05:40:56 +00:00
|
|
|
decoration: InputDecoration(
|
|
|
|
fillColor: _emailInputFieldColor,
|
|
|
|
filled: true,
|
2022-05-30 11:08:15 +00:00
|
|
|
hintText: 'Email',
|
2022-07-03 09:49:33 +00:00
|
|
|
contentPadding:
|
|
|
|
EdgeInsets.symmetric(horizontal: 15, vertical: 15),
|
2022-04-09 05:40:56 +00:00
|
|
|
border: UnderlineInputBorder(
|
2022-06-11 08:23:52 +00:00
|
|
|
borderSide: BorderSide.none,
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
),
|
2022-04-09 05:40:56 +00:00
|
|
|
suffixIcon: _emailIsValid
|
|
|
|
? Icon(
|
|
|
|
Icons.check,
|
|
|
|
size: 20,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.inputDecorationTheme
|
|
|
|
.focusedBorder
|
|
|
|
.borderSide
|
|
|
|
.color,
|
|
|
|
)
|
|
|
|
: null,
|
2021-03-30 11:08:41 +00:00
|
|
|
),
|
2022-04-09 05:40:56 +00:00
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_email = value.trim();
|
|
|
|
_emailIsValid = EmailValidator.validate(_email);
|
|
|
|
if (_emailIsValid) {
|
2022-07-03 09:49:33 +00:00
|
|
|
_emailInputFieldColor =
|
|
|
|
Color.fromRGBO(45, 194, 98, 0.2);
|
2022-04-09 05:40:56 +00:00
|
|
|
} else {
|
|
|
|
_emailInputFieldColor = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
autocorrect: false,
|
|
|
|
keyboardType: TextInputType.emailAddress,
|
|
|
|
//initialValue: _email,
|
|
|
|
autofocus: true,
|
2021-03-30 11:08:41 +00:00
|
|
|
),
|
2022-04-09 05:40:56 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 18),
|
|
|
|
child: Divider(
|
|
|
|
thickness: 1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
flex: 5,
|
|
|
|
child: RichText(
|
|
|
|
text: TextSpan(
|
2022-07-03 09:49:33 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.subtitle1
|
|
|
|
.copyWith(fontSize: 12),
|
2022-04-09 05:40:56 +00:00
|
|
|
children: [
|
|
|
|
TextSpan(
|
2022-06-11 08:23:52 +00:00
|
|
|
text: "By clicking log in, I agree to the ",
|
|
|
|
),
|
2022-04-09 05:40:56 +00:00
|
|
|
TextSpan(
|
|
|
|
text: "terms of service",
|
|
|
|
style: TextStyle(
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
),
|
|
|
|
recognizer: TapGestureRecognizer()
|
|
|
|
..onTap = () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return WebPage(
|
2022-06-11 08:23:52 +00:00
|
|
|
"terms",
|
|
|
|
"https://ente.io/terms",
|
|
|
|
);
|
2022-04-09 05:40:56 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TextSpan(text: " and "),
|
|
|
|
TextSpan(
|
|
|
|
text: "privacy policy",
|
|
|
|
style: TextStyle(
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
),
|
|
|
|
recognizer: TapGestureRecognizer()
|
|
|
|
..onTap = () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (BuildContext context) {
|
2022-06-11 08:23:52 +00:00
|
|
|
return WebPage(
|
|
|
|
"privacy",
|
|
|
|
"https://ente.io/privacy",
|
|
|
|
);
|
2022-04-09 05:40:56 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2021-03-30 11:08:41 +00:00
|
|
|
),
|
2022-04-09 05:40:56 +00:00
|
|
|
textAlign: TextAlign.left,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
flex: 2,
|
|
|
|
child: Container(),
|
|
|
|
)
|
|
|
|
],
|
2021-03-30 11:08:41 +00:00
|
|
|
),
|
2022-04-09 05:40:56 +00:00
|
|
|
),
|
|
|
|
],
|
2021-03-30 11:08:41 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.all(8)),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|