将小部件停靠在其他小部件Flutter上

ruyhziif  于 2023-02-09  发布在  Flutter
关注(0)|答案(2)|浏览(121)

我想“停靠”您可以在GridView上的图片上看到的文本小部件。我的方法如下所示:

Container(
            height: 500,
            child: Column(
              children: [
                Expanded(
                  child: GridView.count(
                    physics: NeverScrollableScrollPhysics(),
                    crossAxisCount: 7,
                    childAspectRatio: 0.6,
                    children: List.generate(dates.length, (index) {
                      final date = firstMonth.add(Duration(days: index));
                      return InkWell(
                        onTap: () {
                          //print(DateTime(date.year, date.month, date.day));
                        },
                        child: Container(
                          decoration: BoxDecoration(
                            border: Border.all(
                                color: date.day == DateTime.now().day && date.month == DateTime.now().month && date.year == DateTime.now().year ? Colors.red : Colors.grey[700]!),
                          ),
                          child: dates[index],
                        ),
                      );
                    }),
                  ),
                ),
                Text("Information"),
                Text("more Information"),

              ],
            ),
          )

问题是,当我们看到二月时,它没有停靠,它现在漂浮在虚空中:

要么我削减日历或浮动在无人区。有没有办法对接到网格视图?我已经尝试使用只是一个扩展,但网格视图占用太多的空间,比它实际需要的,所以文本窗口小部件是在底部...有人能帮我吗?

yquaqz18

yquaqz181#

尝试使用堆栈微件,该微件是为将某个微件“停靠”在另一个微件上而创建的
https://api.flutter.dev/flutter/widgets/Stack-class.html

v6ylcynt

v6ylcynt2#

堆栈与停靠似乎也工作,但我发现另一个解决方案没有添加堆栈:

Column(
        children: [
          GridView.count(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            crossAxisCount: 7,
            childAspectRatio: 0.6,
            children: List.generate(dates.length, (index) {
              final date = firstMonth.add(Duration(days: index));
              return InkWell(
                onTap: () {
                  //print(DateTime(date.year, date.month, date.day));
                },
                child: Container(
                  decoration: BoxDecoration(
                    border: Border.all(
                        color: date.day == DateTime.now().day && date.month == DateTime.now().month && date.year == DateTime.now().year
                            ? Colors.red
                            : Colors.grey[700]!),
                  ),
                  child: dates[index],
                ),
              );
            }),
          ),
          Column(
            mainAxisAlignment: MainAxisAlignment.end,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              SizedBox(height: 20,),
              Text("more Information"),
              Text("more Information"),
            ],
          ),
        ],
      ),

它也停靠在这里

相关问题