【问题标题】:can't load the image using the filepicker in flutter无法使用颤振中的文件选择器加载图像
【发布时间】:2022-01-14 01:54:11
【问题描述】:

最终的 PlatformFile 图像; 最终双倍尺寸;

装饰:BoxDecoration( 图片:装饰图片( 适合:BoxFit.cover, 图片:AssetImage(image.path!), ),

【问题讨论】:

    标签: flutter


    【解决方案1】:

    您需要使用 FileImage 而不是 AssetImage

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

    【讨论】:

    • @hassan yassin 如果您的图片使用此代码加载,请做出正确的回答。
    • 感谢兄弟,已解决
    【解决方案2】:

    如果您尝试从本地路径获取,请使用 FileImage 而不是 AssetImage

    【讨论】:

    • 谢谢解决!!
    【解决方案3】:
     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,),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                      ),)
                                  ],
                                )
    

    【讨论】:

      猜你喜欢
      • 2021-05-12
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 2020-01-22
      • 1970-01-01
      • 2021-01-30
      • 2021-12-22
      • 1970-01-01
      相关资源
      最近更新 更多