这是我的代码。当我向下滚动时,Appbar 保持静止。如果您需要更多代码,请告诉我。
我正在使用 auto_route 颤振,并且路由 InvestHomeRouter() 和 BonusHomeRouter() 导致其他没有自己的 appbar 并且具有 singleChildScrollviews 作为主体的脚手架。
如果子脚手架检测到任何向下滚动,我希望父脚手架隐藏 appbar。
class Home extends StatelessWidget {
`const Home({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return SafeArea(
child: AutoTabsRouter(
routes: [
InvestHomeRouter(),
BonusHomeRouter()
],
builder: (context, child, animation) {
final tabsRouter = AutoTabsRouter.of(context);
return HomeScaffold(
tabsRouter: tabsRouter,
child: child,
animation: animation,
);
}));
}
}
class HomeScaffold extends StatefulWidget {
HomeScaffold(
{required this.tabsRouter,
required this.animation,
required this.child,
Key? key})
: super(key: key);
final Widget child;
final Animation<double> animation;
final TabsRouter tabsRouter;
@override
State<HomeScaffold> createState() => _HomeScaffoldState();
}
class _HomeScaffoldState extends State<HomeScaffold> {
int activeIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverAppBar(
floating: true,
],
),
],
body: FadeTransition(
opacity: widget.animation,
child: widget.child),
),
);
}