diff --git a/android/gradle.properties b/android/gradle.properties index 818e87b23b224ced309ae5c147e5ed827826e237..db7a1ee2908d6e94aeb319e1c1b548a8bb245891 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.0.2 -app.versionCode=2 +app.versionName=0.0.3 +app.versionCode=3 diff --git a/fastlane/metadata/android/en-US/changelogs/3.txt b/fastlane/metadata/android/en-US/changelogs/3.txt new file mode 100644 index 0000000000000000000000000000000000000000..ad391b0e1435a348fde7b9e43fa5b0a09580b15c --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/3.txt @@ -0,0 +1 @@ +Save picture in application folder. Clean some code. diff --git a/fastlane/metadata/android/fr-FR/changelogs/3.txt b/fastlane/metadata/android/fr-FR/changelogs/3.txt new file mode 100644 index 0000000000000000000000000000000000000000..98bcef5f216cc1f10ba1854be6229f014abd597b --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/3.txt @@ -0,0 +1 @@ +Sauvegarde de l'image dans le dossier de l'application, amélioration de code. diff --git a/lib/ui/screens/camera.dart b/lib/ui/screens/camera.dart index 69ae81e174377e9567c19d26c1cdc2f92a7d7328..eafa1426d8acc8a9ec93ad36f933182cc20b0f53 100644 --- a/lib/ui/screens/camera.dart +++ b/lib/ui/screens/camera.dart @@ -14,9 +14,11 @@ class ScreenCamera extends StatelessWidget { return Material( color: Theme.of(context).colorScheme.background, child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[ const SizedBox(height: 8), - TakePictureWidget(), + const TakePictureWidget(), ], ), ); diff --git a/lib/ui/widgets/take_picture_widget.dart b/lib/ui/widgets/take_picture_widget.dart index 488dd178538f9c3422cf6123023da369084c628b..d68b7341238278e82a6e7f4f61c9c761b6976c74 100644 --- a/lib/ui/widgets/take_picture_widget.dart +++ b/lib/ui/widgets/take_picture_widget.dart @@ -1,8 +1,11 @@ +import 'dart:io'; + import 'package:camera/camera.dart'; import 'package:flutter/material.dart'; -import 'package:image_picker/image_picker.dart'; import 'package:unicons/unicons.dart'; +import 'package:stopmotion/utils/picture_storage.dart'; + class TakePictureWidget extends StatefulWidget { const TakePictureWidget({super.key}); @@ -12,13 +15,15 @@ class TakePictureWidget extends StatefulWidget { class TakePictureWidgetState extends State<TakePictureWidget> { CameraController? controller; + PictureStorage? storage; List<String> previousImages = []; - String debug = ''; + List<String> debug = []; @override void initState() { loadCamera(); + storage = PictureStorage(); super.initState(); } @@ -50,80 +55,67 @@ class TakePictureWidgetState extends State<TakePictureWidget> { @override Widget build(BuildContext context) { - return Column( - children: [ - Container( - height: 300, - width: 400, - child: controller == null - ? Center(child: Text("Loading camera...")) - : !controller!.value.isInitialized - ? Center(child: CircularProgressIndicator()) - : CameraPreview(controller!), - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ElevatedButton.icon( - label: Text("Capture (1)"), - icon: Icon(UniconsLine.camera), - onPressed: () async { - try { - if ((controller != null) && (controller!.value.isInitialized)) { - final XFile image = await controller!.takePicture(); - - print('(1)path: ' + image.path); - previousImages.add(image.path); - setState(() {}); - - debug = debug + "\n" + '(1) path: ' + image.path; - } - } catch (e) { - debug = debug + "\n" + '(1) error: ' + e.toString(); - setState(() {}); - - 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); + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + height: 400, + child: controller == null + ? Center(child: Text("Loading camera...")) + : !controller!.value.isInitialized + ? Center(child: CircularProgressIndicator()) + : CameraPreview(controller!), + ), + ElevatedButton.icon( + label: Text("Take picture"), + icon: Icon(UniconsLine.camera), + onPressed: () async { + try { + if ((controller != null) && (controller!.value.isInitialized)) { + final XFile image = await controller!.takePicture(); + print('image.path: ' + image.path); + debug.add('image.path: ' + image.path); + + File savedFile = await storage!.writeCounter(File(image.path)); + debug.add('image.path: ' + image.path); + + String imagePath = savedFile.path; + print('imagePath: ' + imagePath); + debug.add('imagePath: ' + imagePath); + + previousImages.add(imagePath); setState(() {}); - - debug = debug + "\n" + '(2) path: ' + image.path; - } catch (e) { - debug = debug + "\n" + '(2) error: ' + e.toString(); - setState(() {}); - - print(e); } - }, - ), - ], - ), - Text('debug: ' + debug), - previousImages.length == 0 - ? Text('no previous images') - : Column( - children: previousImages.map((String imagePath) { - return Row( - children: [ - // Image.file(File(imagePath)), - Text(imagePath), - ], - ); - }).toList(), - ), - ], + } catch (e) { + debug.add('error: ' + e.toString()); + setState(() {}); + + print(e); + } + }, + ), + Text('debug: '), + Column( + children: debug.map((String line) { + return Text(line); + }).toList(), + ), + previousImages.length == 0 + ? Text('no previous images') + : Column( + children: previousImages.map((String imagePath) { + return Row( + children: [ + // Image.file(File(imagePath)), + Text(imagePath), + ], + ); + }).toList(), + ), + ], + ), ); } } diff --git a/lib/utils/picture_storage.dart b/lib/utils/picture_storage.dart new file mode 100644 index 0000000000000000000000000000000000000000..72e2278f677d39ef318ab24a57dd4a7e8b9ae950 --- /dev/null +++ b/lib/utils/picture_storage.dart @@ -0,0 +1,35 @@ +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); + } +} diff --git a/pubspec.lock b/pubspec.lock index 7d03778bd693a2e32e8fdaf42b23b10e6698c117..3c0facbe365f419588dddf0c1a8926dd11044459 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -9,14 +9,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.4.2" - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" bloc: dependency: transitive description: @@ -145,38 +137,6 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: "direct main" description: flutter @@ -216,22 +176,6 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: "direct main" description: @@ -240,70 +184,6 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: transitive description: @@ -328,14 +208,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" - mime: - dependency: transitive - description: - name: mime - sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e - url: "https://pub.dev" - source: hosted - version: "1.0.4" nested: dependency: transitive description: @@ -485,14 +357,6 @@ packages: description: flutter source: sdk 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: dependency: transitive description: @@ -501,14 +365,6 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: transitive description: @@ -517,14 +373,6 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6589a7ffcb8ec0b330d0e5562ce1441301d1a3bb..01804485e4fd9e6d4941d862e06714251ce74de1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: stop motion assistant publish_to: 'none' -version: 0.0.2+2 +version: 0.0.3+3 environment: sdk: '^3.0.0' @@ -17,7 +17,6 @@ dependencies: equatable: ^2.0.5 flutter_bloc: ^8.1.1 hydrated_bloc: ^9.0.0 - image_picker: ^1.0.6 path: ^1.8.3 path_provider: ^2.1.1 unicons: ^2.1.1