added sharing of recipes
This commit is contained in:
parent
67edbfc472
commit
8927136761
3 changed files with 31 additions and 1 deletions
|
@ -1,9 +1,14 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart';
|
||||
import 'package:pizzaplanner/pages/nav_drawer.dart';
|
||||
import 'package:pizzaplanner/pages/scaffold.dart';
|
||||
import 'package:pizzaplanner/widgets/pizza_recipe_widget.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
|
||||
class RecipesPage extends StatefulWidget {
|
||||
|
@ -64,6 +69,13 @@ class RecipesPageState extends State<RecipesPage> {
|
|||
title: Text(pizzaRecipe.name),
|
||||
content: const Text("What do you want to do?"),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
sharePizzaRecipe(pizzaRecipe);
|
||||
},
|
||||
child: const Text("Share"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
|
@ -144,4 +156,19 @@ class RecipesPageState extends State<RecipesPage> {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> sharePizzaRecipe(PizzaRecipe pizzaRecipe) async{
|
||||
final tempDir = await getTemporaryDirectory();
|
||||
final recipeName = pizzaRecipe.name.replaceAll(RegExp(r"\s+"), "");
|
||||
final recipeYamlPath = path.join(
|
||||
tempDir.absolute.path,
|
||||
"$recipeName.pizza"
|
||||
);
|
||||
|
||||
final recipeYamlHandle = File(recipeYamlPath);
|
||||
|
||||
await recipeYamlHandle.writeAsString(pizzaRecipe.toYaml());
|
||||
|
||||
Share.shareFiles([recipeYamlPath], text: "${pizzaRecipe.name}");
|
||||
}
|
||||
}
|
|
@ -50,6 +50,10 @@ dependencies:
|
|||
flutter_ringtone_player: ^3.0.0
|
||||
vibration: ^1.7.4-nullsafety.0
|
||||
|
||||
path_provider: ^2.0.3
|
||||
path: ^1.8.0
|
||||
share_plus: ^2.1.4
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
|
1
todo.md
1
todo.md
|
@ -1,7 +1,6 @@
|
|||
# TODO
|
||||
|
||||
## Feature
|
||||
- share to/export of yaml of recipes
|
||||
- add an import of recipes from raw url
|
||||
- maybe allow a 'dir' yaml, that just points to other raw pizza yaml urls
|
||||
- add settings page
|
||||
|
|
Loading…
Add table
Reference in a new issue