From 43a90bccb454dc7164983f69daa5b843a9356734 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 20 Jul 2024 18:06:28 +0200 Subject: [PATCH] add image picler --- covas_mobile/lib/pages/Camera.dart | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/covas_mobile/lib/pages/Camera.dart b/covas_mobile/lib/pages/Camera.dart index f5959e7..9ff6cc3 100644 --- a/covas_mobile/lib/pages/Camera.dart +++ b/covas_mobile/lib/pages/Camera.dart @@ -1,6 +1,8 @@ import 'dart:async'; import 'dart:io'; +import 'package:image_picker/image_picker.dart'; + import 'DisplayPictureScreen.dart'; import 'package:camera/camera.dart'; import 'package:flutter/material.dart'; @@ -63,6 +65,22 @@ class CameraState extends State { Future getCamera() async {} + Future pickImage() async { + final imagePicker = ImagePicker(); + final pickedFile = await imagePicker.pickImage(source: ImageSource.gallery); + if (pickedFile != null) { + await Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => DisplayPictureScreen( + // Pass the automatically generated path to + // the DisplayPictureScreen widget. + imagePath: pickedFile.path, + ), + ), + ); + } + } + @override void dispose() { // Dispose of the controller when the widget is disposed. @@ -95,7 +113,7 @@ class CameraState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ FloatingActionButton( - onPressed: () => {}, + onPressed: pickImage, child: Icon(Icons.photo_library), ), SizedBox(width: 40),