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 颤振ListView和ListView.builder问题_Flutter_Dart - Fatal编程技术网

Flutter 颤振ListView和ListView.builder问题

Flutter 颤振ListView和ListView.builder问题,flutter,dart,Flutter,Dart,我是Flatter的初学者,我创建了一个显示玩家信息的小部件,我使用了ListView和ListView.builder,但我有一个uknown错误,错误是:断言失败:第1785行位置12:“hasSize” 我不知道这个错误的来源是什么,它只是在我添加ListView构建器时开始的,在我添加它之前,一切都正常 以下是我尝试过的: import 'package:flutter/material.dart'; import 'package:tl_fantasy/widgets/Player_W

我是Flatter的初学者,我创建了一个显示玩家信息的小部件,我使用了ListView和ListView.builder,但我有一个uknown错误,错误是:断言失败:第1785行位置12:“hasSize”

我不知道这个错误的来源是什么,它只是在我添加ListView构建器时开始的,在我添加它之前,一切都正常

以下是我尝试过的:

import 'package:flutter/material.dart';
import 'package:tl_fantasy/widgets/Player_Widget.dart';
import 'player_arguments.dart';

class PlayerDetails extends StatelessWidget {


  @override
  Widget build(BuildContext context) {
    final PlayerArguments args = ModalRoute.of(context).settings.arguments;
    List<Stats> stats = [
      Stats("Matches", args.matches ),
      Stats("Goals", args.goals ),
      Stats("Assists", args.assists ),
      Stats("Saves", args.saves ),
    ];

    List<Team> teams = [
      Team("Barcelona B", "https://i.pinimg.com/originals/ef/9c/3f/ef9c3fccec423f70376fcafa05c5d447.jpg","1998" ),
      Team("Barcelona", "https://i.pinimg.com/originals/ef/9c/3f/ef9c3fccec423f70376fcafa05c5d447.jpg","2005" ),
    ];

    return Scaffold(
      appBar: AppBar(
        title: Text("Player Details"),
        backgroundColor: Colors.blue[300],
        elevation: 0.0,
      ),
      body: Container(
        decoration: BoxDecoration(
            gradient: LinearGradient(
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
                colors: [Colors.purple, Colors.blue])
        ),
        child: Container(
          decoration: BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                  colors: [Colors.purple, Colors.black38])),
          child: ListView(
            children: [
              SizedBox(
                height: 20,
              ),
              Container(
                width: double.infinity,
                child:    Card(
                  elevation: 4.0,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10.0),
                  ),
                  child: Padding(
                    padding: const EdgeInsets.all(16.0),
                    child:
                    Row(
                      children: <Widget>[
                        CircleAvatar(
                          backgroundImage: NetworkImage(args.image),
                        ),
                        const SizedBox(width:10.0),
                        Spacer(),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: <Widget> [
                            Text(args.name, style: TextStyle( fontWeight:FontWeight.bold,
                              fontSize: 18.0,
                            )),
                            const SizedBox(height: 5.0, ),
                            Text(args.club, style: TextStyle( fontWeight:FontWeight.bold,
                              fontSize: 18.0,
                            )),
                            const SizedBox(height: 5.0, ),
                            Text("Role : "+args.role, style: TextStyle( fontWeight:FontWeight.bold,
                              fontSize: 18.0, color: Colors.grey[600],
                            )),
                            const SizedBox(height: 5.0, ),
                            Text("Position : "+args.club, style: TextStyle( fontWeight:FontWeight.bold,
                              fontSize: 18.0, color: Colors.grey[600],
                            )),
                            const SizedBox(height: 5.0, ),
                            Text("Nationality : "+args.nationality, style: TextStyle( fontWeight:FontWeight.bold,
                              fontSize: 18.0, color: Colors.grey[600],
                            )),

                          ],
                        ),

                      ],
                    ),
                  ),
                ),
              ),
              Container(
                  padding: EdgeInsets.all(12.0),
                  child: GridView.builder(
                    shrinkWrap: true,
                    itemCount: stats.length,
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 2,
                        crossAxisSpacing: 4.0,
                        mainAxisSpacing: 4.0
                    ),
                    itemBuilder: (BuildContext context, int index){
                      return Card(
                        child: Center(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                              children: <Widget>[
                                Container(
                                  alignment: Alignment.topCenter,
                                  padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
                                  child:  Text(stats[index].result,style: TextStyle(fontSize: 20.0)),
                                ),
                                Container(
                                  alignment: Alignment.bottomCenter,
                                  child: Text(stats[index].title,style: TextStyle(fontSize: 25.0)),),

                              ]
                          ),
                        ),
                      );
                    },
                  )
              ),
              SizedBox(
                height: 30,
              ),
             Container(child:
             ListView.builder(
               itemBuilder: (context, index){
                 return Card(
                   elevation: 4.0,
                   shape: RoundedRectangleBorder(
                     borderRadius: BorderRadius.circular(10.0),
                   ),
                   child: Padding(
                     padding: const EdgeInsets.all(16.0),
                     child:
                     Row(
                       children: <Widget>[
                         CircleAvatar(
                           backgroundImage: NetworkImage(teams[index].image),
                         ),
                         const SizedBox(width:10.0),
                         Spacer(),
                         Column(
                           crossAxisAlignment: CrossAxisAlignment.end,
                           children: <Widget> [
                             Text(teams[index].name, style: TextStyle( fontWeight:FontWeight.bold,
                               fontSize: 18.0,
                             )),
                             const SizedBox(height: 5.0, ),
                             Text("joined : "+teams[index].date, style: TextStyle( fontWeight:FontWeight.bold,
                               fontSize: 18.0, color: Colors.grey[600],
                             )),
                           ],
                         ),

                       ],
                     ),
                   ),
                 );
               },
               itemCount: teams.length,
             ),),
            ],
          ),
        ),

      ),
    );
  }
}


class Stats{

  String title;
  String result;

  Stats(this.title,this.result);

}

class Team {

  String name;
  String image;
  String date;

  Team(this.name,this.image,this.date);

}
导入“包装:颤振/材料.省道”;
导入“package:tl_fantasy/widgets/Player_Widget.dart”;
导入“player_arguments.dart”;
类PlayerDetails扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
final PlayerArguments args=ModalRoute.of(context.settings.arguments);
列表统计=[
统计数据(“匹配”,args.Matches),
统计数据(“目标”,args.Goals),
统计数据(“助攻”,args.assesss),
统计数据(“保存”,args.Saves),
];
名单小组=[
“巴塞罗那B队”https://i.pinimg.com/originals/ef/9c/3f/ef9c3fccec423f70376fcafa05c5d447.jpg","1998" ),
“巴塞罗那队”https://i.pinimg.com/originals/ef/9c/3f/ef9c3fccec423f70376fcafa05c5d447.jpg","2005" ),
];
返回脚手架(
appBar:appBar(
标题:文本(“玩家详细信息”),
背景颜色:颜色。蓝色[300],
标高:0.0,
),
主体:容器(
装饰:盒子装饰(
梯度:线性梯度(
开始:Alignment.centerLeft,
结束:对齐。中间右侧,
颜色:[颜色。紫色,颜色。蓝色])
),
子:容器(
装饰:盒子装饰(
梯度:线性梯度(
开始:Alignment.topLeft,
结束:对齐。右下角,
颜色:[colors.purple,colors.black38]),
子:ListView(
儿童:[
大小盒子(
身高:20,
),
容器(
宽度:double.infinity,
孩子:卡片(
标高:4.0,
形状:圆形矩形边框(
边界半径:边界半径。圆形(10.0),
),
孩子:填充(
填充:常数边集全部(16.0),
儿童:
划船(
儿童:[
圆形(
背景图像:NetworkImage(args.image),
),
常量大小框(宽度:10.0),
垫片(),
纵队(
crossAxisAlignment:crossAxisAlignment.end,
儿童:[
Text(args.name,style:TextStyle(fontwweight:fontwweight.bold,
字体大小:18.0,
)),
const SizedBox(高度:5.0,),
文本(args.club,样式:TextStyle),
字体大小:18.0,
)),
const SizedBox(高度:5.0,),
Text(“角色:”+args.Role,样式:TextStyle(fontWeight:fontWeight.bold,
fontSize:18.0,颜色:Colors.灰色[600],
)),
const SizedBox(高度:5.0,),
Text(“位置:”+args.club,样式:TextStyle(fontWeight:fontWeight.bold,
fontSize:18.0,颜色:Colors.灰色[600],
)),
const SizedBox(高度:5.0,),
Text(“国籍:”+args.national,样式:TextStyle(fontWeight:fontWeight.bold,
fontSize:18.0,颜色:Colors.灰色[600],
)),
],
),
],
),
),
),
),
容器(
填充:所有边缘设置(12.0),
子项:GridView.builder(
收缩膜:对,
itemCount:stats.length,
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(
交叉轴计数:2,
交叉轴间距:4.0,
主轴间距:4.0
),
itemBuilder:(构建上下文,int索引){
回程卡(
儿童:中心(
子:列(
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
容器(
对齐:alignment.topCenter,
填充:从LTRB(0,5,0,0)开始的边缘设置,
子项:文本(统计信息[索引])。结果,样式:TextStyle(fontSize:20.0)),
),
容器(
对齐:对齐.bottomCenter,
子项:文本(统计信息[索引])。标题,样式:TextStyle(fontSize:25.0)),
]
),
),
);
},
)
),
大小盒子(
身高:30,
),
容器(子容器:
ListView.builder(
itemBuilder:(上下文,索引){
回程卡(
标高:4.0,
形状:圆形矩形边框(
边界半径:边界半径。圆形(10.0),
),
孩子:填充(
衬垫
    Container(
height: //your parameter,
width: //your parameter,
child:
             ListView.builder(
               itemBuilder: (context, index){
                 return Card(
                   elevation: 4.0,
                   shape: RoundedRectangleBorder(
                     borderRadius: BorderRadius.circular(10.0),
                   ),
                   child: Padding(
                     padding: const EdgeInsets.all(16.0),
                     child:
                     Row(
                       children: <Widget>[
                         CircleAvatar(
                           backgroundImage: NetworkImage(teams[index].image),
                         ),
                         const SizedBox(width:10.0),
                         Spacer(),
                         Column(
                           crossAxisAlignment: CrossAxisAlignment.end,
                           children: <Widget> [
                             Text(teams[index].name, style: TextStyle( fontWeight:FontWeight.bold,
                               fontSize: 18.0,
                             )),
                             const SizedBox(height: 5.0, ),
                             Text("joined : "+teams[index].date, style: TextStyle( fontWeight:FontWeight.bold,
                               fontSize: 18.0, color: Colors.grey[600],
                             )),
                           ],
                         ),

                       ],
                     ),
                   ),
                 );
               },
               itemCount: teams.length,
             ),),
   Column(
  children: [
    Expanded(
      child: ListView.builder(
        itemBuilder: (context, index) {
          return Card(
            elevation: 4.0,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(10.0),
            ),
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: Row(
                children: <Widget>[
                  CircleAvatar(
                    backgroundImage: NetworkImage(teams[index].image),
                  ),
                  const SizedBox(width: 10.0),
                  Spacer(),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: <Widget>[
                      Text(teams[index].name,
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 18.0,
                          )),
                      const SizedBox(
                        height: 5.0,
                      ),
                      Text("joined : " + teams[index].date,
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 18.0,
                            color: Colors.grey[600],
                          )),
                    ],
                  ),
                ],
              ),
            ),
          );
        },
        itemCount: teams.length,
      ),
    ),
  ],
);