简体   繁体   中英

Is there a way in flutter to generate Widgets in a List without using Listview , Gridview?

What I want to do is to put my Widgets in the List to a Stack. Every widget in the list will return a container with different alignment.

Container( alignment: Alignment(xValue,yValue))

My stack is as Follows:

stack(
children: <Widget>[
SizedBox(
width :MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Container(
color:Colors.greenAccent,
child: ListView.builder(
           physics: const NeverScrollableScrollPhysics(),
           itemCount: widgetList.length,
           itemBuilder(BuildContext contet, int index){
                return widgetList[index]; })
))])

Here even though my containers appear in the Stack their positions are not the positions I wanted. Their alignment is done inside the listtile. What i want is to align those containers in the widgetlist inside the SizedBox.I could get it done as follows.

stack(
   children: <Widget>[
        SizedBox(
            width :MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: Container( color: Colors.greenAccent)),
        widgetList[0],
        widgetList[1], ])

This way even if could get the widgets in the list to be at the need location it is not dynamic. I need help to do this dynamically.

Use the spread operator

Stack(
   children: <Widget>[
        SizedBox(
            width :MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: Container( color: Colors.greenAccent)),
        ...widgetList,    // Note the three dots before the widgetList
])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM