Last active
June 24, 2024 22:48
-
-
Save somtech123/60591ad6d1e91a2454bb2e0ee73502dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DashboardScreen extends StatefulWidget { | |
const DashboardScreen({super.key}); | |
@override | |
State<DashboardScreen> createState() => _DashboardScreenState(); | |
} | |
class _DashboardScreenState extends State<DashboardScreen> | |
with SingleTickerProviderStateMixin { | |
late TabController _tabController; | |
int _activeTabIndex = 0; | |
@override | |
void initState() { | |
super.initState(); | |
_tabController = TabController(length: 2, vsync: this); | |
_tabController.addListener(_setActiveTabIndex); | |
} | |
void _setActiveTabIndex() { | |
setState(() { | |
_activeTabIndex = _tabController.index; | |
}); | |
} | |
@override | |
void dispose() { | |
_tabController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return PopScope( | |
canPop: false, | |
child: Scaffold( | |
primary: false, | |
body: SafeArea( | |
child: Padding( | |
padding: EdgeInsets.symmetric(vertical: 20.w, horizontal: 20.w), | |
child: NestedScrollView( | |
headerSliverBuilder: (context, innerBoxIsScrolled) => [ | |
SliverPersistentHeader( | |
pinned: true, | |
floating: true, | |
delegate: _DashboardPersitentAppDelegate( | |
child: PreferredSize( | |
preferredSize: Size.fromHeight(kHeight(context) / 7), | |
child: DashboardHeader( | |
tabBar: Container( | |
height: 40.h, | |
padding: EdgeInsets.all(5.h), | |
decoration: BoxDecoration( | |
color: Colors.grey.withOpacity(0.3), | |
borderRadius: BorderRadius.circular(30.r)), | |
child: TabBar( | |
controller: _tabController, | |
tabs: const [ | |
Text('Discover'), | |
Text('My Match') | |
], | |
dividerColor: Colors.transparent, | |
indicatorSize: TabBarIndicatorSize.tab, | |
indicatorColor: Colors.transparent, | |
indicator: BoxDecoration( | |
gradient: Appcolors.tabBarGradient, | |
borderRadius: BorderRadius.circular(30.r), | |
), | |
unselectedLabelStyle: Theme.of(context) | |
.textTheme | |
.bodyMedium! | |
.copyWith( | |
fontSize: 16, | |
fontWeight: FontWeight.w500), | |
unselectedLabelColor: Appcolors.blackColor, | |
labelColor: Appcolors.whiteColor, | |
labelStyle: Theme.of(context) | |
.textTheme | |
.bodyMedium! | |
.copyWith( | |
fontSize: 16, | |
fontWeight: FontWeight.w500), | |
), | |
), | |
), | |
), | |
childrenHeight: kHeight(context) / 7, | |
), | |
) | |
], | |
body: TabBarView( | |
controller: _tabController, | |
children: const [], | |
)), | |
)), | |
), | |
); | |
} | |
} | |
class _DashboardPersitentAppDelegate extends SliverPersistentHeaderDelegate { | |
_DashboardPersitentAppDelegate( | |
{required this.child, | |
required this.childrenHeight, | |
double topSafeArea = 75}) | |
: _topSafeArea = topSafeArea; | |
final double _topSafeArea; | |
final double childrenHeight; | |
final PreferredSize child; | |
@override | |
Widget build( | |
BuildContext context, double shrinkOffset, bool overlapsContent) { | |
return Container( | |
decoration: const BoxDecoration(color: Appcolors.scaffoldbg), | |
child: child, | |
); | |
} | |
@override | |
double get maxExtent => child.preferredSize.height + _topSafeArea; | |
@override | |
double get minExtent => child.preferredSize.height + _topSafeArea; | |
// double get maxShrinkOffset => maxExtent - minExtent + _topSafeArea; | |
@override | |
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment