70 lines
1.6 KiB
Dart
70 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'presentation/home_page/home_page.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: 'Старостин Иван Константинович'),
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|