ListView.builder()打破了我的应用程序的整个页面。我到底做错了什么?

问题描述 投票:0回答:1

当我用.builder()方法实现ListView类时,我的应用程序就会崩溃,不会在该页面上显示任何东西。

以下是我实现ListView的方法

Column(children: <Widget>[
  ListView.builder(
    itemCount: profileListItems.length,
    itemBuilder: (BuildContext context, int index) {
      ProfileListItem profileListItem = profileListItems[index];
      return InkWell(
        onTap: () {},
        child: Padding(
          padding: const EdgeInsets.all(12.0),
          child: Row(
            children: <Widget>[
              Stack(
                children: <Widget>[
                  ClipRRect(
                    borderRadius: BorderRadius.circular(28.0),
                    child: Container(
                       height: 50.0,
                       width: 50.0,
                       color: Theme.of(context).primaryColor,
                       child: profileListItem.icon
                     ),
                   ),
                 ],
               ),
               SizedBox(width: 16),
               Text(
                 profileListItem.text,
                 style: TextStyle(
                   color: Colors.black87,
                   fontWeight: FontWeight.bold,
                   fontSize: 16
                 ),
               )
             ],
           ),
         ),
       );
     }
   )
])

下面是我的ProfileListItem类

import 'package:flutter/material.dart';

class ProfileListItem {
  Icon icon;
  String text;
  String navigation;

  ProfileListItem({
    this.icon,
    this.text,
    this.navigation,
  });
}

List<ProfileListItem> profileListItems = [
  ProfileListItem(
    icon: Icon(
      Icons.dashboard,
      color: Colors.white,
      size: 24.0,
    ),
    text: 'Dashoard',
    navigation: 'Italy',
  )
];

当我添加ListView类时,页面上的所有其他小部件也消失了。只有一个白色的屏幕。

listview flutter dart builder
1个回答
2
投票

也许你可以使用Expanded widget作为ListView的父类。

Column(
 children: <Widget>[
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: ordersList.length,// Your List
itemBuilder: (context, index) {
// Followed by your return widget.
})),
]
)

如果你不想使用完整的空间,你可以去掉expand,只保留shrinkWrap: true,参数。

© www.soinside.com 2019 - 2024. All rights reserved.