refactor: add intl localization

This commit is contained in:
mso7nueh
2024-09-11 17:39:00 +03:00
parent 69472f422e
commit 6c69bbbf41
29 changed files with 1468 additions and 312 deletions

View File

@@ -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;

View File

@@ -1,10 +1,9 @@
import 'dart:convert';
import 'dart:math';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:carousel_slider_plus/carousel_slider_plus.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/localization/app_localization.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:eatvio_app/theme/app_decoration.dart';
import 'package:eatvio_app/theme/custom_text_style.dart';
import 'package:eatvio_app/theme/theme_helper.dart';
@@ -194,7 +193,8 @@ class MyProfileScreen extends StatelessWidget {
};
}
_buildCarousel(BuildContext contex, MyProfileLoadedState state) {
_buildCarousel(BuildContext context, MyProfileLoadedState state) {
final s = S.of(context);
return CarouselSlider(
options: CarouselOptions(height: 340),
items: [1, 2, 3].map((chartType) {
@@ -207,7 +207,7 @@ class MyProfileScreen extends StatelessWidget {
child: Column(
children: [
Text(
"weight_chart".tr,
s.weight_chart,
style: CustomTextStyles.titleMediumBlack.copyWith(
color: appTheme.black900,
),
@@ -225,7 +225,7 @@ class MyProfileScreen extends StatelessWidget {
return Column(
children: [
Text(
"bodymass_chart".tr,
s.bodymass_chart,
style: CustomTextStyles.titleMediumBlack.copyWith(
color: appTheme.black900,
),
@@ -247,14 +247,14 @@ class MyProfileScreen extends StatelessWidget {
child: Column(
children: [
Text(
"circumferences_chart".tr,
s.circumferences_chart,
style: CustomTextStyles.titleMediumBlack.copyWith(
color: appTheme.black900,
),
),
SizedBox(height: 30),
_buildCircumferenceChart(context, state.circumferences, state.chartDates),
_buildChartLegend(),
_buildChartLegend(context),
],
),
);
@@ -267,9 +267,10 @@ class MyProfileScreen extends StatelessWidget {
);
}
_buildChartLegend() {
_buildChartLegend(BuildContext context) {
final s = S.of(context);
final colors = [Colors.pink, Colors.green, Colors.purple];
final titles = ["chest".tr, "waist".tr, "hips".tr];
final titles = [s.chest, s.waist, s.hips];
final style = TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
@@ -650,13 +651,14 @@ class MyProfileScreen extends StatelessWidget {
/// Section Widget
_buildPlans(BuildContext context, List<dynamic>? plans, List<dynamic>? imagePaths, List<dynamic>? states) {
final s = S.of(context);
return Padding(
padding: EdgeInsets.only(left: 7),
child: Column(
children: [
Padding(
padding: EdgeInsets.only(left: 15),
child: Text("plans_complete".tr, style: CustomTextStyles.titleMediumBlack.copyWith(color: appTheme.black900)),
child: Text(s.plans_complete, style: CustomTextStyles.titleMediumBlack.copyWith(color: appTheme.black900)),
),
SizedBox(height: 5),
Container(
@@ -735,7 +737,7 @@ class MyProfileScreen extends StatelessWidget {
child: Container(
width: 70,
margin: EdgeInsets.only(bottom: 14, right: 22),
child: Text("$state".tr, maxLines: 3, overflow: TextOverflow.ellipsis, style: theme.textTheme.titleSmall),
child: Text("$state", maxLines: 3, overflow: TextOverflow.ellipsis, style: theme.textTheme.titleSmall),
),
),
],
@@ -765,6 +767,7 @@ class MyProfileScreen extends StatelessWidget {
}
_editCircumference(BuildContext context, MyProfileLoadedState state) {
final s = S.of(context);
showDialog(
context: context,
builder: (context) {
@@ -779,7 +782,7 @@ class MyProfileScreen extends StatelessWidget {
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 5),
child: Text("chest_circumference".tr, style: theme.textTheme.bodyLarge),
child: Text(s.chest_circumference, style: theme.textTheme.bodyLarge),
),
SizedBox(height: 5),
CustomTextFormField(
@@ -791,7 +794,7 @@ class MyProfileScreen extends StatelessWidget {
),
Padding(
padding: EdgeInsets.symmetric(vertical: 15),
child: Text("waist_circumference".tr, style: theme.textTheme.bodyLarge),
child: Text(s.waist_circumference, style: theme.textTheme.bodyLarge),
),
SizedBox(height: 5),
CustomTextFormField(
@@ -803,7 +806,7 @@ class MyProfileScreen extends StatelessWidget {
),
Padding(
padding: EdgeInsets.symmetric(vertical: 15),
child: Text("hip_circumference".tr, style: theme.textTheme.bodyLarge),
child: Text(s.hip_circumference, style: theme.textTheme.bodyLarge),
),
SizedBox(height: 5),
CustomTextFormField(
@@ -876,6 +879,7 @@ class MyProfileScreen extends StatelessWidget {
}
_editWeight(BuildContext context, MyProfileLoadedState state) {
final s = S.of(context);
showDialog(
context: context,
builder: (context) {
@@ -887,7 +891,7 @@ class MyProfileScreen extends StatelessWidget {
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 5),
child: Text("weight".tr, style: theme.textTheme.bodyLarge),
child: Text(s.weight, style: theme.textTheme.bodyLarge),
),
SizedBox(height: 5),
CustomTextFormField(