This commit is contained in:
gg12 darfren 2024-09-22 14:04:15 +04:00
parent c0b675355f
commit 45ac3158ac

View File

@ -4,18 +4,20 @@ void main() {
runApp(const MyApp());
}
const Color mainColor = Colors.deepOrangeAccent;
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
colorScheme: ColorScheme.fromSeed(seedColor: mainColor),
useMaterial3: true,
),
home: const MyHomePage(title: 'Салин Олег Алексеевич'),
home: const MyHomePage(title: 'Кафе Ящик'),
);
}
}
@ -23,8 +25,6 @@ class MyApp extends StatelessWidget {
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
@ -32,39 +32,173 @@ class MyHomePage extends StatefulWidget {
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Icon(Icons.abc_rounded),
backgroundColor: mainColor,
title: Text(widget.title),
),
body: const MyWidget(),
);
}
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
final data = [
_CardData(
'Рулет из баклажанов',
descriprionText: 'рулет из баклажанов, чеснока и сыра',
weight: 300,
imageUrl:
'https://kolyda.ru/d/baklazhanchiki_farshirovannye_orehami.jpg',
),
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,
),
],
_CardData(
'Лагман',
descriprionText: 'Суп из говядины и овощей',
isTop: true,
weight: 250,
imageUrl: 'https://avatars.mds.yandex.net/get-altay/5257938/2'
'a0000018aa4c0859fe7c036bfa6312e4732/XXL_height',
),
_CardData(
'Манты',
descriprionText: 'Это пельмени. Большие.',
weight: 250,
imageUrl:
'https://chaihana-zamzam.ru/wp-content/uploads/2022/10/Mantu.jpg',
),
_CardData(
'Свиной шашлык',
descriprionText: 'Осторожно ! Свинина !',
isTop: true,
weight: 300,
imageUrl:
'https://avatars.mds.yandex.net/get-altay/9686455/2a0000018a4892e137bca9e41256a79d2c7a/orig',
icon: Icons.warning,
),
_CardData(
'Куриный шашлык',
descriprionText: 'Халяль',
weight: 300,
imageUrl:
'https://i.pinimg.com/originals/2f/b5/7e/2fb57efeac571775d423ad995e5c1e1d.jpg',
),
];
return Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e)).toList(),
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), );
);
}
}
class _CardData {
final String text;
final String descriprionText;
final int weight;
final IconData icon;
final String? imageUrl;
final bool isTop;
_CardData(
this.text, {
required this.descriprionText,
required this.weight,
this.icon = Icons.hail,
this.imageUrl,
this.isTop = false,
});
}
class _Card extends StatelessWidget {
final String text;
final IconData icon;
final String descriptionText;
final String? imageUrl;
final Color color;
const _Card(
this.text, {
this.icon = Icons.ac_unit_outlined,
required this.descriptionText,
this.imageUrl,
this.color = Colors.white70,
});
factory _Card.fromData(_CardData data) => _Card(
data.text,
descriptionText: data.descriprionText,
icon: data.icon,
imageUrl: data.imageUrl,
color: (data.isTop ? mainColor : Colors.white70),
);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 8, bottom: 8),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.black,
width: 3,
),
boxShadow: [
BoxShadow(color: Colors.grey, spreadRadius: 4, blurRadius: 8)
]),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
height: 140,
width: 120,
child: Image.network(
fit: BoxFit.cover,
imageUrl ?? '',
errorBuilder: (_, __, ___) => const Placeholder(),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
text,
style: Theme.of(context).textTheme.headlineLarge,
),
Text(
descriptionText,
style: Theme.of(context).textTheme.bodyLarge,
),
],
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(icon),
),
],
),
);
}
}