Skip to content

Commit

Permalink
store plant pics to dedicated directory
Browse files Browse the repository at this point in the history
  • Loading branch information
abertschi committed Apr 2, 2023
1 parent 62f1639 commit 36ab400
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/app_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class AppContext {
}

exportPath() {
return db.exportBackupPath;
return db.exportDbBackupPath;
}

exportBackupPath() {
return db.exportBackupPath;
return db.exportDbBackupPath;
}

// returns backup file or exception
Expand Down
13 changes: 12 additions & 1 deletion lib/screens/plant_edit.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:water_me/models/plant_model.dart';
import 'package:water_me/screens/take_picture.dart';
Expand Down Expand Up @@ -87,12 +88,22 @@ class _EditPlant extends State<EditPlant> {

onTakePicture(BuildContext context, PlantModel plant) async {
var c = Provider.of<AppContext>(context, listen: false).camera!;
var appCtx = Provider.of<AppContext>(context, listen: false);
final image = await Navigator.push(
context,
MaterialPageRoute(builder: (context) => TakePictureScreen(camera: c)),
);
if (image != null && image is String) {
plant.image = image;
if (await Permission.storage.request().isGranted) {
String directory = await appCtx.db.exportImageDirectoryPath;
String name = "$directory/" +
"${DateTime.now().toIso8601String().replaceAll(":", "_")}.jpg";
File newImage = await File(image).copy(name);
plant.image = newImage.path;
} else {
plant.image = image;
}
print(plant.image);
}
}

Expand Down
13 changes: 9 additions & 4 deletions lib/services/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@ class Db {
return _model;
}

Future<String> get exportPath async {
Future<String> get exportDbFilePath async {
final directory = await getExternalStorageDirectory();
return "${directory!.path}/water_me.json";
}

Future<String> get exportBackupPath async {
Future<String> get exportImageDirectoryPath async {
final directory = await getExternalStorageDirectory();
return directory!.path;
}

Future<String> get exportDbBackupPath async {
final directory = await getExternalStorageDirectory();
return "${directory!.path}/water_me.backup.json";
}

Future<File> get exportFile async {
final path = await exportPath;
final path = await exportDbFilePath;
return File(path!);
}

Future<File> get exportBackupFile async {
final path = await exportBackupPath;
final path = await exportDbBackupPath;
return File(path!);
}

Expand Down

0 comments on commit 36ab400

Please sign in to comment.