Skip to content
Snippets Groups Projects
Commit 0fa7fe75 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Merge branch '7-save-pictures-in-app-folder' into 'master'

Resolve "Save pictures in app folder"

Closes #7

See merge request !3
parents 9e3a9e56 7548cdde
No related branches found
No related tags found
1 merge request!3Resolve "Save pictures in app folder"
Pipeline #5029 passed
org.gradle.jvmargs=-Xmx1536M org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
app.versionName=0.0.2 app.versionName=0.0.3
app.versionCode=2 app.versionCode=3
Save picture in application folder. Clean some code.
Sauvegarde de l'image dans le dossier de l'application, amélioration de code.
...@@ -14,9 +14,11 @@ class ScreenCamera extends StatelessWidget { ...@@ -14,9 +14,11 @@ class ScreenCamera extends StatelessWidget {
return Material( return Material(
color: Theme.of(context).colorScheme.background, color: Theme.of(context).colorScheme.background,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
const SizedBox(height: 8), const SizedBox(height: 8),
TakePictureWidget(), const TakePictureWidget(),
], ],
), ),
); );
......
import 'dart:io';
import 'package:camera/camera.dart'; import 'package:camera/camera.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:unicons/unicons.dart'; import 'package:unicons/unicons.dart';
import 'package:stopmotion/utils/picture_storage.dart';
class TakePictureWidget extends StatefulWidget { class TakePictureWidget extends StatefulWidget {
const TakePictureWidget({super.key}); const TakePictureWidget({super.key});
...@@ -12,13 +15,15 @@ class TakePictureWidget extends StatefulWidget { ...@@ -12,13 +15,15 @@ class TakePictureWidget extends StatefulWidget {
class TakePictureWidgetState extends State<TakePictureWidget> { class TakePictureWidgetState extends State<TakePictureWidget> {
CameraController? controller; CameraController? controller;
PictureStorage? storage;
List<String> previousImages = []; List<String> previousImages = [];
String debug = ''; List<String> debug = [];
@override @override
void initState() { void initState() {
loadCamera(); loadCamera();
storage = PictureStorage();
super.initState(); super.initState();
} }
...@@ -50,80 +55,67 @@ class TakePictureWidgetState extends State<TakePictureWidget> { ...@@ -50,80 +55,67 @@ class TakePictureWidgetState extends State<TakePictureWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Center(
children: [ child: Column(
Container( mainAxisAlignment: MainAxisAlignment.start,
height: 300, crossAxisAlignment: CrossAxisAlignment.center,
width: 400, children: [
child: controller == null Container(
? Center(child: Text("Loading camera...")) height: 400,
: !controller!.value.isInitialized child: controller == null
? Center(child: CircularProgressIndicator()) ? Center(child: Text("Loading camera..."))
: CameraPreview(controller!), : !controller!.value.isInitialized
), ? Center(child: CircularProgressIndicator())
Row( : CameraPreview(controller!),
mainAxisAlignment: MainAxisAlignment.spaceBetween, ),
children: [ ElevatedButton.icon(
ElevatedButton.icon( label: Text("Take picture"),
label: Text("Capture (1)"), icon: Icon(UniconsLine.camera),
icon: Icon(UniconsLine.camera), onPressed: () async {
onPressed: () async { try {
try { if ((controller != null) && (controller!.value.isInitialized)) {
if ((controller != null) && (controller!.value.isInitialized)) { final XFile image = await controller!.takePicture();
final XFile image = await controller!.takePicture(); print('image.path: ' + image.path);
debug.add('image.path: ' + image.path);
print('(1)path: ' + image.path);
previousImages.add(image.path); File savedFile = await storage!.writeCounter(File(image.path));
setState(() {}); debug.add('image.path: ' + image.path);
debug = debug + "\n" + '(1) path: ' + image.path; String imagePath = savedFile.path;
} print('imagePath: ' + imagePath);
} catch (e) { debug.add('imagePath: ' + imagePath);
debug = debug + "\n" + '(1) error: ' + e.toString();
setState(() {}); previousImages.add(imagePath);
print(e);
}
},
),
ElevatedButton.icon(
label: Text("Capture (2)"),
icon: Icon(UniconsLine.camera),
onPressed: () async {
try {
final ImagePicker _picker = ImagePicker();
final XFile? image = await _picker.pickImage(source: ImageSource.camera);
print('(2) path: ' + image!.path);
previousImages.add(image.path);
setState(() {}); setState(() {});
debug = debug + "\n" + '(2) path: ' + image.path;
} catch (e) {
debug = debug + "\n" + '(2) error: ' + e.toString();
setState(() {});
print(e);
} }
}, } catch (e) {
), debug.add('error: ' + e.toString());
], setState(() {});
),
Text('debug: ' + debug), print(e);
previousImages.length == 0 }
? Text('no previous images') },
: Column( ),
children: previousImages.map((String imagePath) { Text('debug: '),
return Row( Column(
children: [ children: debug.map((String line) {
// Image.file(File(imagePath)), return Text(line);
Text(imagePath), }).toList(),
], ),
); previousImages.length == 0
}).toList(), ? Text('no previous images')
), : Column(
], children: previousImages.map((String imagePath) {
return Row(
children: [
// Image.file(File(imagePath)),
Text(imagePath),
],
);
}).toList(),
),
],
),
); );
} }
} }
import 'dart:io';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
class PictureStorage {
Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
Future<String> _localFilePath(String name) async {
final path = await _localPath;
return path + '/' + name;
}
Future<File> moveFile(File sourceFile, String newPath) async {
try {
return await sourceFile.rename(newPath);
} on FileSystemException catch (e) {
print('Found exception while moving file: ' + e.toString());
final newFile = await sourceFile.copy(newPath);
await sourceFile.delete();
return newFile;
}
}
Future<File> writeCounter(File sourceFile) async {
final targetFile = await _localFilePath(basename(sourceFile.path));
return moveFile(sourceFile, targetFile);
}
}
...@@ -9,14 +9,6 @@ packages: ...@@ -9,14 +9,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.4.2" version: "2.4.2"
async:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.11.0"
bloc: bloc:
dependency: transitive dependency: transitive
description: description:
...@@ -145,38 +137,6 @@ packages: ...@@ -145,38 +137,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "7.0.0" version: "7.0.0"
file_selector_linux:
dependency: transitive
description:
name: file_selector_linux
sha256: "045d372bf19b02aeb69cacf8b4009555fb5f6f0b7ad8016e5f46dd1387ddd492"
url: "https://pub.dev"
source: hosted
version: "0.9.2+1"
file_selector_macos:
dependency: transitive
description:
name: file_selector_macos
sha256: b15c3da8bd4908b9918111fa486903f5808e388b8d1c559949f584725a6594d6
url: "https://pub.dev"
source: hosted
version: "0.9.3+3"
file_selector_platform_interface:
dependency: transitive
description:
name: file_selector_platform_interface
sha256: "0aa47a725c346825a2bd396343ce63ac00bda6eff2fbc43eabe99737dede8262"
url: "https://pub.dev"
source: hosted
version: "2.6.1"
file_selector_windows:
dependency: transitive
description:
name: file_selector_windows
sha256: d3547240c20cabf205c7c7f01a50ecdbc413755814d6677f3cb366f04abcead0
url: "https://pub.dev"
source: hosted
version: "0.9.3+1"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
...@@ -216,22 +176,6 @@ packages: ...@@ -216,22 +176,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.2.3" version: "2.2.3"
http:
dependency: transitive
description:
name: http
sha256: d4872660c46d929f6b8a9ef4e7a7eff7e49bbf0c4ec3f385ee32df5119175139
url: "https://pub.dev"
source: hosted
version: "1.1.2"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
hydrated_bloc: hydrated_bloc:
dependency: "direct main" dependency: "direct main"
description: description:
...@@ -240,70 +184,6 @@ packages: ...@@ -240,70 +184,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "9.1.3" version: "9.1.3"
image_picker:
dependency: "direct main"
description:
name: image_picker
sha256: "340efe08645537d6b088a30620ee5752298b1630f23a829181172610b868262b"
url: "https://pub.dev"
source: hosted
version: "1.0.6"
image_picker_android:
dependency: transitive
description:
name: image_picker_android
sha256: "1a27bf4cc0330389cebe465bab08fe6dec97e44015b4899637344bb7297759ec"
url: "https://pub.dev"
source: hosted
version: "0.8.9+2"
image_picker_for_web:
dependency: transitive
description:
name: image_picker_for_web
sha256: e2423c53a68b579a7c37a1eda967b8ae536c3d98518e5db95ca1fe5719a730a3
url: "https://pub.dev"
source: hosted
version: "3.0.2"
image_picker_ios:
dependency: transitive
description:
name: image_picker_ios
sha256: eac0a62104fa12feed213596df0321f57ce5a572562f72a68c4ff81e9e4caacf
url: "https://pub.dev"
source: hosted
version: "0.8.9"
image_picker_linux:
dependency: transitive
description:
name: image_picker_linux
sha256: "4ed1d9bb36f7cd60aa6e6cd479779cc56a4cb4e4de8f49d487b1aaad831300fa"
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
image_picker_macos:
dependency: transitive
description:
name: image_picker_macos
sha256: "3f5ad1e8112a9a6111c46d0b57a7be2286a9a07fc6e1976fdf5be2bd31d4ff62"
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
image_picker_platform_interface:
dependency: transitive
description:
name: image_picker_platform_interface
sha256: "0e827c156e3a90edd3bbe7f6de048b39247b16e58173b08a835b7eb00aba239e"
url: "https://pub.dev"
source: hosted
version: "2.9.2"
image_picker_windows:
dependency: transitive
description:
name: image_picker_windows
sha256: "6ad07afc4eb1bc25f3a01084d28520496c4a3bb0cb13685435838167c9dcedeb"
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
intl: intl:
dependency: transitive dependency: transitive
description: description:
...@@ -328,14 +208,6 @@ packages: ...@@ -328,14 +208,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.10.0" version: "1.10.0"
mime:
dependency: transitive
description:
name: mime
sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e
url: "https://pub.dev"
source: hosted
version: "1.0.4"
nested: nested:
dependency: transitive dependency: transitive
description: description:
...@@ -485,14 +357,6 @@ packages: ...@@ -485,14 +357,6 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.99" version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.10.0"
stream_transform: stream_transform:
dependency: transitive dependency: transitive
description: description:
...@@ -501,14 +365,6 @@ packages: ...@@ -501,14 +365,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
synchronized: synchronized:
dependency: transitive dependency: transitive
description: description:
...@@ -517,14 +373,6 @@ packages: ...@@ -517,14 +373,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "3.1.0+1" version: "3.1.0+1"
term_glyph:
dependency: transitive
description:
name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.1"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:
......
...@@ -3,7 +3,7 @@ description: stop motion assistant ...@@ -3,7 +3,7 @@ description: stop motion assistant
publish_to: 'none' publish_to: 'none'
version: 0.0.2+2 version: 0.0.3+3
environment: environment:
sdk: '^3.0.0' sdk: '^3.0.0'
...@@ -17,7 +17,6 @@ dependencies: ...@@ -17,7 +17,6 @@ dependencies:
equatable: ^2.0.5 equatable: ^2.0.5
flutter_bloc: ^8.1.1 flutter_bloc: ^8.1.1
hydrated_bloc: ^9.0.0 hydrated_bloc: ^9.0.0
image_picker: ^1.0.6
path: ^1.8.3 path: ^1.8.3
path_provider: ^2.1.1 path_provider: ^2.1.1
unicons: ^2.1.1 unicons: ^2.1.1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment