2

I want to create a Widget with the same layout as bellow.

+===================+ => A not fixed height widget
|  ---------------  |
| |               | |
| |               | | => Image()
|  ---------------  |
|  ~~~~~~~~~        | => Text()
|  ~~~~~~~~~~~~~    | => Text()
+===================+

How could I make the Image Widget small as its parent allows in Flutter? I also as much as possible if I have a big parent Widget, also.

1 Answer 1

1

Expanded inside the Column would do the trick you wanted. You can change height and width of the Container. Expanded flex will fill the percentage of the parent height.

import 'package:flutter/material.dart';

class Question5 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Container(
        color: Colors.grey.shade300,
        width: MediaQuery.of(context).size.width, //you can change width here
        height: MediaQuery.of(context).size.height, //you can change height here
        child: Column(
          children: <Widget>[
            Expanded(
              child: Image.network(
                'https://www.visioncritical.com/hubfs/Imported_Blog_Media/BLG_Andrew-G_-River-Sample_09_13_12.png',
                fit: BoxFit.cover,
              ),
            ),
            Text(
              'Some title here',
              style: TextStyle(
                fontSize: 25.0,
              ),
            ),
            Text(
              'Some subtitle here',
              style: TextStyle(
                fontSize: 15.0,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for your answer. I tested your solution but according my last exposition. Your solution will let the write space below the second Text.
@TrầnĐứcTâm Try out changes I made in the answer
@TrầnĐứcTâm Accept the answer once your issue is solved. thanks
Thank @pskink for your suggest. I tested my solution and got that over engineered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.