非常新的Flutter .我已经能够利用HTTP数据请求、构建列表视图、编辑列表中的一行以及其他基本功能.环境很好.

我已经设法为ListView拼凑了一个构造不佳的标题.但我知道这是不对的.我无法使标题文本正确对齐.

我看到这个抽屉类有一个DrawerHeader类,但是没有看到ListView有一个ListViewHeader.

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Contacts'),
          actions: [
            IconButton(icon: Icon(Icons.add_circle),
                onPressed: getCustData
            ),
          ],
        ),
        //body:
        body: Column(
            children: [
              Row(
                  children: [
                    Expanded(child: Text('', style: TextStyle(height: 3.0, fontSize: 15.2, fontWeight: FontWeight.bold,))),
                    Expanded(child: Text('First Name', style:  TextStyle(height: 3.0, fontSize: 15.2, fontWeight: FontWeight.bold,))),
                    Expanded(child: Text('Last Name', style:  TextStyle(height: 3.0, fontSize: 15.2, fontWeight: FontWeight.bold,))),
                    Expanded(child: Text('City', style: TextStyle(height: 3.0, fontSize: 15.2, fontWeight: FontWeight.bold,))),
                    Expanded(child: Text('Customer Id', style: TextStyle(height: 3.0, fontSize: 15.2, fontWeight: FontWeight.bold,))),
                    Expanded(child: Text('', style: TextStyle(height: 3.0, fontSize: 15.2, fontWeight: FontWeight.bold,))),
                  ]
              ),

          Expanded(child:Container(
            child: ListView.builder(

              itemCount: data == null ? 0 : data.length,
              itemBuilder: (BuildContext context, int index) {

                return InkWell(
                  onTap: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => APIDetailView(data[index])),
                    );
                  },

                  child: ListTile(                //return new ListTile(
                      onTap: null,
                      leading: CircleAvatar(
                        backgroundColor: Colors.blue,
                        child: Text(data[index]["FirstName"][0]),
                      ),
                      title: Row(
                          children: <Widget>[
                            Expanded(child: Text(data[index]["FirstName"])),
                            Expanded(child: Text(data[index]["LastName"])),
                            Expanded(child: Text(data[index]["Bill_City"])),
                            Expanded(child: Text(data[index]["Customer_Id"])),
                          ]
                      )
                  ),

                );
              }, //itemBuilder

            ),
          ),
        ),
      ]
    )
);

}

谢谢

enter image description here

推荐答案

这就是我是如何解决这个问题的.感谢@najeira让我思考其他解决方案.

在第一个正文列中,我使用了与ListTile相同的标题布局.

在这种情况下,因为我的数据ListTile包括CircleAvatar,所以所有的水平间距都有一点偏差……渲染CircleAvatar的5列.然后是4根等间距的柱子.

所以...我在第一个正文Column上添加了ListTile,在backgroundColor为透明的情况下添加了CircleAvatar,然后在我的4个标题中添加了Row.

        ListTile(
        onTap: null,
        leading: CircleAvatar(
          backgroundColor: Colors.transparent,
        ),
        title: Row(
            children: <Widget>[
              Expanded(child: Text("First Name")),
              Expanded(child: Text("Last Name")),
              Expanded(child: Text("City")),
              Expanded(child: Text("Id")),
            ]
        ),
      ),

enter image description here

Flutter相关问答推荐

ListView内的ListView正在一次构建所有项目

为什么我需要等待重新访问Firestore数据库,即使它已经做了之前?

FCM通知显示两次通知(&A)

如何在扩展其他小部件时访问Ref

在Flutter 中每次点击按钮时都很难调用自定义函数

我怎样才能go 掉这个底部导航栏上的白色背景

Ffltter Firebase向用户添加公司

如何处理平台游戏的对象冲突?

如何在 Flutter 中设计像 zomato 应用程序一样的搜索字段?

如何使自动焦点位于已经有一些文本的 TextField 的第一行?

Riverpod 注册多少个 providers

Flutter firebase_auth 和 firebase_core 依赖错误

如何计算 Firestore 集合中的文档数量?

使用 Play Integrity API 时,Firebase 电话身份验证问题缺少客户端标识符错误

如何从另一个页面访问 Firebase 值?

扫描flutter生成的二维码后如何弹出文本字段值

TextSpan 避免符号字符串组上的换行符

Flutter :RangeError(索引):无效值:不在包含范围内0..3:4使用IndexedListView.builder

Flutter 将方法应用于静态变量

如何在Flutter 中将列表的模型类型转换为数组?