简体   繁体   English

Flutter:GroupedListView 无法正常工作

[英]Flutter: GroupedListView not working as it should

Why are my first date and first 2 items correctly built but not the rest?为什么我的第一次约会和前 2 个项目正确构建,但其余的却没有? The first date header wrap my text correctly but the padding is incorrect and the rest has the correct padding but does not wrap my text.第一个date header正确地包裹了我的文本,但填充不正确,其余的有正确的填充但不包裹我的文本。 This is how it looks like right now .这就是它现在的样子

GroupedListView<dynamic, String>(
                    shrinkWrap: true,
                    elements: activityList,
                    groupBy: (element) => element['date'].substring(0, 10),
                    groupSeparatorBuilder: (String groupByValue) => 
                      child: Container(
                          height: 35,
                          width: 125,
                          decoration: BoxDecoration(
                            shape: BoxShape.rectangle,
                            borderRadius: BorderRadius.circular(25),
                            color: themeProvider.isDarkMode
                                ? Color(0xFF64B6F7)
                                : Color(0xFFFFCC00),
                          ),
                          child: Center(child: Text(...))
                    ),
                    itemComparator: (item1, item2) =>
                        item1['date'].compareTo(item2['date']),
                    itemBuilder: (context, element) { 
                      return Card(
                        elevation: 5,
                        margin: EdgeInsets.symmetric(vertical: 15),
                      child: ListTile(
                        //listtile
                      ),
                    );},
                    useStickyGroupSeparators: true,
                    floatingHeader: true,
                  )

The problem is caused by useStickyGroupSeparators but I would want to use that.问题是由useStickyGroupSeparators引起的,但我想使用它。

Based on your code, I tried to reproduce the effect.根据您的代码,我尝试重现该效果。 Is this what you want to achieve?这是你想要达到的目标吗?

截屏

The code:编码:

class TestPage extends StatelessWidget {
  const TestPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: GroupedListView<dynamic, String>(
          shrinkWrap: true,
          elements: items,
          groupBy: (element) => element['date'].substring(0, 10),
          groupSeparatorBuilder: (String groupByValue) => Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Container(
                  height: 35,
                  width: 125,
                  decoration: BoxDecoration(
                    shape: BoxShape.rectangle,
                    borderRadius: BorderRadius.circular(25),
                    color: const Color(0xFFFFCC00),
                  ),
                  child: Center(child: Text(groupByValue))),
            ],
          ),
          itemComparator: (item1, item2) =>
              item1['date'].compareTo(item2['date']),
          itemBuilder: (context, element) {
            return Card(
              elevation: 5,
              margin: const EdgeInsets.symmetric(vertical: 15),
              child: ListTile(
                title: Text(element['activity']),
              ),
            );
          },
          useStickyGroupSeparators: true,
          floatingHeader: true,
        ),
      ),
    );
  }
}

Mock data:模拟数据:

final items = [
  {"date": "2022-07-08", "activity": "Activity 1"},
  {"date": "2022-07-08", "activity": "Activity 2"},
  {"date": "2022-07-09", "activity": "Activity 3"},
  {"date": "2022-07-09", "activity": "Activity 4"},
  {"date": "2022-07-10", "activity": "Activity 5"},
  {"date": "2022-07-11", "activity": "Activity 6"},
  {"date": "2022-07-11", "activity": "Activity 7"},
  {"date": "2022-07-11", "activity": "Activity 8"},
  {"date": "2022-07-11", "activity": "Activity 10"},
  {"date": "2022-07-11", "activity": "Activity 11"},
  {"date": "2022-07-11", "activity": "Activity 12"},
  {"date": "2022-07-11", "activity": "Activity 13"},
  {"date": "2022-07-11", "activity": "Activity 14"},
  {"date": "2022-07-11", "activity": "Activity 15"},
  {"date": "2022-07-12", "activity": "Activity 9"},
];

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

相关问题 在 StreamBuilder 中使用 GroupedListView flutter - use GroupedListView in StreamBuilder flutter 如何将 Stream 传递给 GroupedListView Flutter - How to pass Stream to GroupedListView Flutter 在Flutter中使用带有FireBase数据的StreamBuilder时,如何将ListView替换为GroupedListView? - How to replace ListView with GroupedListView while using StreamBuilder with FireBase data in Flutter? NavigationPush 无法正常工作 - NavigationPush not working in flutter as it should do 如何使用 Streambuilder 和 firebase QuerySnapshot 使用 GroupedListView - How to use GroupedListView using Streambuilder and firebase QuerySnapshot 一个 flutter 屏幕应该一直工作,无论我是在那个屏幕上还是在另一个屏幕上 - One flutter screen should be working the entire time regardless of whether i am on that screen or another flutter 项目的 dockerfile 应该如何 - How should be a dockerfile for a flutter project Stream 构建器在第一次加载屏幕时未加载所需数据,然后在更改选项卡后正常工作:Flutter - Stream builder not loading desired data at the first loading of the screen, then working as it should after changing tabs : Flutter Flutter DateFormatter无法正常工作 - Flutter dateformatter not working correctly Flutter:setState()无法正常工作 - Flutter : setState() is not working properly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM