added loading of pizza yaml from local storage
This commit is contained in:
parent
ed21926cae
commit
93bb696988
3 changed files with 56 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
@ -142,21 +143,65 @@ class RecipesPageState extends State<RecipesPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
Container(
|
Expanded(
|
||||||
color: Colors.blue,
|
flex: 5,
|
||||||
width: double.infinity,
|
child: Row(
|
||||||
child: TextButton(
|
children: <Widget>[
|
||||||
onPressed: () async {
|
Expanded(
|
||||||
Navigator.pushNamed(context, "/recipes/edit");
|
flex: 5,
|
||||||
},
|
child: Container(
|
||||||
child: const Text("New Recipe", style: TextStyle(color: Colors.white)),
|
color: Colors.blue,
|
||||||
)
|
width: double.infinity,
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
loadRecipe();
|
||||||
|
},
|
||||||
|
child: const Text("Load Recipe", style: TextStyle(color: Colors.white)),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Expanded(
|
||||||
|
flex: 1,
|
||||||
|
child: SizedBox(),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
flex: 5,
|
||||||
|
child: Container(
|
||||||
|
color: Colors.blue,
|
||||||
|
width: double.infinity,
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
Navigator.pushNamed(context, "/recipes/edit");
|
||||||
|
},
|
||||||
|
child: const Text("New Recipe", style: TextStyle(color: Colors.white)),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> loadRecipe() async {
|
||||||
|
final result = await FilePicker.platform.pickFiles();
|
||||||
|
if (result == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
File(result.files.single.path).readAsString().then((String contents) async {
|
||||||
|
final pizzaRecipe = await PizzaRecipe.fromYaml(contents);
|
||||||
|
final pizzaRecipeBox = Hive.box<PizzaRecipe>("PizzaRecipes");
|
||||||
|
pizzaRecipeBox.add(pizzaRecipe);
|
||||||
|
});
|
||||||
|
} catch (exception) {
|
||||||
|
print(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> sharePizzaRecipe(PizzaRecipe pizzaRecipe) async{
|
Future<void> sharePizzaRecipe(PizzaRecipe pizzaRecipe) async{
|
||||||
final tempDir = await getTemporaryDirectory();
|
final tempDir = await getTemporaryDirectory();
|
||||||
final recipeName = pizzaRecipe.name.replaceAll(RegExp(r"\s+"), "");
|
final recipeName = pizzaRecipe.name.replaceAll(RegExp(r"\s+"), "");
|
||||||
|
|
|
@ -54,6 +54,8 @@ dependencies:
|
||||||
path: ^1.8.0
|
path: ^1.8.0
|
||||||
share_plus: ^2.1.4
|
share_plus: ^2.1.4
|
||||||
|
|
||||||
|
file_picker: ^4.0.2
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
1
todo.md
1
todo.md
|
@ -3,7 +3,6 @@
|
||||||
## Feature
|
## Feature
|
||||||
- add 'capturing' sharing intent
|
- add 'capturing' sharing intent
|
||||||
- add import of recipes
|
- add import of recipes
|
||||||
- from local
|
|
||||||
- from raw url
|
- from raw url
|
||||||
- maybe allow a 'dir' yaml, that just points to other raw pizza yaml urls
|
- maybe allow a 'dir' yaml, that just points to other raw pizza yaml urls
|
||||||
- add settings page
|
- add settings page
|
||||||
|
|
Loading…
Add table
Reference in a new issue