PMU_Petrushin_PIbd-32/lib/main.dart
2024-09-24 00:19:30 +04:00

169 lines
4.8 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 'dart:math';
import 'package:flutter/material.dart';
import 'year.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Petrushin demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red),
useMaterial3: true,
),
home: const MyHomePage(title: 'Petrushin Egor Alexandrovich'),
);
}
}
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
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: const GrandWidget(),
);
}
}
class GrandWidget extends StatelessWidget {
const GrandWidget({super.key});
@override
Widget build(BuildContext context) {
final data = [
_CardData(text: "Батон",
info: "Белый хлеб, испечённый в виде продолговатой булки",
urlImage: "https://hlebzavod3.ru/images/virtuemart/product/011_IMG_9657.jpg"),
_CardData(text: "Багет",
info: "Длинный тонкий вид хлеба французского происхождения",
urlImage: "https://main-cdn.sbermegamarket.ru/big1/hlr-system/13/14/29/23/31/01/100027310078b0.jpg"),
_CardData(text: "Круассан",
info: "Небольшое мучное кондитерское изделие, булочка в форме полумесяца из слоёного теста",
urlImage: "https://shokoladd.ru/wp-content/uploads/2019/02/Croissant_Chocolate_Plate_Two_547531_2048x1152.jpg"),
_CardData(text: "Чиаба́тта",
info: "Итальянский пшеничный хлеб, выпекаемый с использованием закваски, дрожжей и оливкового масла",
urlImage: "https://avatars.mds.yandex.net/i?id=a9163f90a989a596b26b30ad39beaf47_l-10629685-images-thumbs&n=13")
];
return Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e)).toList(),
)
)
);
}
}
class _CardData {
final String text;
final String info;
final String urlImage;
_CardData({required this.text, required this.info, required this.urlImage});
}
class _Card extends StatefulWidget {
final String text;
final String info;
final String urlImage;
const _Card({super.key, required this.text, required this.info, required this.urlImage});
factory _Card.fromData(_CardData data) => _Card(
text: data.text,
info: data.info,
urlImage: data.urlImage);
@override
State<_Card> createState() => _CardState();
}
class _CardState extends State<_Card> {
bool isLiked = false;
@override
Widget build(BuildContext context) {
return Card(
elevation: 4.0,
margin: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.network(
widget.urlImage,
fit: BoxFit.cover,
height: 150.0,
width: double.infinity,
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.text,
style: const TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 5.0),
Text(
widget.info,
style: const TextStyle(
fontSize: 14.0,
color: Colors.grey,
),
),
Positioned(
top: 8.0,
right: 8.0,
child: GestureDetector(
onTap: () {
setState(() {
isLiked = !isLiked;
});
},
child: Icon(
Icons.favorite,
color: isLiked ? Colors.red : Colors.blueGrey,
size: 30.0,
),
),
),
],
),
),
],
),
);
}
}