flutter 底部溢出17个像素?

5w9g7ksd  于 2023-05-23  发布在  Flutter
关注(0)|答案(1)|浏览(206)

你好,我试图为我的应用程序创建一个源页面GridView,但我得到了一个错误里面。我认为在每3个网格之后,它会指出小部件的底部溢出了17个像素。我似乎无法用SafeArea小部件修复它。我该怎么办?请帮个小忙

@override
Widget build(BuildContext context) {
return Scaffold(
  body: BlocBuilder<FeedPostBloc, FeedPostState>(
    builder: (context, postState) {
      switch (postState.status) {
        case PostStatus.failure:
          return Center(
            child: Text(
              'Bir hata oldu',
              style: Theme.of(context).textTheme.titleLarge,
            ),
          );

        case PostStatus.success:
          if (postState.posts.isEmpty) {
            return const Center(
              child: Text('Post bulunamadı'),
            );
          }
          return DraggableHome(
            appBarColor: HexColor("#562C2C"),
            title: Text(
              'Sosyal',
              style: TextStyle(color: darkColor),
            ),
            headerWidget: Container(
              color: HexColor("#562C2C"),
              child: Center(
                child: Text(
                  "Sosyal",
                  style: Theme.of(context)
                      .textTheme
                      .displayMedium!
                      .copyWith(color: HexColor("#F3D8C7")),
                ),
              ),
            ),
            body: [
              SingleChildScrollView(
                child: ListView.builder(
                  padding: const EdgeInsets.only(top: 0),
                  physics: const NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  itemBuilder: (context, index) {
                    return index >= postState.posts.length
                        ? const IndicatorWidget()
                        : PostListItem(
                            post: postState.posts[index],
                          );
                  },
                  itemCount: postState.hasReachedMax
                      ? postState.posts.length
                      : postState.posts.length + 1,
                  controller: _scrollController,
                ),
              ),
            ],
            backgroundColor: HexColor("#F3D8C7"),
          );

          default:
          return Center(
            child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'Yükleniyor...',
                    style: TextStyle(color: darkColor),
                  ),
                  CircularProgressIndicator(
                    color: darkColor,
                    strokeWidth: 1.5,
                  )
                ]),
          );
      }
    },
  ),
  backgroundColor: HexColor("#F3D8C7"),
);
}
}

class IndicatorWidget extends StatelessWidget {
  const IndicatorWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return const Center(
      child: SizedBox(
        width: 36,
        height: 36,
        child: CircularProgressIndicator(strokeWidth: 1.5),
      ),
    );
  }
}

class PostListItem extends StatelessWidget {
  const PostListItem({super.key, required this.post});

  final FeedPost post;

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
        child: Container(
          width: double.infinity,
          height: 560.0,
          decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(25.0),
              color: HexColor("#562C2C")),
          child: Column(
            children: <Widget>[
              Padding(
                  padding: const EdgeInsets.symmetric(vertical: 10.0),
                  child: Expanded(
                    child: Column(children: <Widget>[
                      ListTile(
                        leading: Container(
                          width: 50.0,
                          height: 50.0,
                          decoration: const BoxDecoration(
                              shape: BoxShape.circle,
                              boxShadow: [
                                BoxShadow(
                                    color: Colors.black45,
                                    offset: Offset(0, 2),
                                    blurRadius: 6.0)
                              ]),
                          child: const CircleAvatar(
                            child: ClipOval(
                              child: Image(
                                  height: 50.0,
                                  width: 50.0,
                                  fit: BoxFit.cover,
                                  image: AssetImage("assets/me.jpeg")),
                            ),
                          ),
                        ),
                        title: Text(
                          post.title,
                          style: TextStyle(
                              fontWeight: FontWeight.bold,
                              color: HexColor("#F3D8C7")),
                            ),
                        subtitle: Text('subtitle',
                            style: TextStyle(color: HexColor("#F3D8C7"))),
                        trailing: IconButton(
                          icon: Icon(Icons.more_horiz,
                              color: HexColor("#F3D8C7")),
                          onPressed: () => print('more'),
                        ),
                      ),
                      Container(
                        margin: const EdgeInsets.all(10.0),
                        width: double.infinity,
                        height: 400.0,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(25.0),
                            boxShadow: const [
                              BoxShadow(
                                  color: Colors.black45,
                                  offset: Offset(0, 5),
                                  blurRadius: 8.0)
                            ],
                            image: const DecorationImage(
                                image: AssetImage("assets/logo.png"),
                                fit: BoxFit.fitWidth)),
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Row(
                            children: <Widget>[
                              IconButton(
                                icon: Icon(Icons.favorite_border,
                                    color: HexColor("#F3D8C7")),
                                iconSize: 30.0,
                                onPressed: () => print('like post'),
                              ),
                              Text(
                                '2,515',
                                style: TextStyle(
                                    fontSize: 14.0,
                                    fontWeight: FontWeight.w600,
                                    color: HexColor("#F3D8C7")),
                              )
                            ],
                          )
                        ],
                      )
                    ]),
                  ))
            ],
          ),
        ),  
      ),
    );
  }
4ngedf3f

4ngedf3f1#

发表评论作为答案

很难使用代码片段进行测试,因为您没有提供BLoC部分。第一个想法,尝试:

  • 拆卸高度:560.0,因为你已经使用了扩展。
  • 删除ListView.builder上面的SingleChildScrollView,因为listView有自己的滚动器

相关问题