2024-12-16 22:27:12 +04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
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';
|
2024-12-16 23:50:05 +04:00
|
|
|
import '../../Components/locale/l10n/app_locale.dart';
|
2024-12-16 22:27:12 +04:00
|
|
|
|
|
|
|
class HeroDetailScreen extends StatelessWidget {
|
|
|
|
final int heroId;
|
|
|
|
|
|
|
|
const HeroDetailScreen({Key? key, required this.heroId}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final heroRepository = context.read<HeroRepository>();
|
|
|
|
|
2024-12-16 23:50:05 +04:00
|
|
|
// Получаем текущую локализацию
|
|
|
|
final locale = AppLocale.of(context)!;
|
|
|
|
|
2024-12-16 22:27:12 +04:00
|
|
|
return BlocProvider(
|
|
|
|
create: (_) => HeroDetailBloc(heroRepository)..add(FetchHeroDetails(heroId)),
|
|
|
|
child: Scaffold(
|
2024-12-16 23:50:05 +04:00
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(locale.heroDetailsTitle),
|
|
|
|
),
|
2024-12-16 22:27:12 +04:00
|
|
|
body: BlocBuilder<HeroDetailBloc, HeroDetailState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
if (state is HeroDetailLoading) {
|
2024-12-16 23:50:05 +04:00
|
|
|
return const Center(child: CircularProgressIndicator());
|
2024-12-16 22:27:12 +04:00
|
|
|
} else if (state is HeroDetailLoaded) {
|
|
|
|
final hero = state.hero;
|
2024-12-16 23:50:05 +04:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
],
|
2024-12-16 22:27:12 +04:00
|
|
|
);
|
|
|
|
} else if (state is HeroDetailError) {
|
2024-12-16 23:50:05 +04:00
|
|
|
return Center(child: Text(state.message));
|
2024-12-16 22:27:12 +04:00
|
|
|
}
|
2024-12-16 23:50:05 +04:00
|
|
|
return const SizedBox.shrink();
|
2024-12-16 22:27:12 +04:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|