PIbd-31_Belianin_N._N._PMD/lib/main.dart

122 lines
3.4 KiB
Dart
Raw Normal View History

2024-09-16 15:06:59 +04:00
import 'package:flutter/material.dart';
void main() {
2024-09-17 03:13:55 +04:00
runApp(const MyApp());
2024-09-16 15:06:59 +04:00
}
class MyApp extends StatelessWidget {
2024-09-17 03:13:55 +04:00
const MyApp({super.key});
2024-09-16 15:06:59 +04:00
@override
Widget build(BuildContext context) {
return MaterialApp(
2024-09-17 03:13:55 +04:00
title: 'Flutter Demo',
2024-09-16 15:15:08 +04:00
debugShowCheckedModeBanner: false,
2024-09-16 15:06:59 +04:00
theme: ThemeData(
2024-09-17 03:13:55 +04:00
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
useMaterial3: true,
2024-09-16 15:06:59 +04:00
),
2024-09-17 03:13:55 +04:00
home: const MyHomePage(title: 'Laboratory 3: Cards'),
2024-09-16 15:06:59 +04:00
);
}
2024-09-17 03:13: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),
),
body: Padding(
padding: const EdgeInsets.all(30),
child: ListView.separated(
itemBuilder: (context, index) =>
Card(name: "House $index", location: "Moscow", price: 1100.0),
separatorBuilder: (context, index) => const SizedBox(height: 20),
itemCount: 5,
)));
}
}
class Card extends StatefulWidget {
const Card({super.key, required this.name, required this.price, required this.location});
final String name;
final double price;
final String location;
@override
State<StatefulWidget> createState() => _CardState();
}
class _CardState extends State<Card> {
bool _isFavorite = false;
void toggleIsFavorite() {
setState(() {
_isFavorite = !_isFavorite;
});
}
@override
Widget build(BuildContext context) {
return Stack(
children: [
Container(
padding:
const EdgeInsets.only(top: 50, bottom: 15, left: 40, right: 40),
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://cdn0.youla.io/files/images/780_780/63/29/6329d9f543eedb62b7695786-1.jpg"),
),
Padding(
padding: EdgeInsets.only(top: 50),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.name, style: TextStyle(fontSize: 17)),
Text("Местоположение: ${widget.location}", style: TextStyle(fontSize: 15)),
Text("${widget.price} Рублей/сутки",
style: TextStyle(
fontSize: 17, color: Colors.orange))
],
),
)
],
),
),
Positioned(
right: 300,
top: 10,
child: IconButton(
icon: Icon(_isFavorite ? Icons.favorite : Icons.favorite_border),
color: Colors.red,
onPressed: toggleIsFavorite,
))
],
);
}
}