forked from eatvio/eatvio_app
refactor: add intl localization
This commit is contained in:
@@ -3,7 +3,7 @@ import 'dart:convert';
|
||||
import 'package:eatvio_app/core/const.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/core/utils/image_constant.dart';
|
||||
import 'package:eatvio_app/localization/app_localization.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:eatvio_app/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/widgets/app_bar/appbar_title_image.dart';
|
||||
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
|
||||
@@ -40,6 +40,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
@@ -51,7 +52,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("email".tr),
|
||||
Text(s.email),
|
||||
SizedBox(height: 4),
|
||||
BlocSelector<AuthBloc, AuthState, TextEditingController?>(
|
||||
selector: (state) => state.emailController,
|
||||
@@ -66,7 +67,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
},
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text("password".tr),
|
||||
Text(s.password),
|
||||
SizedBox(height: 4),
|
||||
BlocSelector<AuthBloc, AuthState, TextEditingController?>(
|
||||
selector: (state) => state.passwordController,
|
||||
@@ -154,6 +155,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
}
|
||||
|
||||
onTapAuth(AuthState state, BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return () async {
|
||||
List<String> errors = validateFields(state.emailController!.text, state.passwordController!.text);
|
||||
if (errors.isEmpty) {
|
||||
@@ -178,7 +180,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Ошибка'),
|
||||
content: Text('wrong_credentials'.tr),
|
||||
content: Text(s.wrong_credentials),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
@@ -213,22 +215,24 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
}
|
||||
|
||||
List<String> validateFields(String email, String password) {
|
||||
final s = S.of(context);
|
||||
|
||||
List<String> errors = [];
|
||||
|
||||
if (!isEmail(email)) {
|
||||
errors.add('email_invalid'.tr);
|
||||
errors.add(s.email_invalid);
|
||||
}
|
||||
|
||||
if (email.isEmpty) {
|
||||
errors.add('email_empty'.tr);
|
||||
errors.add(s.email_empty);
|
||||
}
|
||||
|
||||
if (password.isEmpty) {
|
||||
errors.add('password_empty'.tr);
|
||||
errors.add(s.password_empty);
|
||||
}
|
||||
|
||||
if (password.length < 6) {
|
||||
errors.add('password_short'.tr);
|
||||
errors.add(s.password_short);
|
||||
}
|
||||
|
||||
return errors;
|
||||
|
||||
Reference in New Issue
Block a user