changes
This commit is contained in:
parent
b063c78d11
commit
0520e5722b
234
lib/main.dart
234
lib/main.dart
@ -1,5 +1,51 @@
|
||||
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());
|
||||
}
|
||||
@ -23,8 +69,6 @@ class MyApp extends StatelessWidget {
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
@ -40,7 +84,34 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
});
|
||||
}
|
||||
|
||||
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(
|
||||
@ -49,6 +120,13 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
),
|
||||
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(
|
||||
@ -59,12 +137,158 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),*/
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
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(),
|
||||
))*/
|
||||
])
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
#assets:
|
||||
# - assets/
|
||||
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
|
Loading…
Reference in New Issue
Block a user