ExpansionPanelList In Flutter

ExpansionPanelList In Flutter :

Screenshot :

ExpansionPanelList In Flutter

ExpansionPanelList.dart

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'ExpansionTile',
      theme: ThemeData.dark(),
      home: ExpansionPanelListDemo(),
    );
  }
}

class ExpansionPanelListDemo extends StatefulWidget {
  @override
  _ExpansionPanelListDemoState createState() => _ExpansionPanelListDemoState();
}

class _ExpansionPanelListDemoState extends State<ExpansionPanelListDemo> {
  List<int> mList;

  List<ExpansionStateBean> expansionStateList;

  _ExpansionPanelListDemoState() {
    mList = new List();
    expansionStateList = new List();
    for (var i = 0; i < 10; i++) {
      mList.add(i);
      expansionStateList.add(ExpansionStateBean(i, false));
    }
  }

  _setCurrentIndex(int index, isExpand) {
    setState(() {
      expansionStateList.forEach((item) {
        if (item.index == index) {
          item.isOpen = !isExpand;
        }
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('ExpansionPanelList'),
        ),
        body: SingleChildScrollView(
            child: ExpansionPanelList(
          expansionCallback: (index, bol) {
            _setCurrentIndex(index, bol);
          },
          children: mList.map((index) {
            return ExpansionPanel(
              headerBuilder: (context, isExpanded) {
                return ListTile(
                  title: Text('This is NO.$index'),
                );
              },
              body: ListTile(
                title: Text('expansionPanel NO.$index'),
              ),
              isExpanded: expansionStateList[index].isOpen,
            );
          }).toList(),
        )));
  }
}

class ExpansionStateBean {
  var index;
  var isOpen;
  ExpansionStateBean(this.index, this.isOpen);
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in