Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
f618e7e0e5 | |||
b56181b1c4 | |||
4260c7e1a5 | |||
ffcabca487 | |||
bcac3a5e03 | |||
b3f16e9c47 |
BIN
images/pizza.png
Normal file
BIN
images/pizza.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 669 KiB |
145
lib/main.dart
145
lib/main.dart
@ -11,11 +11,12 @@ class MyApp extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.orangeAccent),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Иванов Вячеслав Николаевич'),
|
||||
home: const MyHomePage(title: 'Cards'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -30,14 +31,6 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
_counter++;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -45,24 +38,132 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
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:',
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: ListView.separated(
|
||||
itemBuilder: (context, index) => GestureDetector(
|
||||
child: CardWidget(name: "Pizza $index", price: 150.0),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => DetailPage(
|
||||
name: "Pizza $index",
|
||||
price: 150.0,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
separatorBuilder: (context, index) => const SizedBox(height: 20),
|
||||
itemCount: 10,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
class CardWidget extends StatefulWidget {
|
||||
const CardWidget({super.key, required this.name, required this.price});
|
||||
|
||||
final String name;
|
||||
final double price;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CardWidgetState();
|
||||
}
|
||||
|
||||
class _CardWidgetState extends State<CardWidget> {
|
||||
bool _isFavourite = false;
|
||||
|
||||
void toggleIsFavourite() {
|
||||
setState(() {
|
||||
_isFavourite = !_isFavourite;
|
||||
final snackBar = SnackBar(
|
||||
duration: const Duration(seconds: 1),
|
||||
content: Text(
|
||||
_isFavourite ? 'Added to favorites' : 'Removed from favorites'),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.deepOrangeAccent, width: 2),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Image
|
||||
Expanded(
|
||||
child: Image.asset(
|
||||
"images/pizza.png",
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
// Content
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(widget.name, style: const TextStyle(fontSize: 18)),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
"${widget.price} Руб",
|
||||
style: const TextStyle(fontSize: 17, color: Colors.orange),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
// Like Button
|
||||
IconButton(
|
||||
icon: Icon(_isFavourite ? Icons.favorite : Icons.favorite_border),
|
||||
color: Colors.red,
|
||||
onPressed: toggleIsFavourite,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DetailPage extends StatelessWidget {
|
||||
final String name;
|
||||
final double price;
|
||||
|
||||
const DetailPage({super.key, required this.name, required this.price});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(name),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Center(
|
||||
child: Image.asset(
|
||||
"images/pizza.png",
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(name,
|
||||
style:
|
||||
const TextStyle(fontSize: 24, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 10),
|
||||
Text("$price Руб",
|
||||
style: const TextStyle(fontSize: 20, color: Colors.orange)),
|
||||
// Add more details here as needed
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -75,6 +75,14 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
intl:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: intl
|
||||
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.18.1"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -30,6 +30,7 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
intl: ^0.18.0
|
||||
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
@ -59,10 +60,9 @@ flutter:
|
||||
uses-material-design: true
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
assets:
|
||||
- images/pizza.png
|
||||
# - images/a_dot_ham.jpeg
|
||||
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/to/resolution-aware-images
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user