错误:使用ListView时,未定义命名参数'childern'

时间:2019-05-15 06:04:29

标签: list view dart flutter

我正在使用Firebase实时数据库检索信息,然后将其显示在可滚动的数据表中。

为了使DataTable可以滚动,我根据这篇文章的评论将其包装在ListView中: DataTable - make scrollable, set background colour and fix/freeze header row and first column

这是我的代码:

import 'package:flutter/material.dart';
import 'package:firebase_database/firebase_database.dart';
import 'cprdata.dart';
import 'dart:convert';


class CprAnalysis extends StatefulWidget {
  @override
  CPRState createState() => CPRState();
}

class CPRState extends State<CprAnalysis> {

  ///var cpr = UpdateData.getData();
  List<FilterData> acData;

  List<FilterData> getData() {
    var cpr = <FilterData>[];

    DatabaseReference cprData = FirebaseDatabase.instance.reference();
    cprData.reference().once().then((DataSnapshot snap) {
      var d = snap.value;
      final jsonE = json.encode(d);
      final jsonResponse = json.decode(jsonE);
      MyDataList zz = new MyDataList.fromJson(jsonResponse);
      zz.myList.forEach((data) {
        cpr.add(FilterData(sYMBOL: data.SYMBOL, fORECAST: data.FORECAST));
      }
      );
    },
    );
    print(cpr);
    return cpr;
  }

  @override
  void initState() {
    super.initState();
    acData = getData();
  }

  Widget bodydata() => Expanded(
            child: ListView(
              ///shrinkWrap: true,
              padding: const EdgeInsets.all(8.0),
              childern: <Widget>[
                SingleChildScrollView(
                  scrollDirection: Axis.horizontal,
                  child: DataTable(
                  columns: <DataColumn>[
                    DataColumn(
                      label: Text("Symbol"),
                      numeric: false,
                    ),
                    DataColumn(
                      label: Text("Forecast"),
                      numeric: false,
                    ),
                  ],

                  rows: acData.map((data) =>
                      DataRow(
                        cells: [
                          DataCell(
                            Text(data.sYMBOL),
                            showEditIcon: false,
                            placeholder: false,
                          ),
                          DataCell(
                            Text(data.fORECAST),
                            showEditIcon: false,
                            placeholder: false,
                          )
                        ],
                      ),
                  )
                      .toList()
              ),
          ),
          ]
        ),
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("CPR Analysis"),
      ),
      body: Container(

        child: bodydata(),
      ),
    );
  }
}


class FilterData {
  String sYMBOL, fORECAST;

  FilterData({
    this.sYMBOL,
    this.fORECAST});
}


预期输出:可滚动的数据表。

实际输出:错误:未在ListView()下定义命名参数'childern'

1 个答案:

答案 0 :(得分:1)

您在代码中将children拼写为childern

将您的ListView代码设为-

ListView(
  children: <Widget> [
    //Your remaining code
  ]
),