栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Flutter中创建Expandable ListView

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Flutter中创建Expandable ListView

Try this:

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: vehicles.length,        itemBuilder: (context, i) {          return new ExpansionTile( title: new Text(vehicles[i].title, style: new TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic),), children: <Widget>[   new Column(     children: _buildExpandableContent(vehicles[i]),   ), ],          );        },      ),    );  }  _buildExpandableContent(Vehicle vehicle) {    List<Widget> columnContent = [];    for (String content in vehicle.contents)      columnContent.add(        new ListTile(          title: new Text(content, style: new TextStyle(fontSize: 18.0),),          leading: new Icon(vehicle.icon),        ),      );    return columnContent;  }}class Vehicle {  final String title;  List<String> contents = [];  final IconData icon;  Vehicle(this.title, this.contents, this.icon);}List<Vehicle> vehicles = [  new Vehicle(    'Bike',    ['Vehicle no. 1', 'Vehicle no. 2', 'Vehicle no. 7', 'Vehicle no. 10'],    Icons.motorcycle,  ),  new Vehicle(    'Cars',    ['Vehicle no. 3', 'Vehicle no. 4', 'Vehicle no. 6'],    Icons.directions_car,  ),];


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/366411.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号