为什么 sliverlist 在我的 customscrollview 中不起作用?
Why is sliverlist not working in my customscrollview?
我正在尝试添加一个 sliverlist,但它对我不起作用,我对使用 flutter 很陌生,我很困惑。
@override
Widget build(BuildContext context) {
return Scaffold(
body: const CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('Sample Slivers'),
leading: Icon(Icons.menu),
backgroundColor: Colors.orangeAccent,
expandedHeight: 90.0,
floating: true,
pinned: true,
snap: false,
),
SliverList(
delegate: SliverChildBuilderDelegate((context) {}),
)
],
),
bottomNavigationBar: _navigatorAppBar(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: _buildFab(),
);
}
}
删除 CustomScrollView
的 const
关键字。
将SliverChildBuilderDelegate((context) {})
替换为:
SliverChildBuilderDelegate((context, index) {})
完整代码:
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('Sample Slivers'),
leading: Icon(Icons.menu),
backgroundColor: Colors.orangeAccent,
expandedHeight: 90.0,
floating: true,
pinned: true,
snap: false,
),
SliverList(
delegate: SliverChildBuilderDelegate((context, index) {}),
)
],
),
bottomNavigationBar: _navigatorAppBar(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: _buildFab(),
);
}
我正在尝试添加一个 sliverlist,但它对我不起作用,我对使用 flutter 很陌生,我很困惑。
@override
Widget build(BuildContext context) {
return Scaffold(
body: const CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('Sample Slivers'),
leading: Icon(Icons.menu),
backgroundColor: Colors.orangeAccent,
expandedHeight: 90.0,
floating: true,
pinned: true,
snap: false,
),
SliverList(
delegate: SliverChildBuilderDelegate((context) {}),
)
],
),
bottomNavigationBar: _navigatorAppBar(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: _buildFab(),
);
}
}
删除
CustomScrollView
的const
关键字。将
SliverChildBuilderDelegate((context) {})
替换为:
SliverChildBuilderDelegate((context, index) {})
完整代码:
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('Sample Slivers'),
leading: Icon(Icons.menu),
backgroundColor: Colors.orangeAccent,
expandedHeight: 90.0,
floating: true,
pinned: true,
snap: false,
),
SliverList(
delegate: SliverChildBuilderDelegate((context, index) {}),
)
],
),
bottomNavigationBar: _navigatorAppBar(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: _buildFab(),
);
}