another in between commit, getting messy :o
This commit is contained in:
parent
e7cca581c5
commit
1382a4a843
16 changed files with 181 additions and 89 deletions
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -3,7 +3,7 @@
|
|||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<type id="android" />
|
||||
</component>
|
||||
<component name="ProjectRootManager">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="false" project-jdk-name="Android API 30 Platform" project-jdk-type="Android SDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
3
android/.idea/.gitignore
generated
vendored
Normal file
3
android/.idea/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
6
android/.idea/compiler.xml
generated
Normal file
6
android/.idea/compiler.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
22
android/.idea/gradle.xml
generated
Normal file
22
android/.idea/gradle.xml
generated
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="C:/ProgramData/chocolatey/lib/gradle/tools/gradle-7.1" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$/../../../lib/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.0+3/android" />
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
9
android/.idea/misc.xml
generated
Normal file
9
android/.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
8
android/.idea/modules.xml
generated
Normal file
8
android/.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/modules/android.iml" filepath="$PROJECT_DIR$/.idea/modules/android.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
10
android/.idea/runConfigurations.xml
generated
Normal file
10
android/.idea/runConfigurations.xml
generated
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -6,6 +6,7 @@ import 'package:pizzaplanner/entities/PizzaRecipe/Ingredient.dart';
|
|||
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeSubStep.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
@entity
|
||||
|
@ -61,7 +62,7 @@ class PizzaRecipe {
|
|||
);
|
||||
}
|
||||
|
||||
static Future<PizzaRecipe> fromYaml(yamlPath) async{
|
||||
static Future<Tuple4<PizzaRecipe, List<Ingredient>, List<RecipeStep>, List<RecipeSubStep>>> fromYaml(yamlPath) async{
|
||||
String yamlString = await loadAsset(yamlPath);
|
||||
var yaml = loadYaml(yamlString);
|
||||
var recipe = yaml["recipe"];
|
||||
|
@ -72,14 +73,13 @@ class PizzaRecipe {
|
|||
PizzaRecipe pizzaRecipe = PizzaRecipe(name, description);
|
||||
pizzaRecipe.insert();
|
||||
|
||||
YamlList ingredients = recipe["ingredients"];
|
||||
YamlList ingredientsYamlList = recipe["ingredients"];
|
||||
List<Ingredient> ingredients = ingredientsYamlList.map((ingredientYaml) => Ingredient(pizzaRecipe.id!, ingredientYaml["name"], ingredientYaml["unit"], ingredientYaml["value"])).toList();
|
||||
|
||||
for (var ingredientYaml in ingredients){
|
||||
Ingredient ingredient = Ingredient(pizzaRecipe.id!, ingredientYaml["name"], ingredientYaml["unit"], ingredientYaml["value"]);
|
||||
ingredient.insert();
|
||||
}
|
||||
|
||||
YamlList steps = recipe["steps"];
|
||||
List<RecipeStep> recipeSteps = [];
|
||||
List<RecipeSubStep> recipeSubSteps = [];
|
||||
for (var step in steps){
|
||||
String stepName = step["name"];
|
||||
String stepDescription = step["description"];
|
||||
|
@ -97,25 +97,31 @@ class PizzaRecipe {
|
|||
waitMin = waitMap["min"];
|
||||
waitMax = waitMap["max"];
|
||||
}
|
||||
|
||||
RecipeStep recipeStep = RecipeStep(
|
||||
pizzaRecipe.id!,
|
||||
stepName,
|
||||
stepDescription,
|
||||
waitDescription,
|
||||
waitUnit,
|
||||
waitMin,
|
||||
waitMax
|
||||
var recipeStep = RecipeStep(
|
||||
pizzaRecipe.id!,
|
||||
stepName,
|
||||
stepDescription,
|
||||
waitDescription,
|
||||
waitUnit,
|
||||
waitMin,
|
||||
waitMax
|
||||
);
|
||||
recipeSteps.add(
|
||||
recipeStep
|
||||
);
|
||||
recipeStep.insert();
|
||||
|
||||
YamlList subSteps = step.containsKey("substeps") ? step["substeps"] : YamlList();
|
||||
for (var subStep in subSteps ) {
|
||||
RecipeSubStep recipeSubStep = RecipeSubStep(recipeStep.id!, subStep["name"], subStep["description"]);
|
||||
recipeSubStep.insert();
|
||||
recipeSubSteps.add(
|
||||
RecipeSubStep(
|
||||
recipeStep.id!,
|
||||
subStep["name"],
|
||||
subStep["description"]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return pizzaRecipe;
|
||||
return Tuple4(pizzaRecipe, ingredients, recipeSteps, recipeSubSteps);
|
||||
}
|
||||
|
||||
Future<Duration> getMinDuration() async {
|
||||
|
|
|
@ -61,4 +61,10 @@ class RecipeStep {
|
|||
int getCurrentWaitInSeconds() {
|
||||
return convertToSeconds(this.waitValue);
|
||||
}
|
||||
|
||||
static Future<List<RecipeStep>> getRecipeStepForRecipe(PizzaRecipe pizzaRecipe) async {
|
||||
final database = await getDatabase();
|
||||
final recipeStepDao = database.recipeStepDao;
|
||||
return recipeStepDao.getPizzaRecipeSteps(pizzaRecipe.id!);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:pizzaplanner/pages/AddPizzaEventPage.dart';
|
||||
import 'package:pizzaplanner/pages/AddPizzaEvent/AddPizzaEventPage.dart';
|
||||
import 'package:pizzaplanner/pages/PizzaEventsPage.dart';
|
||||
|
||||
void main() {
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
|
|||
import 'package:fluttericon/font_awesome5_icons.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaEvent.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/RecipeStep.dart';
|
||||
import 'package:pizzaplanner/util.dart';
|
||||
|
||||
class AddPizzaEventPage extends StatefulWidget {
|
||||
|
@ -13,29 +14,14 @@ class AddPizzaEventPage extends StatefulWidget {
|
|||
|
||||
class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
||||
String name = "";
|
||||
bool initialized = false;
|
||||
late PizzaRecipe pizzaRecipe;
|
||||
late List<PizzaRecipe> pizzaTypes;
|
||||
late Future<PizzaRecipe> pizzaRecipe;
|
||||
final Future<List<PizzaRecipe>> pizzaRecipes = getRecipes();
|
||||
int pizzaCount = 1;
|
||||
int doughBallSize = 250;
|
||||
DateTime eventTime = DateTime.now();
|
||||
|
||||
bool nameValidation = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
getRecipes().then((pTypes) {
|
||||
this.pizzaTypes = pTypes;
|
||||
this.pizzaRecipe = this.pizzaTypes.first;
|
||||
setState(() {this.initialized = true;});
|
||||
}, onError: (e, stacktrace) {
|
||||
print(e);
|
||||
print(stacktrace);
|
||||
Navigator.pop(context);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -70,24 +56,34 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
|||
)
|
||||
]
|
||||
),
|
||||
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Icon(FontAwesome5.pizza_slice),
|
||||
Container(width: 25),
|
||||
Expanded(
|
||||
child: this.initialized ? // Only render the dropdown if the recipes have been loaded from storage
|
||||
DropdownButton<String>(
|
||||
value: this.pizzaRecipe.name,
|
||||
onChanged: (String? newType) {
|
||||
setState(() => this.pizzaRecipe = this.pizzaTypes.firstWhere((pizzaRecipe) => pizzaRecipe.name == newType));
|
||||
},
|
||||
items: this.pizzaTypes.map((pizzaRecipe) {
|
||||
return DropdownMenuItem(
|
||||
value: pizzaRecipe.name,
|
||||
child: Text(pizzaRecipe.name)
|
||||
);
|
||||
}).toList()
|
||||
) : CircularProgressIndicator()
|
||||
child: FutureBuilder<List<PizzaRecipe>>(
|
||||
future: pizzaRecipes,
|
||||
builder: (BuildContext context, AsyncSnapshot<List<PizzaRecipe>> snapshot){
|
||||
if(snapshot.hasData && !snapshot.hasError){
|
||||
//this.pizzaRecipe = snapshot.data!.first;
|
||||
return DropdownButton<String>(
|
||||
value: "this.pizzaRecipe.name",
|
||||
onChanged: (String? newType) {
|
||||
//setState(() => this.pizzaRecipe = snapshot.data!.firstWhere((pizzaRecipe) => pizzaRecipe.name == newType));
|
||||
},
|
||||
items: snapshot.data!.map((pizzaRecipe) {
|
||||
return DropdownMenuItem(
|
||||
value: pizzaRecipe.name,
|
||||
child: Text(pizzaRecipe.name)
|
||||
);
|
||||
}).toList()
|
||||
);
|
||||
} else {
|
||||
return CircularProgressIndicator();
|
||||
}
|
||||
}
|
||||
),
|
||||
)
|
||||
]
|
||||
),
|
||||
|
@ -141,31 +137,40 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
|||
flex: 45,
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
this.initialized ? Column(
|
||||
children: this.pizzaRecipe.recipeSteps.where((recipeStep) => recipeStep.waitDescription.length > 0).map((recipeStep) {
|
||||
return <Widget>[
|
||||
Text(recipeStep.waitDescription),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Slider(
|
||||
value: recipeStep.waitValue.toDouble(),
|
||||
min: recipeStep.waitMin.toDouble(),
|
||||
max: recipeStep.waitMax.toDouble(),
|
||||
divisions: recipeStep.waitMax - recipeStep.waitMin,
|
||||
label: recipeStep.waitValue.toString(),
|
||||
onChanged: (newValue) => this.setState(() => recipeStep.waitValue = newValue.toInt()),
|
||||
)
|
||||
),
|
||||
Container(
|
||||
width: 25,
|
||||
child: Text(recipeStep.waitValue.toString())
|
||||
/*FutureBuilder(
|
||||
future: RecipeStep.getRecipeStepForRecipe(this.pizzaRecipe),
|
||||
builder: (BuildContext context, AsyncSnapshot<List<RecipeStep>> snapshot){
|
||||
if (snapshot.hasData && !snapshot.hasError) {
|
||||
return Column(
|
||||
children: snapshot.data!.where((recipeStep) => recipeStep.waitDescription.length > 0).map((recipeStep) {
|
||||
return <Widget>[
|
||||
Text(recipeStep.waitDescription),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Slider(
|
||||
value: recipeStep.waitValue.toDouble(),
|
||||
min: recipeStep.waitMin.toDouble(),
|
||||
max: recipeStep.waitMax.toDouble(),
|
||||
divisions: recipeStep.waitMax - recipeStep.waitMin,
|
||||
label: recipeStep.waitValue.toString(),
|
||||
onChanged: (newValue) => this.setState(() => recipeStep.waitValue = newValue.toInt()),
|
||||
)
|
||||
),
|
||||
Container(
|
||||
width: 25,
|
||||
child: Text(recipeStep.waitValue.toString())
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
];
|
||||
}).expand((option) => option).toList()
|
||||
) : Container(),
|
||||
];
|
||||
}).expand((option) => option).toList()
|
||||
);
|
||||
} else {
|
||||
return CircularProgressIndicator();
|
||||
}
|
||||
}
|
||||
)*/
|
||||
]
|
||||
)
|
||||
),
|
||||
|
@ -188,15 +193,15 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
|
|||
DateTime? eventTime = await showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return ConfirmPizzaEventDialog(name: name, pizzaRecipe: pizzaRecipe, pizzaCount: pizzaCount, doughBallSize: doughBallSize);
|
||||
return Text("tmp") //ConfirmPizzaEventDialog(name: name, pizzaRecipe: pizzaRecipe, pizzaCount: pizzaCount, doughBallSize: doughBallSize);
|
||||
}
|
||||
);
|
||||
if (eventTime == null){
|
||||
return;
|
||||
}
|
||||
Navigator.pop(context, PizzaEvent(
|
||||
1, // this.pizzaRecipe.id!,
|
||||
this.name,
|
||||
this.pizzaRecipe,
|
||||
this.pizzaCount,
|
||||
this.doughBallSize,
|
||||
eventTime
|
||||
|
@ -234,10 +239,11 @@ class ConfirmPizzaEventState extends State<ConfirmPizzaEventDialog> {
|
|||
late final DateTime minTime;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
void initState() async {
|
||||
super.initState();
|
||||
eventTime = DateTime.now().add(widget.pizzaRecipe.getCurrentDuration()).add(Duration(minutes: 1));
|
||||
minTime = DateTime.now().add(widget.pizzaRecipe.getCurrentDuration());
|
||||
var currentDuration = await widget.pizzaRecipe.getCurrentDuration();
|
||||
eventTime = DateTime.now().add(currentDuration).add(Duration(minutes: 1));
|
||||
minTime = DateTime.now().add(currentDuration);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -255,7 +261,7 @@ class ConfirmPizzaEventState extends State<ConfirmPizzaEventDialog> {
|
|||
Text(widget.name),
|
||||
Divider(),
|
||||
Text("Ingredients"),
|
||||
widget.pizzaRecipe.getIngredientsTable(widget.pizzaCount, widget.doughBallSize),
|
||||
//widget.pizzaRecipe.getIngredientsTable(widget.pizzaCount, widget.doughBallSize),
|
||||
Divider(),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
|
@ -293,7 +299,7 @@ class ConfirmPizzaEventState extends State<ConfirmPizzaEventDialog> {
|
|||
flex: 60,
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
widget.pizzaRecipe.getStepTimeTable(eventTime)
|
||||
//widget.pizzaRecipe.getStepTimeTable(eventTime)
|
||||
]
|
||||
)
|
||||
),
|
0
lib/pages/AddPizzaEvent/PickPizzaRecipePage.dart
Normal file
0
lib/pages/AddPizzaEvent/PickPizzaRecipePage.dart
Normal file
|
@ -21,7 +21,7 @@ class PizzaEventsState extends State<PizzaEventsPage> {
|
|||
body: ListView.separated(
|
||||
padding: const EdgeInsets.all(8),
|
||||
itemCount: pizzaEvents.length,
|
||||
itemBuilder: (BuildContext context, int i) => PizzaEventWidget(pizzaEvents[i]),
|
||||
itemBuilder: (BuildContext context, int i) => const Divider(),// PizzaEventWidget(pizzaEvents[i]),
|
||||
separatorBuilder: (BuildContext context, int i) => const Divider(),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
|
|
|
@ -6,17 +6,30 @@ import 'package:pizzaplanner/entities/PizzaDatabase.dart';
|
|||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||
|
||||
Future<List<PizzaRecipe>> getRecipes() async {
|
||||
final database = await getDatabase();
|
||||
final pizzaRecipeDao = database.pizzaRecipeDao;
|
||||
final pizzaRecipes = await pizzaRecipeDao.getAllPizzaRecipes();
|
||||
if (pizzaRecipes.isNotEmpty) {
|
||||
return pizzaRecipes;
|
||||
}
|
||||
|
||||
// load recipes from yaml files in the asset directory
|
||||
final manifestContent = await rootBundle.loadString('AssetManifest.json');
|
||||
final Map<String, dynamic> manifestMap = json.decode(manifestContent);
|
||||
final List<String> fileList = manifestMap.keys.toList();
|
||||
final List<PizzaRecipe> pizzaRecipes = [];
|
||||
final List<PizzaRecipe> newPizzaRecipes = [];
|
||||
for (var filePath in fileList) {
|
||||
if (filePath.startsWith("assets/recipes") && filePath.endsWith(".yaml")) {
|
||||
PizzaRecipe pizzaRecipe = await PizzaRecipe.fromYaml(filePath);
|
||||
pizzaRecipes.add(pizzaRecipe);
|
||||
var parsedPizzaRecipe = await PizzaRecipe.fromYaml(filePath);
|
||||
await parsedPizzaRecipe.item1.insert();
|
||||
newPizzaRecipes.add(parsedPizzaRecipe.item1);
|
||||
|
||||
parsedPizzaRecipe.item2.forEach((ingredient) async { await ingredient.insert(); });
|
||||
parsedPizzaRecipe.item3.forEach((recipeStep) async { await recipeStep.insert(); });
|
||||
parsedPizzaRecipe.item4.forEach((recipeSubStep) async { await recipeSubStep.insert(); });
|
||||
}
|
||||
}
|
||||
return pizzaRecipes;
|
||||
return newPizzaRecipes;
|
||||
}
|
||||
|
||||
Future<String> loadAsset(String path) async {
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaEvent.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/PizzaRecipe.dart';
|
||||
import 'package:pizzaplanner/util.dart';
|
||||
|
||||
class PizzaEventWidget extends StatelessWidget {
|
||||
final PizzaEvent pizzaEvent;
|
||||
final PizzaRecipe pizzaRecipe;
|
||||
|
||||
PizzaEventWidget(this.pizzaEvent);
|
||||
PizzaEventWidget(this.pizzaEvent, this.pizzaRecipe);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
|
@ -69,7 +71,7 @@ class PizzaEventWidget extends StatelessWidget {
|
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Text(getDateFormat().format(pizzaEvent.dateTime)),
|
||||
Text(pizzaEvent.recipe.name)
|
||||
Text(pizzaRecipe.name)
|
||||
],
|
||||
),
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ dependencies:
|
|||
yaml: ^3.1.0
|
||||
|
||||
floor: ^1.1.0
|
||||
tuple: ^2.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Add table
Reference in a new issue