这是我的代码想要实现自定义标题,当用户滚动时该标题会上升。 并将选项卡栏粘贴到顶部和底部视图小部件将显示.. 对于我的用户 Sliver Widgets..
这是代码 Snaipts。
class ProfileMyGroupDetailsScreen extends StatefulWidget {
const ProfileMyGroupDetailsScreen({Key? key}) : super(key: key);
@override
State<ProfileMyGroupDetailsScreen> createState() => _ProfileMyGroupDetailsScreenState();
}
class _ProfileMyGroupDetailsScreenState extends State<ProfileMyGroupDetailsScreen> with SingleTickerProviderStateMixin {
TabController? _tabController;
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_tabController = TabController(initialIndex: 0, length: 4, vsync: this);
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: CustomChatAppBar(
title: AppLabels.myGroupDetails,
systemOverlayStyle: Global.whiteOverLay,
actions: [],
),
body: buildDataTabWidget(),
);
}
DefaultTabController buildDataTabWidget() {
return DefaultTabController(
length: 4,
child: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: Column(
children: [
ListTileType1(
padding: padXY(24, 8.5),
imageUrl: AppImages.dummyProfileImage1,
imageWidth: 44,
imageHeight: 44,
title1: 'Meme team',
title2: 'Jack & Chris',
),
Padding(
padding: padXY(24, 16),
child: CustomImage(
imageUrl: AppImages.dummyProfileImage1,
height: MediaQuery.of(context).size.width - (24 * 2),
width: MediaQuery.of(context).size.width,
fit: BoxFit.cover,
borderRadius: 12,
),
),
],
),
),
SliverPersistentHeader(
pinned: true,
delegate: _SliverAppBarDelegate(
TabBar(
controller: _tabController,
dividerColor: AppColors.kBorderColor,
dividerHeight: 2,
isScrollable: true,
padding: EdgeInsets.zero,
tabAlignment: TabAlignment.center,
indicatorSize: TabBarIndicatorSize.tab,
indicatorWeight: 1,
labelColor: AppColors.kSecondaryColor,
unselectedLabelColor: AppColors.kAppGrey,
labelStyle: context.bodyLarge.w500,
unselectedLabelStyle: context.bodyLarge,
onTap: (index) {
// moduleDetailController.selectedIndex.value = index;
// moduleDetailController.selectedIndex.refresh();
},
tabs: [
Tab(text: AppLabels.basicInformation),
Tab(text: AppLabels.myLikes),
Tab(text: AppLabels.matches),
Tab(text: AppLabels.sentRequests),
],
),
),
),
SliverFillRemaining(
child: TabBarView(
controller: _tabController,
children: [
BuildBasicInfoTab(),
MyLikeTab(),
MatchesTab(),
SentRequestTab(),
],
),
)
],
),
);
}
}
我制作了自定义委托方法来粘贴选项卡栏
class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
_SliverAppBarDelegate(this._tabBar);
final TabBar _tabBar;
@override
double get minExtent => _tabBar.preferredSize.height;
@override
double get maxExtent => _tabBar.preferredSize.height;
@override
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
return Container(color: AppColors.kWhiteColor, child: _tabBar);
}
@override
bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
return false;
}
}
但主要问题是,当标签栏固定点击后,它会滚动到它下面。
然后无法缩小内容。
请帮助我如何实现这些类型的用户界面?
您应该在
NestedScrollView
中使用 CustomScrollView
而不是 DefaultTabController
。在 headerSliverBuilder
内,将 CustomChatAppBar
小部件放入 SliverAppBar
内,然后放置 SliverPersistentHeader
小部件。最后,在正文中包含 TabBarView
小部件。