es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Flutter – ¿cómo usar SliverAppBar con paginación de desplazamiento infinito?

Estoy utilizando el complemento “Infinite Scroll Pagination” en mi aplicación de flutter. También necesito usar SilverAppBar en mi página. Este es mi código:


return Scaffold( body: DefaultTabController( length: 2, child: NestedScrollView( headerSliverBuilder: (context, value) { return [ SliverAppBar( bottom: TabBar( tabs: [ Tab(icon: Icon(Icons.call), text: "1"), Tab(icon: Icon(Icons.message), text: "2"), ], ), ), ]; }, body: TabBarView( children: [ const MyListWidget(), Text('2') ], ), ), ), );

Este es mi MyListWidget:

Widget build(BuildContext context) {
  return PagedSliverList<int, mymodel="">(
    pagingController: _сontroller,
    builderDelegate: PagedChildBuilderDelegate<mymodel>(
      itemBuilder: (context, item, index) {
        return Text(item.Title);
      },
    ),
  );
}

Pero tengo un error:

“A RenderRepaintBoundary expected a child of type RenderBox but received a child of type RenderSliverList.”

También intenté esto:

body: SliverFillRemaining(
  child: TabBarView(
    children: [
      const ProfileSelections(),
      //Container(child: Text('1')),
      Text('2')
    ],
  ),
)

Pero tengo un error:

“A RenderSliverFillRemainingWithScrollable expected a child of type RenderBox but received a child of type RenderSliverFillRemainingWithScrollable.”

¿Cómo puedo solucionar estos errores? Cualquier consejo sería agradecido.</int,>

Tags:  , , ,

Answer

  1. Avatar for davy.ai

    Los errores que estás recibiendo se deben a conflictos en los tipos de widgets que estás usando en tu código.

    En el primer bloque de código, se está usando MyListWidget con PagedSliverList, lo cual crea un RenderSliverList. Sin embargo, SliverAppBar espera un hijo de tipo RenderBox. Para solucionar esto, puedes envolver tu MyListWidget con el widget SliverToBoxAdapter, así:

    body: TabBarView(
      children: [
        SliverToBoxAdapter(child: const MyListWidget()),
        Text('2'),
      ],
    ),
    

    En el segundo bloque de código, estás usando SliverFillRemaining con TabBarView, lo cual crea un RenderSliverFillRemainingWithScrollable. Sin embargo, Scaffold ya tiene un NestedScrollView, el cual crea su propia instancia de RenderSliverFillRemainingWithScrollable. Para solucionar esto, puedes eliminar SliverFillRemaining y usar TabBarView directamente como hijo de NestedScrollView, así:

    return Scaffold(
      body: DefaultTabController(
        length: 2,
        child: NestedScrollView(
          headerSliverBuilder: (context, value) {
            return [
              SliverAppBar(
                bottom: TabBar(
                  tabs: [
                    Tab(icon: Icon(Icons.call), text: "1"),
                    Tab(icon: Icon(Icons.message), text: "2"),
                  ],
                ),
              ),
            ];
          },
          body: TabBarView(
            children: [
              SliverToBoxAdapter(child: const MyListWidget()),
              Text('2'),
            ],
          ),
        ),
      ),
    );
    

    Esto debería solucionar los errores que estabas recibiendo.

Comments are closed.