0

When i click on camera icon in stack widget and also it is unable to update image it show this error ** [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value E/flutter (28471): #0 _profileState.geturl (package:ecommerce/Auth/profile.dart:25:59) E/flutter (28471): **

I want to update image but facing error please solve it...


Future image(BuildContext context) async{
  showModalBottomSheet(
    elevation: 5,
    enableDrag: true,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.only(
        topLeft: Radius.circular(20),
        topRight: Radius.circular(20),
      ),
    ),
    context: context,
    builder: (BuildContext context) {
      return Container(
        height: 200,
        child: Column(
          children: [
            ///Gallery
            ListTile(
              leading: Icon(Icons.browse_gallery),
              title: Text("Pick image from gallery"),
              onTap: () async{
                final gallery=await ImagePicker().pickImage(source: ImageSource.gallery);
if (gallery!=null) {
  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
    content: Text("Image Picked successfull",style: TextStyle(color: Colors.redAccent),
    ),duration: Duration(seconds: 5),
  ));
} else {
  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
    content: Text("Please pick image for further proccess",style: TextStyle(color: Colors.redAccent),
    ),duration: Duration(seconds: 5),
  ));
}
                Navigator.pop(context);
              },
            ),
           ///Camera
            ListTile(
              leading: Icon(Icons.camera_alt_outlined),
              title: Text("Pick Image from camera"),
              onTap: () async{
                final camera=await ImagePicker().pickImage(source: ImageSource.camera);
                if (camera!=null) {
                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                    content: Text("Image Capture successfull",style: TextStyle(color: Colors.redAccent),
                    ),duration: Duration(seconds: 5),
                  ));
                } else {
                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                    content: Text("Please Capture Image",style: TextStyle(color: Colors.redAccent),
                    ),duration: Duration(seconds: 5),
                  ));

                }
                Navigator.pop(context);
              },
            ),
      ///cancel
            ListTile(
              leading: Icon(Icons.cancel),
              title: Text("Cancel"),
              onTap: () {
                Navigator.pop(context);
              },
            ),
          ],
        ),
      );
    },
  );
}
Future geturl(context)async{
  final id=DateTime.now().toString();
  final reference=FirebaseFirestore.instance.collection("user3");
await image(context);
  final storage.Reference ref =
  storage.FirebaseStorage.instance.ref('/images'+id);
  final storage.UploadTask uploadTask = ref.putFile(_image!.absolute);
  await Future.value(uploadTask);
  final  downurl=await ref.getDownloadURL();
  print(FirebaseAuth.instance.currentUser!.uid);
  reference.doc(FirebaseAuth.instance.currentUser!.uid).update(
      {
        "imageurl":downurl.toString(),
      }
  ).then((value) {
    ScaffoldMessenger.of(context).showSnackBar(SnackBar(
      content: Text("Updated successfully",style: TextStyle(color: Colors.redAccent),
      ),duration: Duration(seconds: 5),
    ));
  }).catchError((e){
    ScaffoldMessenger.of(context).showSnackBar(SnackBar(
      content: Text("${e.message}",style: TextStyle(color: Colors.redAccent),
      ),duration: Duration(seconds: 5),
    ));
  });
}

 Stack(

                          alignment: Alignment.bottomRight,
                          children: [
                            CircleAvatar(
                              radius: 70,
                              backgroundImage:_image!=null?FileImage(_image!.absolute) : NetworkImage(snapshot.data!.docs[index]["imageurl"]) as ImageProvider,
                            ),
                             InkWell(
                                 onTap: (){
geturl(context);
                                 },
                                 child: Icon(Icons.add_a_photo,size: 30,)),
                          ],
                        ),

0 Answers0