How to constrain widget with a listview to the size of their children?The equivalent of wrap_content and match_parent in flutter?Flutter column auto height by parent rowFlutter : Can I add a Header Row to a ListViewHow to pass multiple widgets as children in Flutter?How to Read the size of a Widget in the Layout Phase and Use the size for another widget in the Build Phase Before drawFrame()How to use the sizes of other widgets before the widget tree is drawn ? [with Example]How to offset a scaffold widget in Flutter?Flutter : Bad state: Stream has already been listened toExpanded() widget not working in listviewFlutter Widget Composition - Nested ListviewFlutter: Is the Column widget constrained or unconstrained vertically?hello ,,,,,when I am clicking on card then show me this error how to fix this error

How does Ctrl+c and Ctrl+v work?

Will there be more tax deductions if I put the house completely under my name, versus doing a joint ownership?

How would you translate "grit" (personality trait) to Chinese?

How to continually let my readers know what time it is in my story, in an organic way?

What color to choose as "danger" if the main color of my app is red

Were any of the books mentioned in this scene from the movie Hackers real?

Assembly writer vs compiler

Do high-wing aircraft represent more difficult engineering challenges than low-wing aircraft?

enumitem: Understanding the usage of asterisk and exclamation mark in setting the different lengths

Why would company (decision makers) wait for someone to retire, rather than lay them off, when their role is no longer needed?

How to rename multiple files in a directory at the same time

How could it be that 80% of townspeople were farmers during the Edo period in Japan?

Was the dragon prowess intentionally downplayed in S08E04?

Why did the metro bus stop at each railway crossing, despite no warning indicating a train was coming?

Slice a list based on an index and items behind it in python

What is the effect of the Feeblemind spell on Ability Score Improvements?

c++ conditional uni-directional iterator

What is the status of the Lannisters after Season 8 Episode 5, "The Bells"?

Were any toxic metals used in the International Space Station?

Formal Definition of Dot Product

Will the volt, ampere, ohm or other electrical units change on May 20th, 2019?

Why can't I share a one use code with anyone else?

Is random forest for regression a 'true' regression?

Which creature is depicted in this Xanathar's Guide illustration of a war mage?



How to constrain widget with a listview to the size of their children?


The equivalent of wrap_content and match_parent in flutter?Flutter column auto height by parent rowFlutter : Can I add a Header Row to a ListViewHow to pass multiple widgets as children in Flutter?How to Read the size of a Widget in the Layout Phase and Use the size for another widget in the Build Phase Before drawFrame()How to use the sizes of other widgets before the widget tree is drawn ? [with Example]How to offset a scaffold widget in Flutter?Flutter : Bad state: Stream has already been listened toExpanded() widget not working in listviewFlutter Widget Composition - Nested ListviewFlutter: Is the Column widget constrained or unconstrained vertically?hello ,,,,,when I am clicking on card then show me this error how to fix this error






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have this SectorWidget that I meant it to be something decoupled.



I will pass to it a list of views (of the same height) but I wouldn't like to specify the height hardcoded inside ListView nor outside. I would like it to occupy the same height of widgets, something like wrap_content in Android. But I tried a lot of ways (like this or this) after search and cannot achieve this. Is there a way to do that in my specific case?



import 'package:flixapp/colors.dart';
import 'package:flutter/material.dart';

class SectorWidget extends StatelessWidget
final SectorViewModel viewModel;

SectorWidget(this.viewModel);

@override
Widget build(BuildContext context)
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
child: Material(
color: Colors.transparent,
child: InkWell(
splashColor: kSplashColor,
onTap: () ,
child: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Text(
viewModel.title,
style: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.black54,
fontSize: 30),
),
),
),
),
),
decoration: BoxDecoration(
color: viewModel.titleBackgroundColor ?? Colors.amber),
),
Container(
color: Colors.red,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: viewModel.data?.length ?? 0,
itemBuilder: (BuildContext context, int index)
var data = viewModel.data;
if (data.isNotEmpty) return viewModel.data[index];
,
),
)
],
);



class SectorViewModel
String title;
Color titleBackgroundColor;
List<Widget> data;

SectorViewModel(this.title, this.titleBackgroundColor, this.data);










share|improve this question






























    0















    I have this SectorWidget that I meant it to be something decoupled.



    I will pass to it a list of views (of the same height) but I wouldn't like to specify the height hardcoded inside ListView nor outside. I would like it to occupy the same height of widgets, something like wrap_content in Android. But I tried a lot of ways (like this or this) after search and cannot achieve this. Is there a way to do that in my specific case?



    import 'package:flixapp/colors.dart';
    import 'package:flutter/material.dart';

    class SectorWidget extends StatelessWidget
    final SectorViewModel viewModel;

    SectorWidget(this.viewModel);

    @override
    Widget build(BuildContext context)
    return Column(
    mainAxisAlignment: MainAxisAlignment.start,
    crossAxisAlignment: CrossAxisAlignment.start,
    children: <Widget>[
    Container(
    width: MediaQuery.of(context).size.width,
    child: Material(
    color: Colors.transparent,
    child: InkWell(
    splashColor: kSplashColor,
    onTap: () ,
    child: Align(
    alignment: Alignment.centerLeft,
    child: Padding(
    padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
    child: Text(
    viewModel.title,
    style: TextStyle(
    fontWeight: FontWeight.w600,
    color: Colors.black54,
    fontSize: 30),
    ),
    ),
    ),
    ),
    ),
    decoration: BoxDecoration(
    color: viewModel.titleBackgroundColor ?? Colors.amber),
    ),
    Container(
    color: Colors.red,
    child: ListView.builder(
    shrinkWrap: true,
    scrollDirection: Axis.horizontal,
    itemCount: viewModel.data?.length ?? 0,
    itemBuilder: (BuildContext context, int index)
    var data = viewModel.data;
    if (data.isNotEmpty) return viewModel.data[index];
    ,
    ),
    )
    ],
    );



    class SectorViewModel
    String title;
    Color titleBackgroundColor;
    List<Widget> data;

    SectorViewModel(this.title, this.titleBackgroundColor, this.data);










    share|improve this question


























      0












      0








      0








      I have this SectorWidget that I meant it to be something decoupled.



      I will pass to it a list of views (of the same height) but I wouldn't like to specify the height hardcoded inside ListView nor outside. I would like it to occupy the same height of widgets, something like wrap_content in Android. But I tried a lot of ways (like this or this) after search and cannot achieve this. Is there a way to do that in my specific case?



      import 'package:flixapp/colors.dart';
      import 'package:flutter/material.dart';

      class SectorWidget extends StatelessWidget
      final SectorViewModel viewModel;

      SectorWidget(this.viewModel);

      @override
      Widget build(BuildContext context)
      return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
      Container(
      width: MediaQuery.of(context).size.width,
      child: Material(
      color: Colors.transparent,
      child: InkWell(
      splashColor: kSplashColor,
      onTap: () ,
      child: Align(
      alignment: Alignment.centerLeft,
      child: Padding(
      padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      child: Text(
      viewModel.title,
      style: TextStyle(
      fontWeight: FontWeight.w600,
      color: Colors.black54,
      fontSize: 30),
      ),
      ),
      ),
      ),
      ),
      decoration: BoxDecoration(
      color: viewModel.titleBackgroundColor ?? Colors.amber),
      ),
      Container(
      color: Colors.red,
      child: ListView.builder(
      shrinkWrap: true,
      scrollDirection: Axis.horizontal,
      itemCount: viewModel.data?.length ?? 0,
      itemBuilder: (BuildContext context, int index)
      var data = viewModel.data;
      if (data.isNotEmpty) return viewModel.data[index];
      ,
      ),
      )
      ],
      );



      class SectorViewModel
      String title;
      Color titleBackgroundColor;
      List<Widget> data;

      SectorViewModel(this.title, this.titleBackgroundColor, this.data);










      share|improve this question
















      I have this SectorWidget that I meant it to be something decoupled.



      I will pass to it a list of views (of the same height) but I wouldn't like to specify the height hardcoded inside ListView nor outside. I would like it to occupy the same height of widgets, something like wrap_content in Android. But I tried a lot of ways (like this or this) after search and cannot achieve this. Is there a way to do that in my specific case?



      import 'package:flixapp/colors.dart';
      import 'package:flutter/material.dart';

      class SectorWidget extends StatelessWidget
      final SectorViewModel viewModel;

      SectorWidget(this.viewModel);

      @override
      Widget build(BuildContext context)
      return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
      Container(
      width: MediaQuery.of(context).size.width,
      child: Material(
      color: Colors.transparent,
      child: InkWell(
      splashColor: kSplashColor,
      onTap: () ,
      child: Align(
      alignment: Alignment.centerLeft,
      child: Padding(
      padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      child: Text(
      viewModel.title,
      style: TextStyle(
      fontWeight: FontWeight.w600,
      color: Colors.black54,
      fontSize: 30),
      ),
      ),
      ),
      ),
      ),
      decoration: BoxDecoration(
      color: viewModel.titleBackgroundColor ?? Colors.amber),
      ),
      Container(
      color: Colors.red,
      child: ListView.builder(
      shrinkWrap: true,
      scrollDirection: Axis.horizontal,
      itemCount: viewModel.data?.length ?? 0,
      itemBuilder: (BuildContext context, int index)
      var data = viewModel.data;
      if (data.isNotEmpty) return viewModel.data[index];
      ,
      ),
      )
      ],
      );



      class SectorViewModel
      String title;
      Color titleBackgroundColor;
      List<Widget> data;

      SectorViewModel(this.title, this.titleBackgroundColor, this.data);







      flutter flutter-layout






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 15:24









      Mazin Ibrahim

      1,6972817




      1,6972817










      asked Mar 23 at 15:18









      alexpfxalexpfx

      1,94642245




      1,94642245






















          1 Answer
          1






          active

          oldest

          votes


















          0














          When I understand you correctly, you want the root Column widget to match the size of it's children. For this, simply pass in mainAxisSize: MainAxisSize.min (the default is MainAxisSize.max - which I find a bit annoying as well, but anyway.)



          also: There is no need for width: MediaQuery.of(context).size.width, in the child Container.. just tell the parent Column() to stretch it's children cross axis: crossAxisAlignment: CrossAxisAlignment.stretch.






          share|improve this answer























          • It doesn't work. I have to set the height of the container that wraps listview. The column fit the same size of this container, but I need that this container have the same size of its listview shields, because i don't know the size of the childrens of this listview.

            – alexpfx
            Mar 24 at 20:31











          • okay i think I finally understood what you are asking.. but i'm still not sure how it should work.. you are lazily creating children in the ListView.. how is the ListView supposed to know the height of children that aren't even created yet?

            – herbert
            Mar 24 at 20:54











          • yes, maybe it couldn't be possible. but, if I set the height of the listview (via container), is there a way to make each item to fit exactly in a cell of the listview, keeping the aspect ratio?

            – alexpfx
            Mar 24 at 21:00











          • take a look at the AspectRatio widget docs.flutter.io/flutter/widgets/AspectRatio-class.html .. if this doesn't solve your problem, maybe provide some more details.

            – herbert
            Mar 24 at 21:10











          • I already tried with aspect ratio, but I could not make it work the way I want it to.

            – alexpfx
            Mar 24 at 21:11











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315230%2fhow-to-constrain-widget-with-a-listview-to-the-size-of-their-children%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          When I understand you correctly, you want the root Column widget to match the size of it's children. For this, simply pass in mainAxisSize: MainAxisSize.min (the default is MainAxisSize.max - which I find a bit annoying as well, but anyway.)



          also: There is no need for width: MediaQuery.of(context).size.width, in the child Container.. just tell the parent Column() to stretch it's children cross axis: crossAxisAlignment: CrossAxisAlignment.stretch.






          share|improve this answer























          • It doesn't work. I have to set the height of the container that wraps listview. The column fit the same size of this container, but I need that this container have the same size of its listview shields, because i don't know the size of the childrens of this listview.

            – alexpfx
            Mar 24 at 20:31











          • okay i think I finally understood what you are asking.. but i'm still not sure how it should work.. you are lazily creating children in the ListView.. how is the ListView supposed to know the height of children that aren't even created yet?

            – herbert
            Mar 24 at 20:54











          • yes, maybe it couldn't be possible. but, if I set the height of the listview (via container), is there a way to make each item to fit exactly in a cell of the listview, keeping the aspect ratio?

            – alexpfx
            Mar 24 at 21:00











          • take a look at the AspectRatio widget docs.flutter.io/flutter/widgets/AspectRatio-class.html .. if this doesn't solve your problem, maybe provide some more details.

            – herbert
            Mar 24 at 21:10











          • I already tried with aspect ratio, but I could not make it work the way I want it to.

            – alexpfx
            Mar 24 at 21:11















          0














          When I understand you correctly, you want the root Column widget to match the size of it's children. For this, simply pass in mainAxisSize: MainAxisSize.min (the default is MainAxisSize.max - which I find a bit annoying as well, but anyway.)



          also: There is no need for width: MediaQuery.of(context).size.width, in the child Container.. just tell the parent Column() to stretch it's children cross axis: crossAxisAlignment: CrossAxisAlignment.stretch.






          share|improve this answer























          • It doesn't work. I have to set the height of the container that wraps listview. The column fit the same size of this container, but I need that this container have the same size of its listview shields, because i don't know the size of the childrens of this listview.

            – alexpfx
            Mar 24 at 20:31











          • okay i think I finally understood what you are asking.. but i'm still not sure how it should work.. you are lazily creating children in the ListView.. how is the ListView supposed to know the height of children that aren't even created yet?

            – herbert
            Mar 24 at 20:54











          • yes, maybe it couldn't be possible. but, if I set the height of the listview (via container), is there a way to make each item to fit exactly in a cell of the listview, keeping the aspect ratio?

            – alexpfx
            Mar 24 at 21:00











          • take a look at the AspectRatio widget docs.flutter.io/flutter/widgets/AspectRatio-class.html .. if this doesn't solve your problem, maybe provide some more details.

            – herbert
            Mar 24 at 21:10











          • I already tried with aspect ratio, but I could not make it work the way I want it to.

            – alexpfx
            Mar 24 at 21:11













          0












          0








          0







          When I understand you correctly, you want the root Column widget to match the size of it's children. For this, simply pass in mainAxisSize: MainAxisSize.min (the default is MainAxisSize.max - which I find a bit annoying as well, but anyway.)



          also: There is no need for width: MediaQuery.of(context).size.width, in the child Container.. just tell the parent Column() to stretch it's children cross axis: crossAxisAlignment: CrossAxisAlignment.stretch.






          share|improve this answer













          When I understand you correctly, you want the root Column widget to match the size of it's children. For this, simply pass in mainAxisSize: MainAxisSize.min (the default is MainAxisSize.max - which I find a bit annoying as well, but anyway.)



          also: There is no need for width: MediaQuery.of(context).size.width, in the child Container.. just tell the parent Column() to stretch it's children cross axis: crossAxisAlignment: CrossAxisAlignment.stretch.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 24 at 19:07









          herbertherbert

          1,05011425




          1,05011425












          • It doesn't work. I have to set the height of the container that wraps listview. The column fit the same size of this container, but I need that this container have the same size of its listview shields, because i don't know the size of the childrens of this listview.

            – alexpfx
            Mar 24 at 20:31











          • okay i think I finally understood what you are asking.. but i'm still not sure how it should work.. you are lazily creating children in the ListView.. how is the ListView supposed to know the height of children that aren't even created yet?

            – herbert
            Mar 24 at 20:54











          • yes, maybe it couldn't be possible. but, if I set the height of the listview (via container), is there a way to make each item to fit exactly in a cell of the listview, keeping the aspect ratio?

            – alexpfx
            Mar 24 at 21:00











          • take a look at the AspectRatio widget docs.flutter.io/flutter/widgets/AspectRatio-class.html .. if this doesn't solve your problem, maybe provide some more details.

            – herbert
            Mar 24 at 21:10











          • I already tried with aspect ratio, but I could not make it work the way I want it to.

            – alexpfx
            Mar 24 at 21:11

















          • It doesn't work. I have to set the height of the container that wraps listview. The column fit the same size of this container, but I need that this container have the same size of its listview shields, because i don't know the size of the childrens of this listview.

            – alexpfx
            Mar 24 at 20:31











          • okay i think I finally understood what you are asking.. but i'm still not sure how it should work.. you are lazily creating children in the ListView.. how is the ListView supposed to know the height of children that aren't even created yet?

            – herbert
            Mar 24 at 20:54











          • yes, maybe it couldn't be possible. but, if I set the height of the listview (via container), is there a way to make each item to fit exactly in a cell of the listview, keeping the aspect ratio?

            – alexpfx
            Mar 24 at 21:00











          • take a look at the AspectRatio widget docs.flutter.io/flutter/widgets/AspectRatio-class.html .. if this doesn't solve your problem, maybe provide some more details.

            – herbert
            Mar 24 at 21:10











          • I already tried with aspect ratio, but I could not make it work the way I want it to.

            – alexpfx
            Mar 24 at 21:11
















          It doesn't work. I have to set the height of the container that wraps listview. The column fit the same size of this container, but I need that this container have the same size of its listview shields, because i don't know the size of the childrens of this listview.

          – alexpfx
          Mar 24 at 20:31





          It doesn't work. I have to set the height of the container that wraps listview. The column fit the same size of this container, but I need that this container have the same size of its listview shields, because i don't know the size of the childrens of this listview.

          – alexpfx
          Mar 24 at 20:31













          okay i think I finally understood what you are asking.. but i'm still not sure how it should work.. you are lazily creating children in the ListView.. how is the ListView supposed to know the height of children that aren't even created yet?

          – herbert
          Mar 24 at 20:54





          okay i think I finally understood what you are asking.. but i'm still not sure how it should work.. you are lazily creating children in the ListView.. how is the ListView supposed to know the height of children that aren't even created yet?

          – herbert
          Mar 24 at 20:54













          yes, maybe it couldn't be possible. but, if I set the height of the listview (via container), is there a way to make each item to fit exactly in a cell of the listview, keeping the aspect ratio?

          – alexpfx
          Mar 24 at 21:00





          yes, maybe it couldn't be possible. but, if I set the height of the listview (via container), is there a way to make each item to fit exactly in a cell of the listview, keeping the aspect ratio?

          – alexpfx
          Mar 24 at 21:00













          take a look at the AspectRatio widget docs.flutter.io/flutter/widgets/AspectRatio-class.html .. if this doesn't solve your problem, maybe provide some more details.

          – herbert
          Mar 24 at 21:10





          take a look at the AspectRatio widget docs.flutter.io/flutter/widgets/AspectRatio-class.html .. if this doesn't solve your problem, maybe provide some more details.

          – herbert
          Mar 24 at 21:10













          I already tried with aspect ratio, but I could not make it work the way I want it to.

          – alexpfx
          Mar 24 at 21:11





          I already tried with aspect ratio, but I could not make it work the way I want it to.

          – alexpfx
          Mar 24 at 21:11



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315230%2fhow-to-constrain-widget-with-a-listview-to-the-size-of-their-children%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현