SliverAppBar无法滚动
SliverAppBar和SliverList无法滚动,只能在根脚手架内正常工作,否则不能滚动任何东西
问题代码
return CupertinoApp(
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
title: 'Flutter Demo',
theme: CupertinoThemeData(
primaryColor: Colors.blue,
),
home: Scaffold(
body: Center(
child: Stack(
children: [
CustomScrollView(
controller: ScrollController(initialScrollOffset: 0),
physics: BouncingScrollPhysics(),
shrinkWrap: true,
slivers: <Widget>[
SliverAppBar(
floating: true,
pinned: false,
snap: false,
flexibleSpace: FlexibleSpaceBar(
background: Image.asset("assets/images/wxbg.png"),
),
expandedHeight: 156,
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) => ListTile(
title: Text(
"你们啊,naive",
style: TextStyle(fontSize: 20.0),
),
),
childCount: 20,
))
],
),
PreferredSize(
child: Container(
width: double.infinity,
height: double.infinity,
decoration: BoxDecoration(color: Colors.transparent),
child: SafeArea(
child: AppBar(
centerTitle: true,
elevation: 0,
backgroundColor: Colors.transparent,
title: Text("?"),
leading: IconButton(
icon: Icon(Icons.backspace), onPressed: () => {}),
)),
),
preferredSize: Size(double.infinity, 50)),
],
)),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: SvgPicture.asset("assets/images/test.svg",
height: 30, width: 30),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(
Icons.business,
size: 30,
),
title: Text('Business'),
),
BottomNavigationBarItem(
icon: Icon(
Icons.school,
size: 30,
),
title: Text('School'),
),
],
currentIndex: state.selectedIndex,
selectedItemColor: Colors.amber[800],
)),
debugShowCheckedModeBanner: false,
);
做得好
return CupertinoApp(
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
title: 'Flutter Demo',
theme: CupertinoThemeData(
primaryColor: Colors.blue,
),
home: Scaffold(
body:CustomScrollView( //
controller: ScrollController(initialScrollOffset: 0),
physics: BouncingScrollPhysics(),
shrinkWrap: true,
slivers: <Widget>[
SliverAppBar(
floating: true,
pinned: false,
snap: false,
flexibleSpace: FlexibleSpaceBar(
background: Image.asset("assets/images/wxbg.png"),
),
expandedHeight: 156,
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) => ListTile(
title: Text(
"你们啊,naive",
style: TextStyle(fontSize: 20.0),
),
),
childCount: 20,
))
],
)),
debugShowCheckedModeBanner: false,
);
为什么必须在根层中使用SliverAppBar?我如何像android片段工具栏一样使用它,产生崩溃效果,我只学习了一周的颤振,有人可以帮助我吗?