Home > database >  flutter : positioned not move in stack
flutter : positioned not move in stack

Time:03-23

I have a stack and I want to use listviewBuilder in it. and I use positioned in list view, but position not work and don't move, can anyone help me, please?

it's my list :

 List timeBookMark = [200.0, 500.0, 100.0, 90.0, 900.0, 500.0, 600.0];

and its my code in stack :

 Stack(
   children: [
    Positioned(
      child: SizedBox(
        width: pageWidth,
        height: 26,
        child: ListView.builder(
            physics: NeverScrollableScrollPhysics(),
            scrollDirection: Axis.horizontal,
            shrinkWrap: true,
            itemCount: 6,
            itemBuilder: (BuildContext context, int index) {
               return  (timeBookMark[index   1] -timeBookMark[index] < 100)
                 ? Positioned(
                    left: timeBookMark[index] / 1,
                     child: MyIcons(iconName: MyIcons.Vector,iconSize: 20),)
                 : Positioned(
                    left: timeBookMark[index] / 1,
                     child: MyIcons(iconName: MyIcons.bookMark, iconSize: 26),
                             );
                            },
                          ),
                        ),
                      ),



... //another widget
                          ])

I want to set position for each icon:

enter image description here

CodePudding user response:

When you're trying to align widgets that are not direct children of a Stack, use the Align widget instead.

CodePudding user response:

put positioned wiget in Stack

    Stack(
       children: [
        Positioned(
          child: SizedBox(
            width: pageWidth,
            height: 26,
            child: ListView.builder(
                physics: NeverScrollableScrollPhysics(),
                scrollDirection: Axis.horizontal,
                shrinkWrap: true,
                itemCount: 6,
                itemBuilder: (BuildContext context, int index) {
                   return 
                   Stack(
                  children: [
                    (timeBookMark[index   1] -timeBookMark[index] < 100)
                     ? Positioned(
                        left: timeBookMark[index] / 1,
                         child: MyIcons(iconName: MyIcons.Vector,iconSize: 20),)
                     : Positioned(
                        left: timeBookMark[index] / 1,
                         child: MyIcons(iconName: MyIcons.bookMark, iconSize: 26),
                         ),
                       ]
                   );
                  },
                 ),
                ),
              ),
    
        ])
  • Related