抖动列表视图中的像素溢出了23个像素

时间:2019-11-07 11:37:25

标签: flutter dart

enter image description here

我创建了一个列表视图,但它显示像素错误超载

这是您的列表视图

return ListView.builder(

      itemCount: titles.length,
      itemBuilder: (context, index) {
        return Card(
            elevation: 50,
            child: InkWell(


              splashColor: Colors.green,
              highlightColor: Colors.red,
              child: Row(
                children: <Widget>[


              Container(


                height: 100.0,
                  width:50.0,

                decoration: BoxDecoration(
                    gradient:LinearGradientStyle.linearGradient(
                        orientation:LinearGradientStyle.ORIENTATION_HORIZONTAL,
                        gradientType: LinearGradientStyle.GRADIENT_TYPE_AMIN
                    )
                ),),

                  Container(
                      margin: EdgeInsets.all(10),
                      child: Text(
                        numbers[index],
                      )),


                  Container(
                    margin: EdgeInsets.all(10),
                    child: GradientText((titles[index]),
                      gradient:gradient,

                      style:TextStyle(fontSize:20.0,fontWeight:FontWeight.bold, ),
                    ),
                    //Text(titles[index]),
                  )
                ],
              ),
              onTap: () => onTaps[index](),
            ));
      });


如果您需要更多代码,请发表评论 ...

而不是溢出错误,它应该位于列表的第二行。如果您有任何解决方案,请帮助我。...

2 个答案:

答案 0 :(得分:1)

ListView.builder(

      itemCount: 1,
      itemBuilder: (context, index) {
        return Card(
            elevation: 50,
            child: InkWell(


              splashColor: Colors.green,
              highlightColor: Colors.red,
              child: Row(
                children: <Widget>[


              Container(


                height: 100.0,
                  width:50.0,

                ),

                  Container(
                      margin: EdgeInsets.all(10),
                      child: Text(
                        "numbers[index]",
                      )),


                  Flexible(
                                      child: Container(
                      margin: EdgeInsets.all(10),
                      child: Text("GradientText"*30,

                        style:TextStyle(fontSize:20.0,fontWeight:FontWeight.bold, ),
                      ),
                      //Text(titles[index]),
                    ),
                  )
                ],
              ),
              onTap: () {},
            ));
      }),

使用灵活的窗口小部件(例如父级窗口小部件),

答案 1 :(得分:1)

我在 DropdownButton 中遇到了类似的问题。我试图为问题和答案创建下拉菜单,因为我必须为自定义模型创建 DropdownButton

isExpanded: true,

拯救了我的生命
List<Question> questions;

   Widget buildDropDown() {
    return DropdownButton<Question>(
      isExpanded: true,
      value: _selectedQuestion,
      style: TextStyle(color: Colors.white),
      items: questions.map<DropdownMenuItem<Question>>((Question question) {
        return DropdownMenuItem(
          child: Text(
            question.title,
          ),
          value: question,
        );
      }).toList(),
      onChanged: (Question question) {
        setState(() {
          _selectedQuestion = question;
        });
      },
    );
  }

class Question {
  String title;
  String answer;
  int id;

  Question({this.id, this.title});

  void setAnswer(String answer) {
    this.answer = answer;
  }
}

enter image description here