Skip to content

initiallyOpenedControllersIndexes does not work properly #17

@chirastefan

Description

@chirastefan

Map<String, ExpandedTileController> tilesControllers = {};

class MyWidget extends StatefulWidget {


  const MyWidget({
    super.key,
    this.expandedAll = false,
  });

  @override
  _MyWidgetState createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  List<String> myList = [ 'orange', 'apple', 'lemon'];

  @override
  Widget build(BuildContext context) {

   return ExpandedTileList.builder(
         itemCount: myList.length,
         initiallyOpenedControllersIndexes: widget.expandedAll ? [0, 1, 2, 3, 4, 5] : [],
         itemBuilder: (expContext, expIndex, expCon) {
            if (!tilesControllers.containsKey('$expIndex-${myList[expIndex]}')) {
              tilesControllers['$expIndex-${myList[expIndex]}'] = expCon;
            }
          });
   }
);

if I call the controllers from another widget like this

for (final controller in tilesControllers.values) {
      controller.toggle();
}

initiallyOpenedControllersIndexes does not work properly.
If expandedAll is true, meaning all the indexes are in the array, only 2 controllers are set in the tilesControllers map, and calling them from a loop does not collapse all of them, only the ones with an assigned controller, of course.
On the other hand, if expandedAll is false, meaning the array is empty, or if I remove initiallyOpenedControllersIndexes entirely, all the controllers are set, and if I call toggle them from a loop they work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions