New post on /r/flutterdev subreddit:
<b>HELP PLEASE: I am trying to make a front that has a button to pick an image from gallery and replace it with the current one</b>
Hi,I am having a hard time trying to make the pick from gallery button work, I tried so many tutorials and videos, and IDK what I am doing wrong, please help me solve this.The image of the interface link is below code<pre>import 'dart:io'; import 'dart:ui'; import 'package:image_picker/image_picker.dart'; import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( debugShowCheckedModeBanner: false, home: HomePage(), )); } class HomePage extends StatefulWidget {
@override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { File? image; Future pickImage(ImageSource source) async{ final image = await ImagePicker().pickImage(source: source); if (image== null) return; final imageTemporary =File(image.path); this.image = imageTemporary; } final formKey = GlobalKey<FormState>(); //key for form
@override Widget build(BuildContext context) { final double height= MediaQuery.of(context).size.height; final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(); return Scaffold( appBar: AppBar( elevation:0, brightness: Brightness.light, backgroundColor:Colors.white, leading: Icon(Icons.arrow_back_outlined,size: 20,color:
Colors.black), title:Text('Enregistrer',style: TextStyle(fontSize: 15,color:
Colors.blue),textAlign:TextAlign.right), ), body: SingleChildScrollView( padding: EdgeInsets.symmetric(horizontal: 20 ), child: Form( key: formKey, child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children:<Widget> [ Column( children: [ if(Image ==null ?(Image.asset("images/emilia.jpeg",height: 150,width: 150))):null, pickImage != null ? FileImage(pickImage): null, Row( children:[ OutlineButton.icon( icon:Icon(Icons.camera_alt_outlined,color:
Colors.black), onPressed: (){pickImage(
ImageSource.camera);}, label: Text('Appareil photo',style: TextStyle(fontSize: 10.0)), ), OutlineButton.icon( icon:Icon(Icons.photo_album_rounded,color:
Colors.black), onPressed: (){pickImage(
ImageSource.gallery);}, label: Text('ouvrir la Gallerie',style: TextStyle(fontSize: 10.0)), ) ] ), ], ), Column( crossAxisAlignment: CrossAxisAlignment.stretch, children:<Widget> [ Text('nom', textAlign:TextAlign.left), SizedBox(width:2.0), TextFormField( decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'nom', hintText: 'Entrer votre nom', ), validator:(value) { if (value!.isEmpty || !RegExp(r'^[a-z A-Z]+$').hasMatch(value!)); return "entrer votre nom"; } ), SizedBox(height: 10.0), Text('prénom', textAlign:TextAlign.left), TextFormField( decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'prénom', hintText: 'Entrer votre prénom', ), validator:(value) { if (value!.isEmpty || !RegExp(r'^[a-z A-Z]+$').hasMatch(value!)); return "entrer votre prénom"; } ), Text("Date d'anniversaire", textAlign:TextAlign.left), SizedBox(height: 10.0), TextFormField( decoration: InputDecoration( border: OutlineInputBorder(), labelText: "Date d'anniversaire", hintText: 'Entrer votre date', ), validator:(value) { if (value!.isEmpty || !RegExp(r'^[+]*[(]{0-9}{1,4}[)]{0,1}[-\s\./0-9]+$').hasMatch(value!)); return "entrer votre date"; } ), Text('Adresse e-mail', textAlign:TextAlign.left), SizedBox(height: 10.0), TextFormField( decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'Adresse e-mail', hintText: 'Entrer votre mail', ), validator:(value){ if (value!.isEmpty|| !RegExp(r'^[a-z A-Z]+$').hasMatch(value!)); return "Entrer votre mail"; } ), Text('Numéro de téléphone', textAlign:TextAlign.left), SizedBox(height: 10.0), TextFormField( decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'numéro de téléphone', hintText: 'entrer votre numéro de téléphone', ), validator:(value){ if (value!.isEmpty|| !RegExp(r'^[+]*[(]{0-9}{1,4}[)]{0,1}[-\s\./0-9]+$').hasMatch(value!)); return "Entrer votre telephone"; } ), Text('langue parlée', tex…