103 lines
3.2 KiB
Dart
Raw Normal View History

2024-12-18 03:01:46 +04:00
import 'package:flutter/material.dart';
2024-12-18 13:10:57 +04:00
import 'package:flutter_bloc/flutter_bloc.dart';
2024-12-18 03:01:46 +04:00
import '../../domain/quote.dart';
2024-12-18 13:10:57 +04:00
import '../like_bloc/like_bloc.dart';
import '../like_bloc/like_state.dart';
2024-12-18 03:01:46 +04:00
import 'home_page.dart';
class QuoteCard extends StatelessWidget {
final Quote quote;
final VoidCallback onFavoriteToggle;
2024-12-18 13:10:57 +04:00
const QuoteCard({Key? key, required this.quote, required this.onFavoriteToggle}) : super(key: key);
2024-12-18 03:01:46 +04:00
@override
Widget build(BuildContext context) {
return Card(
2024-12-18 13:10:57 +04:00
margin: const EdgeInsets.all(8.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
quote.text,
style: const TextStyle(fontSize: 18.0),
),
const SizedBox(height: 8.0),
Text(
'- ${quote.author}',
style: const TextStyle(fontStyle: FontStyle.italic, fontSize: 16.0),
2024-12-18 03:01:46 +04:00
),
2024-12-18 13:10:57 +04:00
const SizedBox(height: 8.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ElevatedButton.icon(
onPressed: onFavoriteToggle,
icon: BlocBuilder<LikeBloc, LikeState>(
builder: (context, state) {
final isLiked = state.likedIds?.contains(quote.id) ?? false;
return Icon(
isLiked ? Icons.favorite : Icons.favorite_border,
color: isLiked ? Colors.red : Colors.grey,
);
},
),
label: BlocBuilder<LikeBloc, LikeState>(
builder: (context, state) {
final isLiked = state.likedIds?.contains(quote.id) ?? false;
return Text(isLiked ? 'Убрать из избранного' : 'Добавить в избранное');
},
),
),
],
),
],
),
2024-12-18 03:01:46 +04:00
),
);
}
}
class QuoteDetailScreen extends StatelessWidget {
final Quote quote;
const QuoteDetailScreen({super.key, required this.quote});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Детали цитаты'),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.network(
quote.imagePath,
height: 150,
2024-12-18 13:10:57 +04:00
errorBuilder: (_, __, ___) => const Icon(Icons.error, color: Colors.red),
2024-12-18 03:01:46 +04:00
),
const SizedBox(height: 20),
Text(
quote.text,
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
const SizedBox(height: 10),
Text(
'- ${quote.author}',
style: const TextStyle(fontSize: 18, color: Colors.grey),
),
],
),
),
),
);
}
}