pmu/lib/Components/screens/hero_detail_screen.dart

79 lines
3.0 KiB
Dart
Raw Normal View History

2024-12-16 22:27:12 +04:00
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
2024-12-17 22:28:51 +04:00
import '../../presentation/heroDetail/hero_detail_block.dart';
2024-12-16 22:27:12 +04:00
import '../../data/repositories/hero_repository.dart';
2024-12-17 22:28:51 +04:00
import '../../presentation/heroDetail/hero_detail_state.dart';
import '../../presentation/heroDetail/hero_detail_events.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>();
return BlocProvider(
create: (_) => HeroDetailBloc(heroRepository)..add(FetchHeroDetails(heroId)),
child: Scaffold(
appBar: AppBar(title: const Text('Hero Details')),
2024-12-16 22:27:12 +04:00
body: BlocBuilder<HeroDetailBloc, HeroDetailState>(
builder: (context, state) {
if (state is HeroDetailLoading) {
// Показ индикатора загрузки
return const Center(child: CircularProgressIndicator());
2024-12-16 22:27:12 +04:00
} else if (state is HeroDetailLoaded) {
final hero = state.hero;
2024-12-17 21:29:55 +04:00
return SingleChildScrollView(
// Добавляем прокрутку
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Центрируем изображение героя
Center(
child: hero.portraitUrl != null
? Image.network(hero.portraitUrl!, height: 150)
: const Icon(Icons.image, size: 150),
),
const SizedBox(height: 16),
// Имя героя
Text(
hero.name,
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 16),
// Описание героя
Text(
hero.description ?? 'No description available',
style: const TextStyle(fontSize: 16),
),
],
),
2024-12-17 01:12:29 +04:00
),
2024-12-16 22:27:12 +04:00
);
} else if (state is HeroDetailError) {
// Показ сообщения об ошибке
return Center(
child: Text(
'Error: ${state.message}',
style: const TextStyle(fontSize: 16, color: Colors.red),
),
);
2024-12-16 22:27:12 +04:00
}
// Пустое состояние по умолчанию
return const SizedBox.shrink();
2024-12-16 22:27:12 +04:00
},
),
),
);
}
}