295 lines
8.0 KiB
Dart
295 lines
8.0 KiB
Dart
import 'package:flutter/material.dart';
|
||
|
||
enum FoodType { fruit, vegetable, meat, fish, sweet }
|
||
|
||
class FoodStuff {
|
||
final FoodType _type;
|
||
final String Name;
|
||
|
||
FoodStuff(this._type, this.Name);
|
||
|
||
FoodType getFoodType() => _type;
|
||
|
||
bool isMeat() => _type == FoodType.meat ? true : false;
|
||
}
|
||
|
||
extension IsHealthy on FoodStuff {
|
||
bool isHealthy() {
|
||
switch (_type) {
|
||
case FoodType.meat || FoodType.vegetable:
|
||
return true;
|
||
default:
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
|
||
Future<String> connectToDb() async {
|
||
await Future.delayed(Duration(seconds: 4));
|
||
List<FoodStuff> food = [];
|
||
food.add(new FoodStuff(FoodType.meat, "meat"));
|
||
food.add(new FoodStuff(FoodType.vegetable, "cabbage"));
|
||
food.add(new FoodStuff(FoodType.fruit, "apple"));
|
||
//List<String> names = food.forEach((FoodStuff e )=> e.Name);
|
||
List<String> types = [];
|
||
List<String> names = [];
|
||
for (final element in food) {
|
||
types.add(element
|
||
.getFoodType()
|
||
.name);
|
||
names.add(element.Name);
|
||
}
|
||
var values = [];
|
||
for (var i = 0; i < food.length; i++) {
|
||
values.add('${names[i]} ${types[i]}');
|
||
}
|
||
return values.join(',');
|
||
}
|
||
|
||
void main() {
|
||
runApp(const MyApp());
|
||
}
|
||
|
||
class MyApp extends StatelessWidget {
|
||
const MyApp({super.key});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return MaterialApp(
|
||
title: 'Flutter Demo',
|
||
theme: ThemeData(
|
||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||
useMaterial3: true,
|
||
),
|
||
home: const MyHomePage(title: 'Старостин Иван Константинович'),
|
||
);
|
||
}
|
||
}
|
||
|
||
class MyHomePage extends StatefulWidget {
|
||
const MyHomePage({super.key, required this.title});
|
||
|
||
final String title;
|
||
|
||
@override
|
||
State<MyHomePage> createState() => _MyHomePageState();
|
||
}
|
||
|
||
class _MyHomePageState extends State<MyHomePage> {
|
||
int _counter = 0;
|
||
|
||
void _incrementCounter() {
|
||
setState(() {
|
||
_counter++;
|
||
});
|
||
}
|
||
|
||
String text2 = '';
|
||
String text1 = 'Hello there!!';
|
||
|
||
/*void getVal() async {
|
||
connectToDb().then((data) async {
|
||
setState(() {
|
||
text2 = data;
|
||
});
|
||
});
|
||
setState(() {
|
||
text1 = 'Loading data';
|
||
});
|
||
}*/
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
backgroundColor: Theme
|
||
.of(context)
|
||
.colorScheme
|
||
.inversePrimary,
|
||
title: Text(widget.title),
|
||
),
|
||
body: const CardWidget());
|
||
}
|
||
|
||
/*@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||
title: Text(widget.title),
|
||
),
|
||
body: Center(
|
||
child: Column(
|
||
//width: 100,
|
||
//decoration: BoxDecoration(border: Border.all()),
|
||
children: <Widget>[
|
||
Text(overflow: TextOverflow.ellipsis, '$text1'),
|
||
Text(overflow: TextOverflow.ellipsis, '$text2')
|
||
])
|
||
/*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,
|
||
),
|
||
],
|
||
),*/
|
||
),
|
||
floatingActionButton: FloatingActionButton(
|
||
onPressed: getVal,
|
||
tooltip: 'Increment',
|
||
child: const Icon(Icons.add),
|
||
),
|
||
);
|
||
}*/
|
||
}
|
||
|
||
class _CardData {
|
||
final String text;
|
||
final String descriptionText;
|
||
final Color Backgroundcolor;
|
||
final String? imageUrl;
|
||
|
||
_CardData(this.text, {
|
||
required this.descriptionText,
|
||
this.Backgroundcolor = const Color.fromARGB(70, 173, 216, 230),
|
||
this.imageUrl,
|
||
});
|
||
}
|
||
|
||
class CardWidget extends StatelessWidget {
|
||
const CardWidget({super.key});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final data = [
|
||
_CardData(
|
||
'Фрукты',
|
||
descriptionText: 'Какие же они полезные и сладкие!!!! Generate Lorem Ipsum placeholder text for use in your graphic, print and web layouts, and discover plugins for your favorite writing, design and blogging tools',
|
||
imageUrl:
|
||
'https://media.gettyimages.com/id/182810893/photo/fruit-mix.jpg?s=612x612&w=0&k=20&c=v9jopDXbS5LCXY1d8uSwEldLJVVkOpYtYtyHD8azWDU=',
|
||
),
|
||
_CardData(
|
||
'Киви',
|
||
descriptionText: 'сладкий и спелый, можно купить по акции прямо сейчас звоните не пожалеете',
|
||
Backgroundcolor: Color.fromARGB(10, 210, 30, 40),
|
||
imageUrl:
|
||
'https://www.diyphotography.net/files/images/3/pictures-of-sliced-fruits-09b.jpg',
|
||
),
|
||
_CardData(
|
||
'Банан',
|
||
descriptionText: 'Ого, че с ним произошло',
|
||
Backgroundcolor: Color.fromARGB(30, 30, 210, 15),
|
||
imageUrl:
|
||
'https://www.diyphotography.net/files/images/3/pictures-of-sliced-fruits-01.jpg',
|
||
),
|
||
];
|
||
|
||
return Center(
|
||
child: SingleChildScrollView(
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: data.map((e) => _Card(cardData: e)).toList(),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
class _Card extends StatelessWidget {
|
||
final _CardData cardData;
|
||
|
||
const _Card({
|
||
required this.cardData,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Container(
|
||
margin: const EdgeInsets.all(16),
|
||
padding: const EdgeInsets.all(16),
|
||
decoration: BoxDecoration(
|
||
color: this.cardData.Backgroundcolor,
|
||
borderRadius: BorderRadius.circular(9),
|
||
border: Border.all(color: Colors.grey),
|
||
boxShadow: [
|
||
BoxShadow(
|
||
color: Colors.grey.withOpacity(.5),
|
||
spreadRadius: 4,
|
||
offset: const Offset(0, 5),
|
||
blurRadius: 8,
|
||
),
|
||
],
|
||
),
|
||
child: Column(
|
||
//crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Column(
|
||
children: [
|
||
ClipRRect(
|
||
borderRadius: BorderRadius.circular(10),
|
||
child: SizedBox(
|
||
height: 240,
|
||
width: 300,
|
||
child: Image.network(
|
||
this.cardData.imageUrl ?? '',
|
||
fit: BoxFit.cover,
|
||
errorBuilder: (_, __, ___) => const Placeholder(),
|
||
),
|
||
),
|
||
),
|
||
|
||
],
|
||
),
|
||
]),
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: Padding(
|
||
padding: const EdgeInsets.only(left: 16.0, top: 12.0),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
Text(
|
||
this.cardData.text,
|
||
style:
|
||
TextStyle(decoration: TextDecoration.underline, fontSize: 30)
|
||
),
|
||
]),
|
||
)
|
||
),
|
||
],
|
||
),
|
||
Row(children: [
|
||
Expanded(
|
||
child: Padding(
|
||
padding: const EdgeInsets.only(left: 16.0),
|
||
child: Text(
|
||
this.cardData.descriptionText,
|
||
style: Theme
|
||
.of(context)
|
||
.textTheme
|
||
.bodyLarge,
|
||
)
|
||
),
|
||
),
|
||
/*Expanded(
|
||
child: Padding(
|
||
padding: const EdgeInsets.only(left: 16.0),
|
||
child: Column(),
|
||
))*/
|
||
])
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|