pub dev den image picker eklentisi alıp projeme ekledim yalnız hatalar alıyorum kodu alta bırakıyorum eğer okuyorsan bu kodu kendi pc nizde bi deneyip bi bakarmısınız rica etsem lütfen bana geri dönüş yapmayı unutmayın🙂
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
void main() {
runApp(MaterialApp(
home: userProfilimageUpdateClass(),
));
}
class userProfilimageUpdateClass extends StatefulWidget {
@override
_userProfilimageUpdateClassState createState() =>
_userProfilimageUpdateClassState();
}
class _userProfilimageUpdateClassState
extends State<userProfilimageUpdateClass> {
late File _image;
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.gallery);
setState(() {
if (pickedFile != null) {
_image = File(pickedFile.path);
} else {
print("Resim Yok");
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: BackButton(
color: Colors.lightGreen,
),
title: Text(
"Profil Resmi Güncelle",
style: TextStyle(
fontSize: 16,
color: Colors.lightGreen,
),
),
),
body: Container(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
width: 150,
height: 150,
decoration: BoxDecoration(
borderRadius: BorderRadius.vertical(
top: Radius.circular(50),
bottom: Radius.circular(50),
),
),
child: ClipOval(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/user_pp.jpg"),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.vertical(
top: Radius.circular(50),
bottom: Radius.circular(50),
),
),
child: _image == null ? Text(" ") : Image.file(_image),
),
),
),
],
),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(
Icons.add,
),
onPressed: (){
getImage();
},
),
);
}
}