我对CustomScrollView有问题。 这是主窗口小部件的代码:
slivers: [
SliverAppBar(
expandedHeight: 414.0,
backgroundColor: Colors.white,
leadingWidth: 0.0,
leading: Container(),
flexibleSpace: _header(context, _provider),
),
SliverAppBar(
backgroundColor: Colors.white,
flexibleSpace: _tabBar(context, _provider)),
SliverList(delegate: SliverChildBuilderDelegate((context, index) => _tabs(context, _provider), childCount: 1)),
],
),
这是_tab方法代码:
_tabs(BuildContext context, UserProfileProvider _provider) {
switch (_provider.userTab) {
case 0:
return _GridView();
case 1:
return _trophyChart(context, _provider);
case 2:
return _achivements(BuildContext context, UserProfileProvider _provider)
}
}
当我尝试从_achivements返回小部件时,出现错误。如果将小部件从_achivements放置到主小部件,则错误消失。但是在我的项目中,条子必须是动态的。
我还尝试过将_achivenets的碎片作为列表返回,并返回每个小部件,例如:
_achivements(BuildContext context, UserProfileProvider _provider).forEach((element) => element)
以下是_achivements的源代码:
List<Widget> _achivements(BuildContext context, UserProfileProvider _provider) {
return [
SliverAppBar(
backgroundColor: ThemeDefaults.primaryColor,
pinned: true,
leading: Container(),
bottom: PreferredSize(
preferredSize: Size(100, 0),
child: DefaultTabController(
length: 2,
child: TabBar(
indicatorColor: Colors.white,
unselectedLabelStyle: GoogleFonts.raleway(
fontSize: 14.0,
fontWeight: FontWeight.w500,
color: Colors.white.withOpacity(0.9)),
labelStyle: GoogleFonts.raleway(
fontSize: 14.0,
fontWeight: FontWeight.w600,
color: Colors.white),
tabs: [
Tab(text: 'IN PROGRESS'),
Tab(text: 'COMPLETED'),
],
),
),
),
),
SliverAppBar(
pinned: true,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
expandedHeight: 40.0,
leading: Container(),
flexibleSpace: Padding(
padding: EdgeInsets.symmetric(horizontal: 28.0, vertical: 15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Completed IRLAs',
style: GoogleFonts.raleway(
fontFeatures: [FontFeature.enable('lnum')],
fontSize: 24.0,
fontWeight: FontWeight.bold,
color: Colors.black),
),
GestureDetector(
onTap: () => showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return GestureDetector(
onTap: () => Navigator.pop(context),
child: DraggableScrollableSheet(
initialChildSize: 0.1,
maxChildSize: 1.0,
minChildSize: 0.1,
builder: (BuildContext context,
ScrollController scrollController) {
return Container(
height: 100.0,
color: Colors.white,
child: Text('123'),
);
},
),
);
},
),
child: Container(
child: SvgPicture.asset('assets/img/filter.svg'),
),
)
],
),
),
),
SliverGrid(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
margin: EdgeInsets.all(10.0),
decoration: BoxDecoration(color: Colors.white, boxShadow: [
BoxShadow(
color: ThemeDefaults.inactiveColor,
offset: Offset(0, 2),
blurRadius: 2.0,
spreadRadius: 0.0)
]),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CircleAvatar(
radius: 40,
backgroundImage: NetworkImage(
_provider.mockedTrophies[index].imageURL),
child: Align(
alignment: Alignment.bottomRight,
child: _provider.mockedTrophies[index].trophyType ==
TrophyType.verified
? Image.asset(
'assets/img/checkmark_verified.png',
width: 24.0,
)
: null, //_getUserCheckMark(),
),
),
SizedBox(
height: 18,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
_provider.mockedTrophies[index].name,
style: GoogleFonts.raleway(
fontFeatures: [FontFeature.enable('lnum')],
fontSize: 18,
fontWeight: FontWeight.bold),
),
],
),
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'${_provider.mockedTrophies[index].points} points',
style: GoogleFonts.raleway(
fontFeatures: [FontFeature.enable('lnum')],
fontSize: 16.84,
fontWeight: FontWeight.normal),
),
],
),
],
),
),
);
},
childCount: _provider.mockedTrophies.length,
),
),
];
}
我不知道该如何解决。如果有人有主意,请帮忙。