95 lines
3.1 KiB
Dart
95 lines
3.1 KiB
Dart
import 'package:flutter/cupertino.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:pmu_new/presentation/home_page/MyCard.dart';
|
||
import 'package:pmu_new/models/CardData.dart';
|
||
|
||
import '../details_page/details_page.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> {
|
||
|
||
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||
title: Text(widget.title),
|
||
),
|
||
body: const CardWidget());
|
||
}
|
||
}
|
||
|
||
|
||
class CardWidget extends StatelessWidget {
|
||
const CardWidget({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.greenAccent,
|
||
duration: const Duration(seconds: 1),
|
||
));
|
||
});
|
||
}
|
||
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final data = [
|
||
CardData(
|
||
'Фрукты',
|
||
descriptionText:
|
||
'Какие же они полезные и сладкие!!!! Generate Lorem Ipsum placeholder text for use in your graphic, print and web layouts, and discover plugins for your favorite writing, design and blogging tools',
|
||
imageUrl:
|
||
'https://media.gettyimages.com/id/182810893/photo/fruit-mix.jpg?s=612x612&w=0&k=20&c=v9jopDXbS5LCXY1d8uSwEldLJVVkOpYtYtyHD8azWDU=',
|
||
onlike: (name, state) => _showSnackBar(context, name, state),
|
||
),
|
||
CardData(
|
||
'Киви',
|
||
descriptionText:
|
||
'сладкий и спелый, можно купить по акции прямо сейчас звоните не пожалеете',
|
||
Backgroundcolor: Color.fromARGB(10, 210, 30, 40),
|
||
imageUrl:
|
||
'https://www.diyphotography.net/files/images/3/pictures-of-sliced-fruits-09b.jpg',
|
||
onlike: (name, state) => _showSnackBar(context, name, state),
|
||
),
|
||
CardData(
|
||
'Банан',
|
||
descriptionText: 'Ого, че с ним произошло',
|
||
Backgroundcolor: Color.fromARGB(30, 30, 210, 15),
|
||
imageUrl:
|
||
'https://www.diyphotography.net/files/images/3/pictures-of-sliced-fruits-01.jpg',
|
||
onlike: (name, state) => _showSnackBar(context, name, state),
|
||
),
|
||
];
|
||
|
||
return Center(
|
||
child: SingleChildScrollView(
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: data.map((e) => MyCard(cardData: e, onTap: () {
|
||
Navigator.push(
|
||
context,
|
||
CupertinoPageRoute(
|
||
builder: (context) => DetailsPage(e)),
|
||
);
|
||
})).toList(),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
} |