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"); } }
相關文章
相關標籤/搜索