ExpansionList In Flutter

ExpansionList In Flutter

hello friends today i will going to show you how to create expansionlist in flutter

flutter provides ExpansionTile widget which is use to create the expansionlist in flutter

Properties :

backgroundColor : used to set the background color of the widget

initiallyExpanded : if it is true then child will expand default

OnExpansionChanged : this property used to handle the expansion event

children : the children property used for the add child widget

title : used to set the title of the header

here i will give you the small example of how to create ExpansionList in flutter

Screenshot :

ExpansionList In Flutter

Program :

import 'package:flutter/material.dart';

void main() => runApp(
      new MaterialApp(
        home: new MyApp(),
        debugShowCheckedModeBanner: false,
      ),
    );

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new ListView.builder(
        itemCount: educationList.length,
        itemBuilder: (context, i) {
          return new ExpansionTile(
            title: new Text(
              educationList[i].title,
              style: new TextStyle(
                  fontSize: 20.0,
                  fontWeight: FontWeight.bold,
                  fontStyle: FontStyle.italic),
            ),
            children: <Widget>[
              new Column(
                children: _buildExpandableContent(educationList[i]),
              ),
            ],
          );
        },
      ),
    );
  }

  _buildExpandableContent(Education education) {
    List<Widget> columnContent = [];

    for (String content in education.topic)
      columnContent.add(
        new ListTile(
          title: new Text(
            content,
            style: new TextStyle(fontSize: 18.0),
          ),
          leading: new Icon(Icons.arrow_forward_ios),
        ),
      );

    return columnContent;
  }
}

class Education {
  final String title;
  List<String> topic = [];

  Education(this.title, this.topic);
}

List<Education> educationList = [
  new Education(
    'Flutter',
    ['Basic in flutterturorial.in', 'ListView in flutterturorial.in']
  ),
  new Education(
    'Java',
    ['Basic in flutterturorial.in', 'OOP in flutterturorial.in', 'Generics in flutterturorial.in']
  ),
];

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