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,>
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
conPagedSliverList
, lo cual crea unRenderSliverList
. Sin embargo,SliverAppBar
espera un hijo de tipoRenderBox
. Para solucionar esto, puedes envolver tuMyListWidget
con el widgetSliverToBoxAdapter
, así:En el segundo bloque de código, estás usando
SliverFillRemaining
conTabBarView
, lo cual crea unRenderSliverFillRemainingWithScrollable
. Sin embargo,Scaffold
ya tiene unNestedScrollView
, el cual crea su propia instancia deRenderSliverFillRemainingWithScrollable
. Para solucionar esto, puedes eliminarSliverFillRemaining
y usarTabBarView
directamente como hijo deNestedScrollView
, así:Esto debería solucionar los errores que estabas recibiendo.