add image picler

This commit is contained in:
Valentin CZERYBA 2024-07-20 18:06:28 +02:00
parent 3306a34e5c
commit 43a90bccb4

View File

@ -1,6 +1,8 @@
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'package:image_picker/image_picker.dart';
import 'DisplayPictureScreen.dart'; import 'DisplayPictureScreen.dart';
import 'package:camera/camera.dart'; import 'package:camera/camera.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -63,6 +65,22 @@ class CameraState extends State<Camera> {
Future<void> getCamera() async {} Future<void> getCamera() async {}
Future<void> 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 @override
void dispose() { void dispose() {
// Dispose of the controller when the widget is disposed. // Dispose of the controller when the widget is disposed.
@ -95,7 +113,7 @@ class CameraState extends State<Camera> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
FloatingActionButton( FloatingActionButton(
onPressed: () => {}, onPressed: pickImage,
child: Icon(Icons.photo_library), child: Icon(Icons.photo_library),
), ),
SizedBox(width: 40), SizedBox(width: 40),