попытки в локализацию
This commit is contained in:
parent
8b6d1d8dab
commit
2e52b5d09d
@ -72,16 +72,6 @@ abstract class AppLocale {
|
||||
|
||||
static const LocalizationsDelegate<AppLocale> delegate = _AppLocaleDelegate();
|
||||
|
||||
/// A list of this localizations delegate along with the default localizations
|
||||
/// delegates.
|
||||
///
|
||||
/// Returns a list of localizations delegates containing this delegate along with
|
||||
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
|
||||
/// and GlobalWidgetsLocalizations.delegate.
|
||||
///
|
||||
/// Additional delegates can be added by appending to this list in
|
||||
/// MaterialApp. This list does not have to be used at all if a custom list
|
||||
/// of delegates is preferred or required.
|
||||
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
|
||||
delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
@ -89,35 +79,21 @@ abstract class AppLocale {
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
];
|
||||
|
||||
/// A list of this localizations delegate's supported locales.
|
||||
static const List<Locale> supportedLocales = <Locale>[
|
||||
Locale('en'),
|
||||
Locale('ru')
|
||||
];
|
||||
|
||||
/// No description provided for @search.
|
||||
///
|
||||
/// In ru, this message translates to:
|
||||
/// **'Поиск'**
|
||||
// Существующие строки
|
||||
String get search;
|
||||
|
||||
/// No description provided for @liked.
|
||||
///
|
||||
/// In ru, this message translates to:
|
||||
/// **'нравится!'**
|
||||
String get liked;
|
||||
|
||||
/// No description provided for @disliked.
|
||||
///
|
||||
/// In ru, this message translates to:
|
||||
/// **'не нравится :<'**
|
||||
String get disliked;
|
||||
|
||||
/// No description provided for @arbEnding.
|
||||
///
|
||||
/// In ru, this message translates to:
|
||||
/// **'ЗАПЯТАЯ'**
|
||||
String get arbEnding;
|
||||
|
||||
// Новые строки для HeroDetailScreen
|
||||
String get heroDetailsTitle;
|
||||
String get heroNoImage;
|
||||
String get heroNoDescription;
|
||||
}
|
||||
|
||||
class _AppLocaleDelegate extends LocalizationsDelegate<AppLocale> {
|
||||
|
@ -16,5 +16,15 @@ class AppLocaleEn extends AppLocale {
|
||||
String get disliked => 'disliked :<';
|
||||
|
||||
@override
|
||||
String get arbEnding => 'ЗАПЯТАЯ';
|
||||
String get arbEnding => 'COMMA';
|
||||
|
||||
// Добавленные строки
|
||||
@override
|
||||
String get heroDetailsTitle => 'Hero Details';
|
||||
|
||||
@override
|
||||
String get heroNoImage => 'No image available';
|
||||
|
||||
@override
|
||||
String get heroNoDescription => 'No description available';
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import 'app_locale.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
import 'app_locale.dart';
|
||||
|
||||
/// The translations for Russian (`ru`).
|
||||
class AppLocaleRu extends AppLocale {
|
||||
@ -17,4 +17,14 @@ class AppLocaleRu extends AppLocale {
|
||||
|
||||
@override
|
||||
String get arbEnding => 'ЗАПЯТАЯ';
|
||||
|
||||
// Добавленные строки
|
||||
@override
|
||||
String get heroDetailsTitle => 'Детали героя';
|
||||
|
||||
@override
|
||||
String get heroNoImage => 'Изображение отсутствует';
|
||||
|
||||
@override
|
||||
String get heroNoDescription => 'Описание отсутствует';
|
||||
}
|
@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../presentation/home_page/bloc/hero_detail_bloc.dart';
|
||||
import '../../data/dtos/hero_dto.dart';
|
||||
import '../../data/repositories/hero_repository.dart';
|
||||
import '../../Components/locale/l10n/app_locale.dart';
|
||||
|
||||
class HeroDetailScreen extends StatelessWidget {
|
||||
final int heroId;
|
||||
@ -13,43 +14,45 @@ class HeroDetailScreen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final heroRepository = context.read<HeroRepository>();
|
||||
|
||||
// Получаем текущую локализацию
|
||||
final locale = AppLocale.of(context)!;
|
||||
|
||||
return BlocProvider(
|
||||
create: (_) => HeroDetailBloc(heroRepository)..add(FetchHeroDetails(heroId)),
|
||||
child: Scaffold(
|
||||
appBar: AppBar(title: Text('Hero Details')),
|
||||
appBar: AppBar(
|
||||
title: Text(locale.heroDetailsTitle),
|
||||
),
|
||||
body: BlocBuilder<HeroDetailBloc, HeroDetailState>(
|
||||
builder: (context, state) {
|
||||
if (state is HeroDetailLoading) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is HeroDetailLoaded) {
|
||||
final hero = state.hero;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
return Column(
|
||||
children: [
|
||||
Center(
|
||||
child: hero.portraitUrl != null
|
||||
? Image.network(hero.portraitUrl!, height: 150)
|
||||
: Icon(Icons.image, size: 150),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
hero.name,
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
hero.description ?? 'No description available',
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
hero.portraitUrl != null
|
||||
? Image.network(hero.portraitUrl!)
|
||||
: Column(
|
||||
children: [
|
||||
const Icon(Icons.image, size: 100),
|
||||
Text(locale.heroNoImage),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
hero.name,
|
||||
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(
|
||||
hero.description ?? locale.heroNoDescription,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (state is HeroDetailError) {
|
||||
return Center(child: Text('Error: ${state.message}'));
|
||||
return Center(child: Text(state.message));
|
||||
}
|
||||
return SizedBox.shrink();
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
|
@ -8,6 +8,8 @@ import 'package:provider/provider.dart';
|
||||
import 'presentation/home_page/bloc/hero_search_bloc.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import '../../Components/locale/l10n/app_locale.dart';
|
||||
|
||||
|
||||
|
||||
|
||||
@ -47,6 +49,8 @@ class MyApp extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
return MaterialApp(
|
||||
localizationsDelegates: AppLocale.localizationsDelegates,
|
||||
supportedLocales: AppLocale.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
|
Loading…
Reference in New Issue
Block a user