1+ import 'package:flutter/material.dart' ;
2+
3+ class ExpansionPanelItem {
4+ final String headerText;
5+ final Widget body;
6+ bool isExpanded;
7+ ExpansionPanelItem ({
8+ this .headerText,
9+ this .body,
10+ this .isExpanded
11+ });
12+ }
13+
14+ class Index extends StatefulWidget {
15+ @override
16+ _IndexState createState () => _IndexState ();
17+ }
18+
19+ class _IndexState extends State <Index > {
20+ List <ExpansionPanelItem > _expansionPanelItems;
21+ @override
22+ void initState () {
23+ // TODO: implement initState
24+ super .initState ();
25+ _expansionPanelItems = < ExpansionPanelItem > [
26+ ExpansionPanelItem (
27+ headerText: 'Panel A' ,
28+ body: Container (
29+ padding: EdgeInsets .all (16.0 ),
30+ width: double .infinity,
31+ child: Image .network ('http://pic1.win4000.com/wallpaper/2019-02-15/5c664c46823f8.jpg' ),
32+ ),
33+ isExpanded: false
34+ ),
35+ ExpansionPanelItem (
36+ headerText: 'Panel B' ,
37+ body: Container (
38+ padding: EdgeInsets .all (16.0 ),
39+ width: double .infinity,
40+ child: Image .network ('http://pic1.win4000.com/wallpaper/2019-02-14/5c651084373de.jpg' ),
41+ ),
42+ isExpanded: false
43+ ),
44+ ExpansionPanelItem (
45+ headerText: 'Panel C' ,
46+ body: Container (
47+ padding: EdgeInsets .all (16.0 ),
48+ width: double .infinity,
49+ child: Image .network ('http://pic1.win4000.com/wallpaper/2019-02-14/5c65107a0ee05.jpg' ),
50+ ),
51+ isExpanded: false
52+ )
53+ ];
54+
55+ }
56+ @override
57+ Widget build (BuildContext context) {
58+ return Scaffold (
59+ appBar: AppBar (title: Text ('ExpansionPanel' ),),
60+ body: SingleChildScrollView (
61+ padding: EdgeInsets .all (16.0 ),
62+ child: ExpansionPanelList (
63+ animationDuration: Duration (microseconds: 500 ),
64+ expansionCallback: (int panelIndex, bool isExpaned) {
65+ setState (() {
66+ _expansionPanelItems[panelIndex].isExpanded = ! isExpaned;
67+ });
68+ },
69+ children: _expansionPanelItems.map (
70+ (ExpansionPanelItem item) {
71+ return ExpansionPanel (
72+ isExpanded: item.isExpanded,
73+ body: item.body,
74+ headerBuilder: (BuildContext context, bool isExpanded) {
75+ return Container (
76+ padding: EdgeInsets .all (16.0 ),
77+ child: Text (
78+ item.headerText,
79+ style: Theme .of (context).textTheme.title,
80+ ),
81+ );
82+ }
83+ );
84+ }
85+ ).toList (),
86+ ),
87+ ),
88+ );
89+ }
90+ }
0 commit comments