Skip to content

Commit

Permalink
[#6] Add app constants and update localizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Thieurom committed Aug 7, 2023
1 parent d25e885 commit 65327b0
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"hello": "Hello!"
"emailInputHint": "Email",
"passwordInputHint": "Password",
"loginButton": "Log in"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_th.arb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"hello": "สวัสดี"
"emailInputHint": "",
"passwordInputHint": "",
"loginButton": ""
}
4 changes: 3 additions & 1 deletion lib/l10n/app_vi.arb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"hello": "Xin chào!"
"emailInputHint": "",
"passwordInputHint": "",
"loginButton": ""
}
8 changes: 5 additions & 3 deletions lib/screens/login/login_form.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:survey_flutter/screens/widgets/primary_button_style.dart';
import 'package:survey_flutter/screens/widgets/primary_text_field_decoration.dart';

Expand All @@ -12,12 +13,13 @@ class _LoginFormState extends State<LoginForm> {
final _formKey = GlobalKey<FormState>();

TextTheme get _textTheme => Theme.of(context).textTheme;
AppLocalizations get _localizations => AppLocalizations.of(context)!;

TextFormField get _emailTextField => TextFormField(
keyboardType: TextInputType.emailAddress,
autocorrect: false,
decoration: PrimaryTextFieldDecoration(
hintText: 'Email',
hintText: _localizations.emailInputHint,
hintTextStyle: _textTheme.bodyMedium,
),
style: _textTheme.bodyMedium,
Expand All @@ -27,7 +29,7 @@ class _LoginFormState extends State<LoginForm> {
autocorrect: false,
obscureText: true,
decoration: PrimaryTextFieldDecoration(
hintText: 'Password',
hintText: _localizations.passwordInputHint,
hintTextStyle: _textTheme.bodyMedium,
),
style: _textTheme.bodyMedium,
Expand All @@ -36,7 +38,7 @@ class _LoginFormState extends State<LoginForm> {
ElevatedButton get _loginButton => ElevatedButton(
style: PrimaryButtonStyle(hintTextStyle: _textTheme.labelMedium),
onPressed: _submit,
child: const Text('Log in'),
child: Text(_localizations.loginButton),
);

void _submit() {
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/widgets/primary_button_style.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:survey_flutter/theme/app_constants.dart';

class PrimaryButtonStyle extends ButtonStyle {
PrimaryButtonStyle({required TextStyle? hintTextStyle})
Expand All @@ -11,7 +12,7 @@ class PrimaryButtonStyle extends ButtonStyle {
overlayColor: MaterialStateProperty.all(Colors.black12),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
borderRadius: BorderRadius.circular(Metrics.defaultBorderRadius),
),
),
);
Expand Down
3 changes: 2 additions & 1 deletion lib/screens/widgets/primary_text_field_decoration.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:flutter/material.dart';
import 'package:survey_flutter/theme/app_constants.dart';

class PrimaryTextFieldDecoration extends InputDecoration {
PrimaryTextFieldDecoration(
{required String hintText, required TextStyle? hintTextStyle})
: super(
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(12.0),
borderRadius: BorderRadius.circular(Metrics.defaultBorderRadius),
),
fillColor: Colors.white24,
filled: true,
Expand Down
3 changes: 3 additions & 0 deletions lib/theme/app_constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Metrics {
static const defaultBorderRadius = 12.0;
}

0 comments on commit 65327b0

Please sign in to comment.