Flutter - How to use container widget with image and text/icons below image

0

I am having a bit of a problem trying to create an image and text/icons below that image within a container in flutter. What I have so far , I want to include three row widgets under the image, each row will have a text widget or an icon widget but whenever i try to do this the container will just take the shape of the text/icon widgets and the image will disappear. Am I using the wrong widget in this case? I would like to have something similar to this notice the bottom section of the picture with the title, date, and location.

My code:

class EventRow extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 150.0,
      margin: const EdgeInsets.symmetric(
        vertical: 16.0,
        horizontal: 24.0,
      ),
      child: new Stack(
        children: <Widget>[
          eventCardContent,
          userThumbnail,
        ],
      ),
    );
  }

  final userThumbnail = new Container(
    margin: EdgeInsets.symmetric(vertical: 16.0),
    alignment: FractionalOffset.centerLeft,
    child: CircleAvatar(
      backgroundImage: AssetImage("assets/images/letter_u.png"),
      backgroundColor: Colors.white,
      maxRadius: 40.0,
    ),
  );

  final eventCardContent = new Container(
    margin: new EdgeInsets.only(left: 46.0),
    decoration: new BoxDecoration(
      shape: BoxShape.rectangle,
      color: new Color(0xFFFFFFFF),
      borderRadius: new BorderRadius.circular(8.0),
      image: DecorationImage(
        image: AssetImage("assets/images/moon_pumpkin.jpeg"),
        fit: BoxFit.fill,
      ),
    ),
  );
android-studio
user-interface
dart
widget
flutter
asked on Stack Overflow Oct 28, 2018 by theSimm • edited Oct 30, 2018 by theSimm

1 Answer

1

you nee d to just wrap your container of userThumbnail with Column and use property mainAxisSize: MainAxisSize.min, that solved your problem.

It tells column widget to take space whatever is required but not more than that. Any uncertainty in size won't work with mainAxisSize: MainAxisSize.min and can result in ui error of size undefined.

Following code may help you.

 @override
Widget build (BuildContext context) {
return Scaffold(
  appBar: new AppBar(
    title: new Text("Csd"),
  ),
  body: Column(
    children: <Widget>[
      Container(
        height: 150.0,
        margin: const EdgeInsets.symmetric(
          vertical: 16.0,
          horizontal: 24.0,
        ),
        child: new Stack(
          children: <Widget>[
            eventCardContent,
            userThumbnail,
          ],
        ),
      ),
      new Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              new Column(
                children: <Widget>[
                  Text("SEP"),
                  Text("30"),
                ],
              ),
              Expanded(
                 child:new Column(
                   children: <Widget>[
                     new Text("title"),
                     new Text("Sub title"),
                     new Text("Second Sub Title"),
                   ],
                 )
              )
            ],
          ),

        ],
      )
    ],
  ),
);
}
answered on Stack Overflow Oct 29, 2018 by Viren V Varasadiya • edited Oct 23, 2019 by vivek yadav

User contributions licensed under CC BY-SA 3.0