0

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

user17838882
  • 93
  • 2
  • 14

2 Answers2

0

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

Tim Jacobs
  • 1,023
  • 1
  • 8
  • 14
  • where ? instead of positioned ? – user17838882 Mar 23 '22 at 08:36
  • Yes. Align takes an `alignment` property, which you assign a preset `alignment: Alignment.bottomCenter,` or specify exactly where you want it `alignment: Alignment(0.0, 0.0),`. To figure out exactly how these doubles work, check out the documentation: https://api.flutter.dev/flutter/painting/Alignment-class.html – Tim Jacobs Mar 23 '22 at 08:56
  • still dont move :( – user17838882 Mar 23 '22 at 09:09
0

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),
                         ),
                       ]
                   );
                  },
                 ),
                ),
              ),
    
        ])
benten
  • 696
  • 7
  • 18