2024-09-06 20:59:47 +04:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
runApp(const MyApp());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
2024-09-06 21:09:15 +04:00
|
|
|
|
@override
|
2024-09-06 20:59:47 +04:00
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
|
title: 'Flutter Demo',
|
2024-09-10 20:22:56 +04:00
|
|
|
|
debugShowCheckedModeBanner: false,
|
2024-09-06 20:59:47 +04:00
|
|
|
|
theme: ThemeData(
|
2024-09-10 20:22:56 +04:00
|
|
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
2024-09-06 20:59:47 +04:00
|
|
|
|
useMaterial3: true,
|
|
|
|
|
),
|
2024-09-10 23:06:35 +04:00
|
|
|
|
home: const MyHomePage(title: 'Lab 3: Cards'),
|
2024-09-06 20:59:47 +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> {
|
2024-09-10 23:06:35 +04:00
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
|
|
|
title: Text(widget.title),
|
|
|
|
|
),
|
|
|
|
|
body: Padding(
|
2024-09-11 15:36:09 +04:00
|
|
|
|
padding: const EdgeInsets.all(30),
|
2024-09-10 23:06:35 +04:00
|
|
|
|
child: ListView.separated(
|
|
|
|
|
itemBuilder: (context, index) =>
|
|
|
|
|
Card(name: "test $index", price: 11.0),
|
2024-09-11 15:36:09 +04:00
|
|
|
|
separatorBuilder: (context, index) => const SizedBox(height: 20),
|
2024-09-10 23:06:35 +04:00
|
|
|
|
itemCount: 2,
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Card extends StatefulWidget {
|
|
|
|
|
const Card({super.key, required this.name, required this.price});
|
|
|
|
|
|
|
|
|
|
final String name;
|
|
|
|
|
final double price;
|
2024-09-06 20:59:47 +04:00
|
|
|
|
|
2024-09-10 23:06:35 +04:00
|
|
|
|
@override
|
|
|
|
|
State<StatefulWidget> createState() => _CardState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _CardState extends State<Card> {
|
|
|
|
|
bool _isFavourite = true;
|
|
|
|
|
|
|
|
|
|
void toggleIsFavourite() {
|
2024-09-06 20:59:47 +04:00
|
|
|
|
setState(() {
|
2024-09-10 23:06:35 +04:00
|
|
|
|
_isFavourite = !_isFavourite;
|
2024-09-06 20:59:47 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-09-10 23:06:35 +04:00
|
|
|
|
return Stack(
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
2024-09-11 15:36:09 +04:00
|
|
|
|
padding: const EdgeInsets.only(top: 50, bottom: 15, left: 40, right: 40),
|
2024-09-10 23:06:35 +04:00
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
border: Border.all(color: Colors.black12, width: 2),
|
|
|
|
|
borderRadius: BorderRadius.circular(20)),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Center(
|
|
|
|
|
child: Image.network(
|
|
|
|
|
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTtAT11wKgHrJBUYzIBFogucXg0a9fE0fQXDQ&s"),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: EdgeInsets.only(top: 50),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(widget.name, style: TextStyle(fontSize: 17)),
|
2024-09-11 15:36:09 +04:00
|
|
|
|
Text("${widget.price} Руб",
|
2024-09-10 23:06:35 +04:00
|
|
|
|
style: TextStyle(fontSize: 17, color: Colors.orange))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
2024-09-06 20:59:47 +04:00
|
|
|
|
),
|
2024-09-10 23:06:35 +04:00
|
|
|
|
Positioned(
|
|
|
|
|
right: 10,
|
|
|
|
|
top: 10,
|
|
|
|
|
child: IconButton(
|
|
|
|
|
icon: Icon(_isFavourite ? Icons.favorite : Icons.favorite_border),
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
onPressed: toggleIsFavourite,
|
2024-09-11 15:36:09 +04:00
|
|
|
|
)
|
|
|
|
|
)
|
2024-09-10 23:06:35 +04:00
|
|
|
|
],
|
|
|
|
|
);
|
2024-09-06 20:59:47 +04:00
|
|
|
|
}
|
2024-09-11 15:36:09 +04:00
|
|
|
|
}
|