7 перевод робит

This commit is contained in:
GokaPek 2024-10-20 15:05:45 +04:00
parent af7174d02c
commit f4cbfe7e68
7 changed files with 153 additions and 19 deletions

View File

@ -72,7 +72,8 @@ class _$HomeStateCWProxyImpl implements _$HomeStateCWProxy {
// ignore: cast_nullable_to_non_nullable // ignore: cast_nullable_to_non_nullable
: isLoading as bool, : isLoading as bool,
isPaginationLoading: isPaginationLoading:
isPaginationLoading == const $CopyWithPlaceholder() || isPaginationLoading == null isPaginationLoading == const $CopyWithPlaceholder() ||
isPaginationLoading == null
? _value.isPaginationLoading ? _value.isPaginationLoading
// ignore: cast_nullable_to_non_nullable // ignore: cast_nullable_to_non_nullable
: isPaginationLoading as bool, : isPaginationLoading as bool,

View File

@ -1,9 +1,13 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:labs_petrushin/Presentation/common/svg_objects.dart';
import 'package:labs_petrushin/Presentation/home_page/bloc/bloc.dart'; import 'package:labs_petrushin/Presentation/home_page/bloc/bloc.dart';
import 'package:labs_petrushin/Presentation/home_page/bloc/events.dart'; import 'package:labs_petrushin/Presentation/home_page/bloc/events.dart';
import 'package:labs_petrushin/Presentation/home_page/bloc/state.dart'; import 'package:labs_petrushin/Presentation/home_page/bloc/state.dart';
import 'package:labs_petrushin/Presentation/locale_bloc/locale_bloc.dart';
import 'package:labs_petrushin/Presentation/locale_bloc/locale_events.dart';
import 'package:labs_petrushin/Presentation/locale_bloc/locale_state.dart';
import 'package:labs_petrushin/components/extensions/context_x.dart'; import 'package:labs_petrushin/components/extensions/context_x.dart';
import '../../Presentation/detailPage.dart'; import '../../Presentation/detailPage.dart';
import '../../components/util/Debounce.dart'; import '../../components/util/Debounce.dart';
@ -77,11 +81,28 @@ class BodyState extends State<Body> {
padding: const EdgeInsets.all(12), padding: const EdgeInsets.all(12),
child: CupertinoSearchTextField( child: CupertinoSearchTextField(
controller: searchController, controller: searchController,
placeholder: context.locale.search,
onChanged: (search) { onChanged: (search) {
Debounce.run(() => context.read<HomeBloc>().add(HomeLoadDataEvent(search: search))); Debounce.run(() => context.read<HomeBloc>().add(HomeLoadDataEvent(search: search)));
}, },
), ),
), ),
GestureDetector(
onTap: () => context.read<LocaleBloc>().add(const ChangeLocaleEvent()),
child: SizedBox.square(
dimension: 50,
child: Padding(
padding: const EdgeInsets.only(right: 12),
child: BlocBuilder<LocaleBloc, LocaleState>(
builder: (context, state) {
return state.currentLocale.languageCode == 'ru'
? const SvgRu()
: const SvgUk();
},
),
),
),
),
BlocBuilder<HomeBloc, HomeState>( BlocBuilder<HomeBloc, HomeState>(
builder: (context, state) => state.error != null builder: (context, state) => state.error != null
? Text( ? Text(

View File

@ -0,0 +1,19 @@
import 'dart:async';
import 'dart:ui';
import 'package:labs_petrushin/components/locale/l10n/app_locale.dart';
import 'package:labs_petrushin/Presentation/locale_bloc/locale_events.dart';
import 'package:labs_petrushin/Presentation/locale_bloc/locale_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class LocaleBloc extends Bloc<LocaleEvent, LocaleState> {
LocaleBloc(Locale defaultLocale) : super(LocaleState(currentLocale: defaultLocale)) {
on<ChangeLocaleEvent>(_onChangeLocale);
}
FutureOr<void> _onChangeLocale(ChangeLocaleEvent event, Emitter<LocaleState> emit) async {
final toChange = AppLocale.supportedLocales
.firstWhere((e) => e.languageCode != state.currentLocale.languageCode);
emit(state.copyWith(currentLocale: toChange));
}
}

View File

@ -0,0 +1,7 @@
abstract class LocaleEvent {
const LocaleEvent();
}
class ChangeLocaleEvent extends LocaleEvent {
const ChangeLocaleEvent();
}

View File

@ -0,0 +1,15 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import 'package:copy_with_extension/copy_with_extension.dart';
part 'locale_state.g.dart';
@CopyWith()
class LocaleState extends Equatable {
final Locale currentLocale;
const LocaleState({required this.currentLocale});
@override
List<Object?> get props => [currentLocale];
}

View File

@ -0,0 +1,58 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'locale_state.dart';
// **************************************************************************
// CopyWithGenerator
// **************************************************************************
abstract class _$LocaleStateCWProxy {
LocaleState currentLocale(Locale currentLocale);
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `LocaleState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
///
/// Usage
/// ```dart
/// LocaleState(...).copyWith(id: 12, name: "My name")
/// ````
LocaleState call({
Locale? currentLocale,
});
}
/// Proxy class for `copyWith` functionality. This is a callable class and can be used as follows: `instanceOfLocaleState.copyWith(...)`. Additionally contains functions for specific fields e.g. `instanceOfLocaleState.copyWith.fieldName(...)`
class _$LocaleStateCWProxyImpl implements _$LocaleStateCWProxy {
const _$LocaleStateCWProxyImpl(this._value);
final LocaleState _value;
@override
LocaleState currentLocale(Locale currentLocale) =>
this(currentLocale: currentLocale);
@override
/// This function **does support** nullification of nullable fields. All `null` values passed to `non-nullable` fields will be ignored. You can also use `LocaleState(...).copyWith.fieldName(...)` to override fields one at a time with nullification support.
///
/// Usage
/// ```dart
/// LocaleState(...).copyWith(id: 12, name: "My name")
/// ````
LocaleState call({
Object? currentLocale = const $CopyWithPlaceholder(),
}) {
return LocaleState(
currentLocale:
currentLocale == const $CopyWithPlaceholder() || currentLocale == null
? _value.currentLocale
// ignore: cast_nullable_to_non_nullable
: currentLocale as Locale,
);
}
}
extension $LocaleStateCopyWith on LocaleState {
/// Returns a callable class that can be used as follows: `instanceOfLocaleState.copyWith(...)` or like so:`instanceOfLocaleState.copyWith.fieldName(...)`.
// ignore: library_private_types_in_public_api
_$LocaleStateCWProxy get copyWith => _$LocaleStateCWProxyImpl(this);
}

View File

@ -1,5 +1,9 @@
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:labs_petrushin/Presentation/home_page/bloc/bloc.dart'; import 'package:labs_petrushin/Presentation/home_page/bloc/bloc.dart';
import 'package:labs_petrushin/Presentation/locale_bloc/locale_bloc.dart';
import 'package:labs_petrushin/Presentation/locale_bloc/locale_state.dart';
import 'package:labs_petrushin/components/locale/l10n/app_locale.dart'; import 'package:labs_petrushin/components/locale/l10n/app_locale.dart';
import 'package:labs_petrushin/repositories/food_repository.dart'; import 'package:labs_petrushin/repositories/food_repository.dart';
import 'home_page/home_page.dart'; import 'home_page/home_page.dart';
@ -14,24 +18,33 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return BlocProvider<LocaleBloc>(
title: 'Petrushin demo', lazy: false,
localizationsDelegates: AppLocale.localizationsDelegates, create: (context) => LocaleBloc(Locale(Platform.localeName)),
supportedLocales: AppLocale.supportedLocales, child: BlocBuilder<LocaleBloc, LocaleState>(
debugShowCheckedModeBanner: false, builder: (context, state) {
theme: ThemeData( return MaterialApp(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red), title: 'Petrushin demo',
useMaterial3: true, locale: state.currentLocale,
), localizationsDelegates: AppLocale.localizationsDelegates,
home: RepositoryProvider<FoodRepository>( supportedLocales: AppLocale.supportedLocales,
lazy: true, debugShowCheckedModeBanner: false,
create: (_) => FoodRepository(), theme: ThemeData(
child: BlocProvider<HomeBloc>( colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
lazy: false, useMaterial3: true,
create: (context) => HomeBloc(context.read<FoodRepository>()),
child: const MyHomePage(
title: 'Петрушин Егор Александрович',
), ),
))); home: RepositoryProvider<FoodRepository>(
lazy: true,
create: (_) => FoodRepository(),
child: BlocProvider<HomeBloc>(
lazy: false,
create: (context) => HomeBloc(context.read<FoodRepository>()),
child: const MyHomePage(
title: 'Петрушин Егор Александрович',
),
)));
}
),
);
} }
} }