listView赢得了滚动中的滚动

发布于 2025-02-11 07:58:41 字数 2347 浏览 1 评论 0 原文

我尝试创建一个可滚动的ListView,但由于各种原因,它无法正常工作。

我的目标是:创建一个连接到Firebase的列表视图。我的listView收集良好的数据,但是scoll是不可能的。

我的脚手架的身体:

body: const SingleChildScrollView(
  child: RecipesInformations(),
),

我的小部件:

@override
  Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
      stream: _recipesStream,
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError) {
          return const Text('Something went wrong');
        }

        if (snapshot.connectionState == ConnectionState.waiting) {
          return const Text("Chargement recettes");
        }

        return ListView(
          shrinkWrap: true,
          children: snapshot.data!.docs.map((DocumentSnapshot document) {
            Map<String, dynamic> data =
                document.data()! as Map<String, dynamic>;
            List tags = List.from(document["tags"]);

            return Container(
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border.all(color: const Color(0xFF011200)),
                    borderRadius: const BorderRadius.all(Radius.circular(8))),
                margin: const EdgeInsets.only(
                    bottom: 32, left: 16, right: 16, top: 8),
                padding: const EdgeInsets.all(32),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          data["title"],
                          overflow: TextOverflow.fade,
                          maxLines: 1,
                          softWrap: false,
                          style: Theme.of(context).textTheme.headline1,
                        )
                      ],
                    ),
                  ],
                ));
          }).toList(),
        );
      },
    );
  }

让我知道您是否需要更多信息。

I try to create a scrollable ListView, but for somes reasons it's not working.

My goal: create a ListView connected to Firebase. My ListView gather well datas, but scoll is impossible.

The body of my Scaffold:

body: const SingleChildScrollView(
  child: RecipesInformations(),
),

My widget:

@override
  Widget build(BuildContext context) {
    return StreamBuilder<QuerySnapshot>(
      stream: _recipesStream,
      builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (snapshot.hasError) {
          return const Text('Something went wrong');
        }

        if (snapshot.connectionState == ConnectionState.waiting) {
          return const Text("Chargement recettes");
        }

        return ListView(
          shrinkWrap: true,
          children: snapshot.data!.docs.map((DocumentSnapshot document) {
            Map<String, dynamic> data =
                document.data()! as Map<String, dynamic>;
            List tags = List.from(document["tags"]);

            return Container(
                decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border.all(color: const Color(0xFF011200)),
                    borderRadius: const BorderRadius.all(Radius.circular(8))),
                margin: const EdgeInsets.only(
                    bottom: 32, left: 16, right: 16, top: 8),
                padding: const EdgeInsets.all(32),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          data["title"],
                          overflow: TextOverflow.fade,
                          maxLines: 1,
                          softWrap: false,
                          style: Theme.of(context).textTheme.headline1,
                        )
                      ],
                    ),
                  ],
                ));
          }).toList(),
        );
      },
    );
  }

Let me know if you need more informations.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萌︼了一个春 2025-02-18 07:58:41

删除 SinglechildScrollview 可能会有所帮助。

Removing SingleChildScrollView might help.

南风几经秋 2025-02-18 07:58:41

使用 listView.builder.builder 简化事物并删除未经必要的嵌套scrolllviews 。这样的事情可以起作用:

body: RecipesInformations(),
Widget build(BuildContext context) {
  return StreamBuilder<QuerySnapshot>(
    stream: _recipesStream,
    builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
...
      return ListView.builder(
        itemCount: snapshot.data!.docs.length,
        itemBuilder: (context, index) {
          final document = snapshot.data!.docs[index];
          return Container(
            ...
          );
        },
      ) 
...

Use ListView.builder to simplify things and remove unnecessary nested scrollviews. Something like this could work:

body: RecipesInformations(),
Widget build(BuildContext context) {
  return StreamBuilder<QuerySnapshot>(
    stream: _recipesStream,
    builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
...
      return ListView.builder(
        itemCount: snapshot.data!.docs.length,
        itemBuilder: (context, index) {
          final document = snapshot.data!.docs[index];
          return Container(
            ...
          );
        },
      ) 
...
尐籹人 2025-02-18 07:58:41

您需要使用 futorbuilder 代替 streambuilder

cream> streambuilder 是一个基于与流的交互的最新快照。

取而代之的是,将流转换为 tolist(tolist()) 方法并在 futurebuilder.future.future.future so:

    ...

    return FutureBuilder<List<QuerySnapshot>>(
      future: _recipesStream.toList(),
      builder: (BuildContext context, snapshot) {

    ...

snapshot.data 现在是 list> list QUERYSNAPSHOT 。因此,它将与迭代上的迭代有所不同:

      ...

      return ListView(
        shrinkWrap: true,
        children: snapshot.data!.map((query) {
          Map<String, dynamic> data = query.docs.first;

      ...

结果将是这样的东西:

“在此处输入图像说明”

You'd need to use FutureBuilder instead of StreamBuilder.

From the docs, the StreamBuilder is a Widget that builds itself based on the latest snapshot of interaction with a Stream. So, only the last item is going to show up on the screen.

Instead, transform the stream to a List with the toList() method and use it on the FutureBuilder.future property like so:

    ...

    return FutureBuilder<List<QuerySnapshot>>(
      future: _recipesStream.toList(),
      builder: (BuildContext context, snapshot) {

    ...

snapshot.data now is a List of QuerySnapshot. So, it's going to be a bit different to iterate over it:

      ...

      return ListView(
        shrinkWrap: true,
        children: snapshot.data!.map((query) {
          Map<String, dynamic> data = query.docs.first;

      ...

The result is going to be something like this:

enter image description here

淡看悲欢离合 2025-02-18 07:58:41

在您 listView 构造函数中,set primary:false ,因为您将其嵌套在 singlechildscrollview 中。

In you ListViewconstructor, set primary: false since you are nesting it inside of a SingleChildScrollView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文