Готово (еще не сдано)
This commit is contained in:
parent
79abdf88b7
commit
f93387655a
BIN
cart_example.png
Normal file
BIN
cart_example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
@ -16,7 +16,7 @@ class MyApp extends StatelessWidget {
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Дьяконов Руслан ПИбд-33'),
|
||||
home: const MyHomePage(title: 'Lab 3: Cards'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -31,39 +31,82 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.all(30),
|
||||
child: ListView.separated(
|
||||
itemBuilder: (context, index) =>
|
||||
Card(name: "test $index", price: 11.0),
|
||||
separatorBuilder: (context, index) => SizedBox(height: 20),
|
||||
itemCount: 2,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
void _incrementCounter() {
|
||||
class Card extends StatefulWidget {
|
||||
const Card({super.key, required this.name, required this.price});
|
||||
|
||||
final String name;
|
||||
final double price;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CardState();
|
||||
}
|
||||
|
||||
class _CardState extends State<Card> {
|
||||
bool _isFavourite = true;
|
||||
|
||||
void toggleIsFavourite() {
|
||||
setState(() {
|
||||
_counter++;
|
||||
_isFavourite = !_isFavourite;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'You have pushed the button this many times:',
|
||||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
],
|
||||
return Stack(
|
||||
children: [
|
||||
Container(
|
||||
padding: 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://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)),
|
||||
Text(widget.price.toString() + " Руб",
|
||||
style: TextStyle(fontSize: 17, color: Colors.orange))
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
));
|
||||
Positioned(
|
||||
right: 10,
|
||||
top: 10,
|
||||
child: IconButton(
|
||||
icon: Icon(_isFavourite ? Icons.favorite : Icons.favorite_border),
|
||||
color: Colors.red,
|
||||
onPressed: toggleIsFavourite,
|
||||
))
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user