K
K
KMks2021-12-23 12:51:54
Dart
KMks, 2021-12-23 12:51:54

Flutter (Dynamic Blocks) show/hide. How to split the disclosure blocks?

Please help me with point 1.
I have a list of objects displayed dynamically. Each of them has a button, when clicked, a block inside each element should open.
It looks like this:
61c4459de869b610251360.png
61c445b9f38f3909423604.png

At the moment, the following is implemented. way:

Visibility(
                                              visible:_visible,
                                              child: Container(
                                                child: Column(
                                                  children: [
                                                    Html(
                                                      data: ('<ul><li>ТЕКСТ</li><li>ТЕКСТ</li></ul>'),
                                                      style: {
                                                        'ul':Style(

                                                        ),
                                                        'li':Style(

                                                          color:  Colors.black,
                                                        )
                                                      },
                                                    ),
                                                  ],
                                                ),
                                              ),


                                            )


Implemented the method on button click:
void _toggle() {
    setState(() {
      _visible = !_visible;
    });
  }


But now the disclosure occurs for all elements and, accordingly, the closure.
Tell me how to implement separate opening and closing of blocks.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KMks, 2021-12-24
@KMks

Resolved the issue.
Perhaps someone will come in handy.

void showHide(int i){
    setState((){
      showQty[i]=!showQty[i];
    });
  }

Visibility(
                      visible:showQty[position],
                      child: Container(
                        child: Column(
                          children: [
                            Html(
                              data: ('${article[position].description}'),
                              style: {
                                'ul':Style(

                                ),
                                'li':Style(

                                  color:  Colors.black,
                                )
                              },
                            ),
                          ],
                        ),
                      ),


                    ),

And be sure to declare:
List showQty=[];
And further:
@override
  void initState() {
    for(int i=0;i<10;i++){
      showQty.add(false);
    }

    super.initState();

  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question