106 lines
3.1 KiB
Dart
106 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter/cupertino.dart';
|
||
import 'package:pmu/domain/models/card.dart';
|
||
import 'package:pmu/presentation/details_page/details_page.dart';
|
||
|
||
part 'card.dart';
|
||
|
||
|
||
class MyHomePage extends StatefulWidget {
|
||
const MyHomePage({super.key, required this.title});
|
||
|
||
final String title;
|
||
|
||
@override
|
||
State<MyHomePage> createState() => _MyHomePageState();
|
||
}
|
||
|
||
class _MyHomePageState extends State<MyHomePage> {
|
||
final Color _color = Colors.deepPurple.shade300;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
backgroundColor: _color,
|
||
title: Text(widget.title),
|
||
),
|
||
body: const Body(),
|
||
);
|
||
}
|
||
}
|
||
|
||
class Body extends StatelessWidget {
|
||
const Body({super.key});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final data = [
|
||
CardData(
|
||
'Абиссинская',
|
||
descriptionText: 'Эфиопия',
|
||
icon: Icons.favorite,
|
||
imageUrl: 'https://ajo-pet.ru/u/ckupload/files/abissinskaya-koshka-sorrel.jpg'
|
||
),
|
||
CardData(
|
||
'Британская',
|
||
descriptionText: 'Великобритания',
|
||
icon: Icons.ac_unit,
|
||
imageUrl: 'https://zoopt.ru/upload/iblock/ce2/britan.png',
|
||
),
|
||
CardData(
|
||
'Невская Маскарадная',
|
||
descriptionText: 'СССР',
|
||
icon: Icons.ac_unit,
|
||
imageUrl: 'https://wikipet.ru/wp-content/uploads/2018-10/1539243031_1491312430_nev_mask_info.jpg',
|
||
),
|
||
CardData(
|
||
'Персидская',
|
||
descriptionText: 'Иран',
|
||
imageUrl: 'https://s4.stc.all.kpcdn.net/family/wp-content/uploads/2022/08/top-persidskaya-koshka-960h540.jpg',
|
||
),
|
||
CardData(
|
||
'Ангорская',
|
||
descriptionText: 'Турция',
|
||
imageUrl: 'https://ornella.club/uploads/posts/2023-05/thumbs/1685245234_ornella-club-p-sibirskaya-angorskaya-koshka-krasivo-2.jpg',
|
||
),
|
||
];
|
||
return Center(
|
||
child: SingleChildScrollView(
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: data.map((data) {
|
||
return _Card.fromData(
|
||
data,
|
||
onLike: (String title, bool isLiked) =>
|
||
_showSnackBar(context, title, isLiked),
|
||
onTap: () => _navToDetails(context, data),
|
||
);
|
||
}).toList(),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
void _navToDetails(BuildContext context, CardData data) {
|
||
Navigator.push(
|
||
context,
|
||
CupertinoPageRoute(builder: (context) => DetailsPage(data)),
|
||
);
|
||
}
|
||
|
||
void _showSnackBar(BuildContext context, String title, bool isLiked) {
|
||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||
content: Text(
|
||
'You ${isLiked ? 'like!' : 'disliked :('} $title ',
|
||
style: Theme
|
||
.of(context)
|
||
.textTheme
|
||
.bodyLarge,
|
||
),
|
||
backgroundColor: Colors.deepPurple.shade600,
|
||
duration: const Duration(seconds: 1),
|
||
));
|
||
});
|
||
}} |