how para implementar un sliverAppBar con un tabBar
el documento de aleteo muestra unamanifestació paraSliverAppBar
+ TabBar
+ TabBarView with ListView
utilizarNestedScrollView
, y es un poco complejo, por lo que me pregunto si existe una manera simple y clara de implementarlo. Intenté esto:
CustomScrollView
slivers:
SliverAPPBar
bottom: TabBar
TabBarView
children: MyWidget(list or plain widget)
got error:
flutter: se lanzó la siguiente afirmación Building Scrollable (axisDirection: right, física:
flutter: un RenderViewport esperaba un hijo del tipo RenderSliver pero recibió un hijo del tipo _RenderExcludableScrollSemantics.
flutter: RenderObjects esperan tipos específicos de niños porque se coordinan con sus hijos durante el diseño y la pintura. Por ejemplo, un RenderSliver no puede ser hijo de un RenderBox porque un RenderSliver no comprende el protocolo de diseño de RenderBox.
flutter: se lanzó otra excepción: 'paquete: flutter / src / widgets / framework.dart': Afirmación fallida: línea 3497 pos 14: 'propietario._debugCurrentBuildTarget == esto': no es cierto.
AQUÍ ESTÁ MI CÓDIGO:
import 'package:flutter/material.dart';
main(List<String> args) {
runApp(MyScrollTabListApp());
}
class MyScrollTabListApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(title: "aa", home: MyScrollTabListHomePage());
}
}
class MyScrollTabListHomePage extends StatefulWidget {
@override
MyScrollTabListHomePageState createState() {
return new MyScrollTabListHomePageState();
}
}
class MyScrollTabListHomePageState extends State<MyScrollTabListHomePage>
with SingleTickerProviderStateMixin {
final int _listItemCount = 300;
final int _tabCount = 8;
TabController _tabController;
@override
void initState() {
_tabController = TabController(length: _tabCount, vsync: this);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight: 240.0,
title: Text("Title"),
pinned: true,
bottom: TabBar(
controller: _tabController,
isScrollable: true,
tabs: List<Tab>.generate(_tabCount, (int i) {
return Tab(text: "TAB$i");
}),
),
),
TabBarView(
controller: _tabController,
children: List<Widget>.generate(_tabCount, (int i) {
return Text('line $i');
}),
),
],
),
);
}
}
y para la demostración oficial, usa una estructura como esta
DefaultTabController
NestedScrollView
headerSliverBuilder
SliverOverlapAbsorber
handle
SliverAppBar
TabBarView
CustomScrollView
SliverOverlapInjector
handle
SliverPadding