美文网首页
flutter控件之ExpansionPanelList

flutter控件之ExpansionPanelList

作者: Mr丶xi先森 | 来源:发表于2018-09-11 16:06 被阅读725次
import 'package:flutter/material.dart';
class LearnExpansionPanelList extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return new _LearnExpansionPanelList();
  }
}
class _LearnExpansionPanelList extends State<LearnExpansionPanelList>{
  var currentPanelIndex=-1;//设置-1默认全部闭合
  List<int> mList;
  _LearnExpansionPanelList(){
    mList=new List();
    for(int i=0;i<5;i++){
      mList.add(i);
    }
  }
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new SingleChildScrollView(
        child:new Column(
          children: <Widget>[
            new Text('这是一个自带的,样子挺丑的吧'),
            new ExpansionPanelList(
              expansionCallback: (panelIndex,isExpanded){
                setState(() {
                  currentPanelIndex=(currentPanelIndex!=panelIndex?panelIndex:-1);
                });
              },
              children: mList.map((i){
                return new ExpansionPanel(
                  headerBuilder: (context,isExpanded){
                    return new ListTile(
                      title: new Text('这是标题$i'),
                    );
                  },
                  body:new Padding(
                    padding: EdgeInsets.all(30.0),
                    child:new ListBody(
                      children: <Widget>[
                        new Text('这是标题$i的内容'),
                      ],
                    ),
                  ),
                  isExpanded: currentPanelIndex==i,
                );
              }).toList(),
            ),
            new Text('拉一个好看点的吧,类似qq分组之类的'),
//            new ListView.builder(
//                itemBuilder: (BuildContext context, int index){
//                  return new ListTile(
//                    leading: new Icon(Icons.add),
//                    title: new Text('111'),
//                  );
//                },
//              itemCount: 1,
//            ),
          ],
        ),
      ),
    );
  }
}

相关文章

网友评论

      本文标题:flutter控件之ExpansionPanelList

      本文链接:https://www.haomeiwen.com/subject/swpugftx.html