2024-10-04 11:07:54 +04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:test_app/domain/card.dart';
|
|
|
|
import 'package:test_app/view/details_page/details_page.dart';
|
2024-10-04 12:03:16 +04:00
|
|
|
import 'package:test_app/view/home_page/home_card.dart';
|
2024-10-04 11:07:54 +04:00
|
|
|
|
|
|
|
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.orangeAccent;
|
|
|
|
|
|
|
|
@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(
|
|
|
|
'Hello',
|
|
|
|
descriptionText: 'Hello text',
|
|
|
|
imageUrl:
|
|
|
|
'https://unsplash.com/photos/6GMq7AGxNbE/download?ixid=M3wxMjA3fDB8MXxzZWFyY2h8Mnx8cmFjY29vbnxlbnwwfHx8fDE3Mjc5MTExNTl8MA&force=true&w=640',
|
|
|
|
),
|
|
|
|
CardData(
|
|
|
|
'Hello 2',
|
|
|
|
descriptionText: 'Hello 2 text',
|
|
|
|
icon: Icons.add,
|
|
|
|
imageUrl:
|
|
|
|
'https://unsplash.com/photos/UopR2NUBYek/download?ixid=M3wxMjA3fDB8MXxzZWFyY2h8MTF8fHJhY2Nvb258ZW58MHx8fHwxNzI3OTExMTU5fDA&force=true&w=640',
|
|
|
|
),
|
|
|
|
CardData(
|
|
|
|
'Hello 3',
|
|
|
|
descriptionText: 'Hello 3 text',
|
|
|
|
icon: Icons.add,
|
|
|
|
imageUrl:
|
|
|
|
'https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/Raccoon_on_Log.jpg/640px-Raccoon_on_Log.jpg',
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
return Center(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
padding: const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 8),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: data
|
2024-10-04 11:59:55 +04:00
|
|
|
.map((data) => HomeCard.fromData(
|
2024-10-04 11:07:54 +04:00
|
|
|
data,
|
|
|
|
onLike: (String title, bool isLiked) =>
|
|
|
|
_showSnackBar(context, title, isLiked),
|
|
|
|
onTap: () => _navigateToDetails(context, data),
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _showSnackBar(BuildContext context, String title, bool isLiked) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
|
|
content: Text(
|
|
|
|
'$title is ${isLiked ? 'liked' : 'disliked'}!',
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
|
|
|
backgroundColor: Colors.orangeAccent,
|
|
|
|
duration: const Duration(seconds: 1),
|
|
|
|
));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _navigateToDetails(BuildContext context, CardData data) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) => DetailsPage(data)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|