Привет, ребята, я флаттер и дартс новичок
Я делаю функцию загрузки фото
Но у меня возникли проблемы, когда я делал это.
class pictureBox () canне распознаю getImage () ,,
Весь мой код:
class writeprofile extends StatefulWidget {
@override
_writeprofileState createState() => _writeprofileState();
}
class _writeprofileState extends State<writeprofile> {
File _image;
@override
Widget build(BuildContext context) {
Future getImage() async{
var image= await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
print('Image Path $_image');
});
}
Future uploadPic(BuildContext context) async{
String filName = basename(_image.path);
StorageReference firebaseStorageRef = FirebaseStorage.instance.ref().child(filName);
StorageUploadTask uploadTask = firebaseStorageRef.putFile(_image);
StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
setState(() {
print("Profile pic upload !!");
Scaffold.of(context).showSnackBar(SnackBar(content: Text('Profile pic Upload !!')));
});
}
return Scaffold(
body: Builder(
builder: (context)=> Center(
child: Container(
child: Container(
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 70),
child: Text(
'사진 선택',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.w500,
),
),
),
Padding(
padding: EdgeInsets.only(top: 10, bottom: 50),
child: Container(
height: 1,
width: MediaQuery.of(context).size.width / 1.4,
color: Colors.black26,
),
),
Container(
width: MediaQuery.of(context).size.width / 1.5,
height: MediaQuery.of(context).size.height / 15,
alignment: FractionalOffset.center,
decoration: BoxDecoration(
color: const Color.fromRGBO(250, 80, 120, 1),
borderRadius: BorderRadius.all(const Radius.circular(30)),
),
child: Text(
"가이드 라인을 읽어주세요 !",
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w300,
letterSpacing: 0.3,
),
),
),
Padding(
padding: const EdgeInsets.only(top: 100),
child: Row(
children: <Widget>[
PictureBox(),
PictureBox(),
PictureBox(),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: Row(
children: <Widget>[
PictureBox(),
PictureBox(),
PictureBox(),
],
),
),
InkWell(
onTap: (){uploadPic(context);},
child: Padding(
padding: EdgeInsets.only(top: 50),
child: Container(
width: MediaQuery.of(context).size.width / 3,
height: MediaQuery.of(context).size.height /20,
alignment: FractionalOffset.center,
decoration: BoxDecoration(
color: const Color.fromRGBO(250, 80, 100, 1),
borderRadius: BorderRadius.all(const Radius.circular(30)),
),
child: Text(
"Next",
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w500,
letterSpacing: 0.3,
),
),
),
),
),
],
),
),
),
),
),
);
}
}
class PictureBox extends StatefulWidget {
@override
_PictureBoxState createState() => _PictureBoxState();
}
class _PictureBoxState extends State<PictureBox>{
@override
Widget build(BuildContext context) {
return Container(
child: InkWell(
onTap: (){getImage(context);},
child: Padding(
padding: EdgeInsets.only(left: 10),
child:Container(
width: MediaQuery.of(context).size.width / 3.3,
height: MediaQuery.of(context).size.height / 7,
color: Colors.black12,
child: Center(
child: (_image!=null)? Image.file(_image, fit:BoxFit.fill)
:Icon(
Icons.camera_alt,
color: Colors.black26,
),
),
),
),
),
);
}
}
Это мой код, я хочу использовать 'Future getImage ()' в PictureBox Как запустить getImage () в PictureBox?
Кроме того, как решить ошибку 'неопределенное имя' _image '' в PictureBox?