2024-11-26 16:43:55 +04:00
|
|
|
|
import 'package:flutter/cupertino.dart';
|
2024-11-26 15:44:55 +04:00
|
|
|
|
import 'package:flutter/material.dart';
|
2024-11-26 16:43:55 +04:00
|
|
|
|
import 'package:pmu/domain/card.dart';
|
|
|
|
|
import 'package:pmu/presentation/detail_pages/card_detail_page.dart';
|
|
|
|
|
import 'package:pmu/presentation/home_page/card.dart';
|
2024-11-26 15:44:55 +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> {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
|
|
|
title: Text(widget.title),
|
|
|
|
|
),
|
2024-11-26 16:43:55 +04:00
|
|
|
|
body: const Body(),
|
2024-11-26 15:44:55 +04:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-26 16:43:55 +04:00
|
|
|
|
class Body extends StatelessWidget {
|
|
|
|
|
const Body({super.key});
|
|
|
|
|
|
|
|
|
|
void _navToDetails(BuildContext context, CardPostData data) {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
CupertinoPageRoute(builder: (context) => DetailPage(data)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _showSnackBar(BuildContext context, String title, bool isLiked) {
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
|
|
|
|
content: Text(
|
|
|
|
|
'${isLiked ? 'Вы поставили лайк: ' : 'Вы убрали лайк: '} $title',
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
color: Colors.black45,
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
fontWeight: FontWeight.bold
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
backgroundColor: isLiked ? Colors.green : Colors.red,
|
|
|
|
|
duration: const Duration(seconds: 2),
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-11-26 15:44:55 +04:00
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final data = [
|
2024-11-26 16:43:55 +04:00
|
|
|
|
const CardPostData(
|
2024-11-26 15:44:55 +04:00
|
|
|
|
"Евгения",
|
|
|
|
|
"Люблю программирование и кататься на скейте",
|
|
|
|
|
"https://avatar.iran.liara.run/public/girl",
|
|
|
|
|
true),
|
2024-11-26 16:43:55 +04:00
|
|
|
|
const CardPostData("Алекс", "Junior Flutter Engineer",
|
2024-11-26 15:44:55 +04:00
|
|
|
|
"https://avatar.iran.liara.run/public/36", false),
|
2024-11-26 16:43:55 +04:00
|
|
|
|
const CardPostData(
|
2024-11-26 15:44:55 +04:00
|
|
|
|
"Станислав",
|
|
|
|
|
"Нет ничего приятнее прогулки на природе!",
|
|
|
|
|
"https://avatar.iran.liara.run/public/boy",
|
|
|
|
|
true),
|
2024-11-26 16:43:55 +04:00
|
|
|
|
const CardPostData("Вероника", "В свободное время хожу на уроки вокала",
|
2024-11-26 15:44:55 +04:00
|
|
|
|
"https://avatar.iran.liara.run/public/93", false),
|
|
|
|
|
];
|
|
|
|
|
return Center(
|
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2024-11-26 16:43:55 +04:00
|
|
|
|
children: data.map((data) {
|
|
|
|
|
return CardPost.fromData(data,
|
|
|
|
|
onLike: (String title, bool isLiked) =>
|
|
|
|
|
_showSnackBar(context, title, isLiked),
|
|
|
|
|
onTap: () => _navToDetails(context, data));
|
|
|
|
|
}).toList(),
|
2024-11-26 15:44:55 +04:00
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
}
|