Flutter Dart List.map() 获取下标

class HomePageState extends State{
  final topTitles = ['审批单', '机票列表', '客服'];
  final topIcons = ['assets/home/approval.png', 'assets/home/air_ticket.png', 'assets/home/service.png'];
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: AppBar(
        title: Text('首页')
      ),
      body: Column(
        children: <Widget>[
          //顶部
          Row(
            children: topTitles.asMap().keys.map((f)=>
          //f拿到的就是下标:
Expanded( flex: 1, child: Column( children: <Widget>[ Image( image: new AssetImage(topIcons[f]), height: 60, width: 60), Text(topTitles[f]) ], ), )).toList(), ), //列表 ], ), ); } @override void initState() { // TODO: implement initState super.initState(); print("initStateHome"); } }

 

posted @ 2019-10-22 14:25  生如逆旅,一苇以航  阅读(9622)  评论(0编辑  收藏  举报