Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

关于flutter类型报错的问题

以前天天写js,突然切换到dart,真不习惯,下面是报错的代码:

import 'package:flutter/material.dart';
import './ClockWidget.dart';
import './ControlWidget.dart';
import './MusicWidget.dart';
import './TestScrollNotification.dart';

class MyHomePage extends StatefulWidget {
  final String title;
  MyHomePage({this.title});
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int num = 0;

  List<Map<String, dynamic>> pages = [
    {"page": ControlWidget(), "icon": Icon(Icons.settings), "title": "控制台"},
    {"page": ColockWidget(), "icon": Icon(Icons.settings), "title": "时钟列表"},
    {"page": MusickWidget(), "icon": Icon(Icons.settings), "title": "音乐控制"},
    {
      "page": TestScrollNotification(),
      "icon": Icon(Icons.settings),
      "title": "测试页面"
    }
  ];

  void showPage(int n) {
    setState(() {
      num = n;
      print(num);
    });
  }

  List<Widget> renderList(
      int num, List<Map<String, dynamic>> data, Function showPage) {
    List<Widget> list = [];
    for (var i = 0; i < data.length; i++) {
      print(data[i]['icon']);
      list.add(ListTile(
        tileColor: num == i ? Colors.blue : null,
        leading: data[i]['icon'],
        title: Text(data[i]['title']),
        trailing: new Icon(Icons.arrow_forward_ios),
        onTap: () => {showPage(i)},
      ));
    }
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text("标准时钟系统")),
        body: Row(
          children: [
            Container(
              width: 200,
              child: ListView(children: renderList(num, pages, showPage)),
            ),
            // Expanded(flex: 1, child: pages[num])
          ],
        ));
  }
}

报错信息如图:

image.png

我按字面翻译说是动态List不是 静态List<Map<String, dynamic>> 的子类型 所以不太明白,万望朋友们帮忙解惑,万分感激


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

没看出问题,具体报错位置是哪儿


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...