-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#6] Create LoginScreen with LoginForm
- Loading branch information
Showing
7 changed files
with
180 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,4 @@ SPEC CHECKSUMS: | |
|
||
PODFILE CHECKSUM: 632d6ac0b577d6e268ff7a13a105bbc4f7941989 | ||
|
||
COCOAPODS: 1.12.0 | ||
COCOAPODS: 1.12.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:survey_flutter/screens/widgets/primary_button_style.dart'; | ||
import 'package:survey_flutter/screens/widgets/primary_text_field_decoration.dart'; | ||
|
||
class LoginForm extends StatefulWidget { | ||
const LoginForm({Key? key}) : super(key: key); | ||
@override | ||
State<StatefulWidget> createState() => _LoginFormState(); | ||
} | ||
|
||
class _LoginFormState extends State<LoginForm> { | ||
final _formKey = GlobalKey<FormState>(); | ||
|
||
TextTheme get _textTheme => Theme.of(context).textTheme; | ||
|
||
TextFormField get _emailTextField => TextFormField( | ||
keyboardType: TextInputType.emailAddress, | ||
autocorrect: false, | ||
decoration: PrimaryTextFieldDecoration( | ||
hintText: 'Email', | ||
hintTextStyle: _textTheme.bodyMedium, | ||
), | ||
style: _textTheme.bodyMedium, | ||
); | ||
|
||
TextFormField get _passwordTextField => TextFormField( | ||
autocorrect: false, | ||
obscureText: true, | ||
decoration: PrimaryTextFieldDecoration( | ||
hintText: 'Password', | ||
hintTextStyle: _textTheme.bodyMedium, | ||
), | ||
style: _textTheme.bodyMedium, | ||
); | ||
|
||
ElevatedButton get _loginButton => ElevatedButton( | ||
style: PrimaryButtonStyle(hintTextStyle: _textTheme.labelMedium), | ||
onPressed: _submit, | ||
child: const Text('Log in'), | ||
); | ||
|
||
void _submit() { | ||
// TODO: Integrate with API | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
const fieldSpacing = 20.0; | ||
return Form( | ||
key: _formKey, | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
_emailTextField, | ||
const SizedBox( | ||
height: fieldSpacing, | ||
), | ||
_passwordTextField, | ||
const SizedBox( | ||
height: fieldSpacing, | ||
), | ||
SizedBox( | ||
height: 56, | ||
width: double.infinity, | ||
child: _loginButton, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:survey_flutter/screens/login/login_form.dart'; | ||
|
||
// TODO: Update to `/login` | ||
const routePathLoginScreen = '/'; | ||
|
||
class LoginScreen extends StatefulWidget { | ||
const LoginScreen({Key? key}) : super(key: key); | ||
@override | ||
State<StatefulWidget> createState() => _LoginSrceenState(); | ||
} | ||
|
||
class _LoginSrceenState extends State<LoginScreen> { | ||
late final _gradientOverlay = Container( | ||
decoration: BoxDecoration( | ||
gradient: LinearGradient( | ||
begin: Alignment.topCenter, | ||
end: Alignment.bottomCenter, | ||
colors: [ | ||
Colors.black.withOpacity(0.2), | ||
Colors.black, | ||
], | ||
), | ||
), | ||
); | ||
|
||
late final _loginForm = Padding( | ||
padding: const EdgeInsets.symmetric( | ||
horizontal: 24.0, | ||
), | ||
child: LoginForm(), | ||
); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
resizeToAvoidBottomInset: false, | ||
body: Stack( | ||
alignment: AlignmentDirectional.center, | ||
fit: StackFit.expand, | ||
children: [ | ||
_gradientOverlay, | ||
_loginForm, | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class PrimaryButtonStyle extends ButtonStyle { | ||
PrimaryButtonStyle({required TextStyle? hintTextStyle}) | ||
: super( | ||
textStyle: MaterialStateProperty.all( | ||
hintTextStyle, | ||
), | ||
backgroundColor: MaterialStateProperty.all(Colors.white), | ||
foregroundColor: MaterialStateProperty.all(Colors.black), | ||
overlayColor: MaterialStateProperty.all(Colors.black12), | ||
shape: MaterialStateProperty.all<RoundedRectangleBorder>( | ||
RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(12.0), | ||
), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class PrimaryTextFieldDecoration extends InputDecoration { | ||
PrimaryTextFieldDecoration( | ||
{required String hintText, required TextStyle? hintTextStyle}) | ||
: super( | ||
border: OutlineInputBorder( | ||
borderSide: BorderSide.none, | ||
borderRadius: BorderRadius.circular(12.0), | ||
), | ||
fillColor: Colors.white24, | ||
filled: true, | ||
hintText: hintText, | ||
hintStyle: hintTextStyle?.copyWith(color: Colors.white24), | ||
errorMaxLines: 2, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:survey_flutter/gen/fonts.gen.dart'; | ||
|
||
class AppTheme { | ||
static ThemeData get light => ThemeData( | ||
fontFamily: FontFamily.neuzeit, | ||
textTheme: const TextTheme( | ||
bodyMedium: TextStyle( | ||
color: Colors.white, | ||
fontSize: 17, | ||
fontWeight: FontWeight.normal, | ||
), | ||
labelMedium: TextStyle( | ||
color: Colors.white, | ||
fontSize: 17, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
); | ||
} |