0

i have to use index in position , but when I use listView.builder for I , I got this error :

Incorrect use of ParentDataWidget.

The ParentDataWidget Positioned(left: 157.2) wants to apply ParentData of type StackParentData to a RenderObject, which has been set up to accept ParentData of incompatible type FlexParentData.

Usually, this means that the Positioned widget has the wrong ancestor RenderObjectWidget. Typically, Positioned widgets are placed directly inside Stack widgets. The offending Positioned is currently placed inside a Row widget.

and app crashed.

i use stack -> listview.bulder(for index) -> position

but correct is stack -> position

I have to use index in position. so can anyone help me how can I do that ?

for example myList are :

myList = [{"data" : 100.0},{"data" : 200.0 },{"data" : 300.0 }, {"data" :400.0 },{"data" : 500.0} ]

here is my code :

Stack(
                  alignment: AlignmentDirectional.topStart,
                  children: [
                    Positioned(
                          left: (myList[index]["data"]),
                          child: Directionality(
                            textDirection: TextDirection.ltr,
                            child: MySimpleIcons(
                              iconName: MyIcons.bookProfile,
                              iconColor: theme.darkGrey,
                              iconSize: 24,
                            ),
                          ),
                 // another widgets
                 ) ],
2
  • Where is this ListView added in your code? in the stack or outside? Commented Jun 22, 2022 at 8:37
  • out , i need it for left Commented Jun 22, 2022 at 8:43

1 Answer 1

0

You can use .map & spread operator to fulfill this case. You can try the following code:

Stack(
      alignment: AlignmentDirectional.topStart,
      children: [
        ...myList.map((position) => Positioned(
                  left: position,
                  child: Directionality(
                    textDirection: TextDirection.ltr,
                    child: MySimpleIcons(
                      iconName: MyIcons.bookProfile,
                      iconColor: theme.darkGrey,
                      iconSize: 24,
                    ),
                  ),
                )
            // another widgets
            )
      ],
    );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.