126 lines
3.5 KiB
Dart
126 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
void main() {
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Demo',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
|
|
useMaterial3: true,
|
|
),
|
|
home: const MyHomePage(title: 'Laboratory 3: Cards'),
|
|
);
|
|
}
|
|
}
|
|
|
|
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.orange, width: 2),
|
|
color: Colors.blue,
|
|
borderRadius: BorderRadius.circular(20)),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Center(
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(20.0),
|
|
// Радиус скругления
|
|
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,
|
|
))
|
|
],
|
|
);
|
|
}
|
|
}
|