简体   繁体   English

如何使列表视图与 itemBuilder 一起使用

[英]How to make listview to work with itemBuilder

i can't seem to solve this problem, for me the code it's correct, but i can't see where the error is.我似乎无法解决这个问题,对我来说代码是正确的,但我看不到错误在哪里。 What do i need to return for the listview?我需要为列表视图返回什么? Should i put the listview.builder in another place?我应该把 listview.builder 放在另一个地方吗? the listbuild is returning the _buildTitleSection and the _buildCreditCard so i can't seem to understand it. listbuild 正在返回 _buildTitleSection 和 _buildCreditCard,所以我似乎无法理解它。

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            ListView.builder(
               itemCount: users == null ? 0 : users.length,
              itemBuilder: (context, index) { //This is giving me "error" *** 
                _buildTitleSection(
                    title: "Names", subTitle: "User informations");
                _buildCreditCard(
                    url: users[index].imageURL,
                    color: Color(0xFF1E90FF),
                    cardExpiration: users[index].cardExpiration,
                    cardHolder: users[index].cardHolder,
                    cardNumber: users[index].cardNumber);
                SizedBox(
                  height: 15,
                );
              },
            ),
          ],
        ),
      ),
    );
  }

***This function has a return type of 'Widget', but doesn't end with a return statement. ***此函数的返回类型为“Widget”,但不以 return 语句结尾。 Try adding a return statement, or changing the return type to 'void'.尝试添加 return 语句,或将返回类型更改为“void”。

Builder methods need to return an object of type Widget so in order to get your code working you need to return your widgets, you have more than one widget, you have to wrap them in a Column or a Row..构建器方法需要返回一个 Widget 类型的对象,所以为了让你的代码工作,你需要返回你的小部件,你有多个小部件,你必须将它们包装在一个列或一行中..

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            ListView.builder(
               itemCount: users == null ? 0 : users.length,
              itemBuilder: (context, index) {
                return Column(
                   children: [
                        _buildTitleSection(
                            title: "Names", subTitle: "User informations"),
                        _buildCreditCard(
                            url: users[index].imageURL,
                            color: Color(0xFF1E90FF),
                            cardExpiration: users[index].cardExpiration,
                            cardHolder: users[index].cardHolder,
                            cardNumber: users[index].cardNumber),
                        SizedBox(
                            height: 15,
                        ),
                    ]
                );
              },
            ),
          ],
        ),
      ),
    );
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM