import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class ExcerciseListPage extends StatefulWidget {
ExcerciseListPage({Key? key}) : super(key: key);
@override
_ExcerciseListPageState createState() => new _ExcerciseListPageState();
}
const CITY_NAMES = {
'北京': ['东城区', '西城区', '朝阳区', '顺义区', '南城区', '北城区'],
'上海': ['浦东区', '浦西区', '崇明区', '虹口区'],
'广州': ['越秀区', '珠海', '荔湾', '番禺'],
'合肥': ['瑶海', '蜀山', '庐阳', '经开'],
};
class _ExcerciseListPageState extends State<ExcerciseListPage>
with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
final title = '列表展开收起';
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Container(
child: ListView(
children: _buildList(),
),
),
);
}
List<Widget> _buildList() {
List<Widget> widgets = [];
CITY_NAMES.keys.forEach((key) {
widgets.add(_item(key, CITY_NAMES[key]!));
});
return widgets;
}
Widget _item(String city, List<String> subCities) {
return ExpansionTile(
title: Text(
city,
style: TextStyle(color: Colors.black54, fontSize: 20),
),
children: subCities.map((subCity) => _buildSubCity(subCity)).toList(),
);
}
Widget _buildSubCity(String subCity) {
return FractionallySizedBox(
widthFactor: 1,
child: Container(
height: 50,
margin: EdgeInsets.only(bottom: 5),
decoration: BoxDecoration(color: Colors.lightBlue),
child: Text(subCity),
),
);
}
@override
bool get wantKeepAlive => true;
}
Flutter:ExpansionTile折叠展开层级菜单
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- (2019-03-04-周一 04:53:01) “此快捷键无法更改”,系统默认,尚未发现执行效果(按快捷键无反应)。