Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何为列表中的每个值显示按钮?_Flutter_Dart - Fatal编程技术网

Flutter 如何为列表中的每个值显示按钮?

Flutter 如何为列表中的每个值显示按钮?,flutter,dart,Flutter,Dart,我有一个字符串列表_选项,我想为_选项列表中的每个值显示一个按钮。 我有一个错误:元素类型Set MaterialButton无法分配给列表类型“Widget” import 'package:flutter/material.dart'; class QuestionPage extends StatelessWidget { final String playerName; final String question; final List<String>

我有一个字符串列表_选项,我想为_选项列表中的每个值显示一个按钮。 我有一个错误:元素类型Set MaterialButton无法分配给列表类型“Widget”

    import 'package:flutter/material.dart';


class QuestionPage extends StatelessWidget {

  final String playerName;   final String question;   final List<String> _choice;   final String answer;


  QuestionPage(this.playerName, this.question, this._choice, this.answer);


  Widget build(BuildContext context) {
    return Scaffold(
        //AppBar
        appBar: AppBar(
        title: Text("$playerName to play", style: TextStyle(color: Colors.white)),
    centerTitle: true,
    backgroundColor: Colors.black,
    ),

      body: Stack(children: <Widget>[
      new Container(
      child: SingleChildScrollView(
          child: Container(
              padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
              child: Center(
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Text('Question: \n $question'),

                      //------------PROBLEM HERE------------------
                      for (var i = 0; i < _choice.length; i++) {
                      new MaterialButton(
                        minWidth: 120.0,
                        color: Colors.blueGrey,
                        onPressed: null,
                        child: new Text(_choice[i],
                          style: new TextStyle(
                              fontSize: 20.0,
                              color: Colors.white
                          ),),
                      ),
                      }

                      ]   ))))]

    )} }

拆下用于卷曲支架的环

您需要更改以下内容:

    for (var i = 0; i < _choice.length; i++) {
          new MaterialButton(
            minWidth: 120.0,
            color: Colors.blueGrey,
            onPressed: null,
            child: new Text(_choice[i],
              style: new TextStyle(
                  fontSize: 20.0,
                  color: Colors.white
              ),),
          ),
          }
为此:

for (var i = 0; i < _choice.length; i++)
  new MaterialButton(
    minWidth: 120.0,
    color: Colors.blueGrey,
    onPressed: null,
    child: new Text(_choice[i],
      style: new TextStyle(
          fontSize: 20.0,
          color: Colors.white
      ),
      ),
  ),