skip to Main Content

I don’t know why I set in my container or Image.file the height and width with a BoxFit.fill and it’s not working

     Stack(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: [
              [...]

              Padding(
                padding: ...,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min,
                  children: [
                      [...]
                      Container(
                        height: 150,
                        width: MediaQuery.of(context).size.width,
                        color: Colors.red,
                        child: Image.file(
                          File(...),
                          fit: BoxFit.fill,
                        ),
                      )
                  ],
                ),
              ),
            ],
          ),

          [...]
        ],
      ),

enter image description here

2

Answers


  1. You can try this code

        Container(
    height : 200.0,
    width : 200.0,
    decoration: const BoxDecoration(
                image: DecorationImage(
              image: AssetImage(
                'assets/images/bg.png',
              ),
              fit: BoxFit.cover,
            ),
    color:Colors.red,),
    child: Text("Hello World"),
    ),
    

    I hope this can work for you.

    Login or Signup to reply.
  2. Do you want to keep the image inside the Red container?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search