如何在ListTile中显示每个值映射?

时间:2020-04-20 13:31:15

标签: flutter dart

我的目标
我有一个名为“得分”的地图,我想在ListTile中显示每个值。 我收到此错误消息的问题:“此处的表达式的类型为void,无法使用。”

我的代码:

function exportToExcelsheets($data, $fileName){
    /* Create new PHPExcel object*/
    $objPHPExcel = new PHPExcel();
    $sheet_index = 0;
    foreach ($data as $s=>$sheet){
        /* Create a first sheet, representing sales data*/
        $alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','V','W','X','Y','Z'];
        $objPHPExcel->setActiveSheetIndex($sheet_index);
        $head_keys = array_keys($sheet[0]);
        foreach ($head_keys as $a=>$headval){
            $objPHPExcel->getActiveSheet()->setCellValue($alpha[$a].'1', $headval);
        }
        $i=2;
        foreach($sheet as $row) {
            $index = 0;
            foreach ($row as $v=>$value){
                $value =  isset($value)?$value:'';
                $objPHPExcel->getActiveSheet()->setCellValue($alpha[$index].$i,$value);
                $index++;
            }
            $i++;
        }
        /*Rename sheet*/
        $objPHPExcel->getActiveSheet()->setTitle('sheet_'.$s);
        /* Create a new worksheet, after the default sheet*/
        $objPHPExcel->createSheet();
        $sheet_index++;
    }

    /* Redirect output to a client’s web browser (Excel5)*/
    header('Content-Type: application/vnd.ms-excel');
    header("Content-Disposition: attachment; filename=\"$fileName\"");
    header('Cache-Control: max-age=0');
    //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    //$objWriter->save('php://output');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('php://output');
}

2 个答案:

答案 0 :(得分:2)

return Scaffold(
    appBar: AppBar(
      title: Text('Result'),
    ),
    body: Container(
        child: SingleChildScrollView(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            children:
              score.entries.map( (entry) => new ListTile(
                contentPadding: const EdgeInsets.all(16.0),
                title: Text(entry.key),
                trailing: Text(entry.value.toString()),
              )).toList(),
          ),
        )
    )
);

答案 1 :(得分:1)

您可以创建一个方法...

  final Map<String, int> score = {'playe1': 1, 'player2': 2};

  List<Widget> builder() {
    List<Widget> l = [];
    score.forEach((k, v) => l.add(ListTile(
          contentPadding: const EdgeInsets.all(16.0),
          title: Text(k),
          trailing: Text(v.toString()),
        )));
    return l;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(body: Column(children: builder()));
  }