hassan yassin
hassan yassin

Reputation: 11

can't load the image using the filepicker in flutter

final PlatformFile image; final double size;

decoration: BoxDecoration( image: DecorationImage( fit: BoxFit.cover, image: AssetImage(image.path!), ),

Upvotes: 0

Views: 114

Answers (3)

Vishal_VE
Vishal_VE

Reputation: 2127

 You can also do one thing check the _image value if it null shows image through your assets if not then you call it through FileImage(_image!)

//////code   
File ?_image;
       
     _image==null?Stack(
                              children: [
                                Container(
                                  height: 150,
                                  width:_width,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Container(
                                        height: 120,
                                        width: 120,
                                        decoration: BoxDecoration(
                                            color: Colors.white,
                                            borderRadius: BorderRadius.circular(60),
                                            border: Border.all(color: AppColors.white, width: 2.0),
                                            image: DecorationImage(
                                              image: AssetImage("assets/managerPicture.jpeg"),fit: BoxFit.cover,
                                            )
                                          /*gradient: LinearGradient(
                                  begin: Alignment.topRight,
                                  end: Alignment.bottomLeft,
                                  colors: [
                                    Color(0xff00519E),
                                    AppColors.blue,
                                    Colors.blue.shade900,
                                  ],
                                )*/
                                        ),
                                        /* child: ClipRRect(
                                borderRadius: BorderRadius.circular(60.0),
                                child: Image.asset("assets/manager.jpeg",height: 100,width: 100,)
                              //Icon(Icons.person, size: 100),
                              // child: Image.asset("assets/logo/profile.png", fit: BoxFit.fill),
                            ),*/
                                      ),
                                    ],
                                  ),
                                ),
                                Positioned(
                                  top: 60,
                                  right: 0,
                                  left: 100,
                                  bottom: 0,
                                  child: GestureDetector(
                                    onTap: (){
                                      _showChoiceDialog(context);
                                    },
                                    child: Container(
                                      height: 10,
                                      width: _width,
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.center,
                                        children: [
                                          Container(
                                            height: 35,
                                            width: 35,
                                            decoration: BoxDecoration(
                                              color: AppColors.profiePicBackground,
                                              borderRadius: BorderRadius.circular(60),
        
                                              //border: Border.all(color: Colors.blue.shade900, width: 2.0),
                                            ),
                                            child: ClipRRect(
                                              borderRadius: BorderRadius.circular(60.0),
                                              child: Icon(MdiIcons.squareEditOutline,color: AppColors.popUpBlueColor,size: 20,),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),)
                              ],
                            ):Stack(
                              children: [
                                Container(
                                  height: 150,
                                  width:_width,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Container(
                                        height: 120,
                                        width: 120,
                                        decoration: BoxDecoration(
                                          color: Colors.white,
                                          shape: BoxShape.circle,
                                          image: DecorationImage(
                                            fit: BoxFit.fill,
                                            image:  FileImage(_image!),
                                          ),
                                          border: Border.all(color: AppColors.white, width: 2.0),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                Positioned(
                                  top: 60,
                                  right: 0,
                                  left: 100,
                                  bottom: 0,
                                  child: GestureDetector(
                                    onTap: (){
                                      _showChoiceDialog(context);
                                    },
                                    child: Container(
                                      height: 10,
                                      width: _width,
                                      child: Row(
                                        mainAxisAlignment: MainAxisAlignment.center,
                                        children: [
                                          Container(
                                            height: 35,
                                            width: 35,
                                            decoration: BoxDecoration(
                                              color: AppColors.profiePicBackground,
                                              borderRadius: BorderRadius.circular(60),
        
                                              //border: Border.all(color: Colors.blue.shade900, width: 2.0),
                                            ),
                                            child: ClipRRect(
                                              borderRadius: BorderRadius.circular(60.0),
                                              child: Icon(MdiIcons.squareEditOutline,color: AppColors.popUpBlueColor,size: 20,),
                                            ),
                                          ),
                                        ],
                                      ),
                                    ),
                                  ),)
                              ],
                            )

Upvotes: 0

Pranav
Pranav

Reputation: 336

Use FileImage instead of AssetImage if you are trying to take from local path.

Upvotes: 1

Dipak Prajapati
Dipak Prajapati

Reputation: 154

you need to used FileImage instead of AssetImage

            decoration: new BoxDecoration(
                color: Colors.transparent,
                image: new DecorationImage(
                  image: new FileImage(File(image.path)),
                  fit: BoxFit.cover,
                ),
        
              ),

Upvotes: 2

Related Questions