58 lines
2.1 KiB
Dart
58 lines
2.1 KiB
Dart
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';
|
|
|
|
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: Text('Hero Details')),
|
|
body: BlocBuilder<HeroDetailBloc, HeroDetailState>(
|
|
builder: (context, state) {
|
|
if (state is HeroDetailLoading) {
|
|
return 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,
|
|
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),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
} else if (state is HeroDetailError) {
|
|
return Center(child: Text('Error: ${state.message}'));
|
|
}
|
|
return SizedBox.shrink();
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |