PIbd31_Razubaev.S.M._PMU/lib/presentation/home_page/home_page.dart
2024-10-04 14:11:06 +04:00

95 lines
3.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pmu_labs/presentation/details_page/details_page.dart';
import '../../domain/models/carddata.dart';
part 'card.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
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),
),
body: const Body(),
);
}
}
class Body extends StatelessWidget {
const Body({super.key});
void _showSnackbar(BuildContext context, String title, bool isLiked) {
WidgetsBinding.instance.addPostFrameCallback((_) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Лайк на $title ${isLiked ? 'поставлен':'убран'}',
style: Theme.of(context).textTheme.bodyLarge,
),
backgroundColor: Colors.orangeAccent,
duration: const Duration(seconds: 1),
));
});
}
void _navToDetails(BuildContext context, CardData data)
{
Navigator.push(context, CupertinoPageRoute(builder: (context) => DetailsPage(data)));
}
@override
Widget build(BuildContext context) {
final data = [
CardData('Зов Ктулху',
descriptionText:
'Лучше бы не находить разгадку, объединяющую сошедших с ума творцов...',
imageUrl:
'https://lovecraft.country/images/bibliography/call-of-cthulhu-mini.webp'),
CardData('Хребты безумия',
descriptionText:
'«Хребты безумия» написаны в документальной манере повествования, постепенно привыкая к которой, становишься свидетелем особой реальности описываемых событий.',
imageUrl:
'https://lovecraft.country/images/bibliography/At-the-Mountains-of-Madness-mini.webp'),
CardData('Тень над Инсмутом',
descriptionText:
'Инсмут, маленький рыбацкий городок неподалеку от Аркхэма, уже много лет имеет дурную славу. В округе ходят жуткие истории о его угрюмых и уродливых жителях, от которых лучше держаться подальше.',
imageUrl:
'https://lovecraft.country/images/bibliography/The-Shadow-over-Innsmouth.webp')
];
return Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e,onLike: (title, isLiked) => _showSnackbar(context, title, isLiked), onTap: () => _navToDetails(context, e))).toList(),
),
),
);
}
}