feat: pull to refresh on home
This commit is contained in:
parent
5a83bc4049
commit
3f75bffd09
@ -67,119 +67,126 @@ class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: AppColor.background,
|
backgroundColor: AppColor.background,
|
||||||
body: BlocBuilder<HomeBloc, HomeState>(
|
body: RefreshIndicator(
|
||||||
builder: (context, state) {
|
onRefresh: () {
|
||||||
return CustomScrollView(
|
context.read<HomeBloc>().add(HomeEvent.fetchedDashboard());
|
||||||
physics: const BouncingScrollPhysics(
|
return Future.value();
|
||||||
parent: ClampingScrollPhysics(),
|
},
|
||||||
),
|
child: BlocBuilder<HomeBloc, HomeState>(
|
||||||
slivers: [
|
builder: (context, state) {
|
||||||
// SliverAppBar with HomeHeader as background
|
return CustomScrollView(
|
||||||
SliverAppBar(
|
physics: const BouncingScrollPhysics(
|
||||||
expandedHeight: 260, // Adjust based on HomeHeader height
|
parent: ClampingScrollPhysics(),
|
||||||
floating: true,
|
),
|
||||||
pinned: true,
|
slivers: [
|
||||||
snap: true,
|
// SliverAppBar with HomeHeader as background
|
||||||
elevation: 0,
|
SliverAppBar(
|
||||||
scrolledUnderElevation: 8,
|
expandedHeight: 260, // Adjust based on HomeHeader height
|
||||||
backgroundColor: AppColor.primary,
|
floating: true,
|
||||||
surfaceTintColor: Colors.transparent,
|
pinned: true,
|
||||||
flexibleSpace: LayoutBuilder(
|
snap: true,
|
||||||
builder: (BuildContext context, BoxConstraints constraints) {
|
elevation: 0,
|
||||||
// Calculate collapse progress (0.0 = expanded, 1.0 = collapsed)
|
scrolledUnderElevation: 8,
|
||||||
final double expandedHeight = 200;
|
backgroundColor: AppColor.primary,
|
||||||
final double collapsedHeight =
|
surfaceTintColor: Colors.transparent,
|
||||||
kToolbarHeight + MediaQuery.of(context).padding.top;
|
flexibleSpace: LayoutBuilder(
|
||||||
final double currentHeight = constraints.maxHeight;
|
builder: (BuildContext context, BoxConstraints constraints) {
|
||||||
|
// Calculate collapse progress (0.0 = expanded, 1.0 = collapsed)
|
||||||
|
final double expandedHeight = 200;
|
||||||
|
final double collapsedHeight =
|
||||||
|
kToolbarHeight + MediaQuery.of(context).padding.top;
|
||||||
|
final double currentHeight = constraints.maxHeight;
|
||||||
|
|
||||||
double collapseProgress =
|
double collapseProgress =
|
||||||
1.0 -
|
1.0 -
|
||||||
((currentHeight - collapsedHeight) /
|
((currentHeight - collapsedHeight) /
|
||||||
(expandedHeight - collapsedHeight));
|
(expandedHeight - collapsedHeight));
|
||||||
collapseProgress = collapseProgress.clamp(0.0, 1.0);
|
collapseProgress = collapseProgress.clamp(0.0, 1.0);
|
||||||
|
|
||||||
return FlexibleSpaceBar(
|
return FlexibleSpaceBar(
|
||||||
title: Opacity(
|
title: Opacity(
|
||||||
opacity: collapseProgress, // Title muncul saat collapse
|
opacity:
|
||||||
child: Row(
|
collapseProgress, // Title muncul saat collapse
|
||||||
children: [
|
child: Row(
|
||||||
Expanded(
|
children: [
|
||||||
child: Text(
|
Expanded(
|
||||||
AppConstant.appName,
|
child: Text(
|
||||||
style: AppStyle.xl.copyWith(
|
AppConstant.appName,
|
||||||
fontWeight: FontWeight.w700,
|
style: AppStyle.xl.copyWith(
|
||||||
fontSize: 18,
|
fontWeight: FontWeight.w700,
|
||||||
letterSpacing: -0.5,
|
fontSize: 18,
|
||||||
color: AppColor.white,
|
letterSpacing: -0.5,
|
||||||
|
color: AppColor.white,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
ActionIconButton(
|
||||||
ActionIconButton(
|
onTap: () {},
|
||||||
onTap: () {},
|
icon: LineIcons.bell,
|
||||||
icon: LineIcons.bell,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
titlePadding: const EdgeInsets.only(
|
|
||||||
left: 20,
|
|
||||||
right: 12,
|
|
||||||
bottom: 16,
|
|
||||||
),
|
|
||||||
background: AnimatedBuilder(
|
|
||||||
animation: _headerAnimationController,
|
|
||||||
builder: (context, child) {
|
|
||||||
return Transform.translate(
|
|
||||||
offset: Offset(
|
|
||||||
0,
|
|
||||||
50 * (1 - _headerAnimationController.value),
|
|
||||||
),
|
|
||||||
child: Opacity(
|
|
||||||
opacity: _headerAnimationController.value,
|
|
||||||
child: HomeHeader(
|
|
||||||
totalRevenue:
|
|
||||||
state.dashboard.overview.totalSales,
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
);
|
),
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
// Main Content
|
|
||||||
SliverToBoxAdapter(
|
|
||||||
child: AnimatedBuilder(
|
|
||||||
animation: _contentAnimationController,
|
|
||||||
builder: (context, child) {
|
|
||||||
return Transform.translate(
|
|
||||||
offset: Offset(
|
|
||||||
0,
|
|
||||||
30 * (1 - _contentAnimationController.value),
|
|
||||||
),
|
|
||||||
child: Opacity(
|
|
||||||
opacity: _contentAnimationController.value,
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
HomeFeature(),
|
|
||||||
HomeStats(overview: state.dashboard.overview),
|
|
||||||
HomeTopProduct(
|
|
||||||
products: state.dashboard.topProducts,
|
|
||||||
),
|
|
||||||
const SpaceHeight(40),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
titlePadding: const EdgeInsets.only(
|
||||||
);
|
left: 20,
|
||||||
},
|
right: 12,
|
||||||
|
bottom: 16,
|
||||||
|
),
|
||||||
|
background: AnimatedBuilder(
|
||||||
|
animation: _headerAnimationController,
|
||||||
|
builder: (context, child) {
|
||||||
|
return Transform.translate(
|
||||||
|
offset: Offset(
|
||||||
|
0,
|
||||||
|
50 * (1 - _headerAnimationController.value),
|
||||||
|
),
|
||||||
|
child: Opacity(
|
||||||
|
opacity: _headerAnimationController.value,
|
||||||
|
child: HomeHeader(
|
||||||
|
totalRevenue:
|
||||||
|
state.dashboard.overview.totalSales,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
// Main Content
|
||||||
);
|
SliverToBoxAdapter(
|
||||||
},
|
child: AnimatedBuilder(
|
||||||
|
animation: _contentAnimationController,
|
||||||
|
builder: (context, child) {
|
||||||
|
return Transform.translate(
|
||||||
|
offset: Offset(
|
||||||
|
0,
|
||||||
|
30 * (1 - _contentAnimationController.value),
|
||||||
|
),
|
||||||
|
child: Opacity(
|
||||||
|
opacity: _contentAnimationController.value,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
HomeFeature(),
|
||||||
|
HomeStats(overview: state.dashboard.overview),
|
||||||
|
HomeTopProduct(
|
||||||
|
products: state.dashboard.topProducts,
|
||||||
|
),
|
||||||
|
const SpaceHeight(40),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,10 @@ class HomeTopProduct extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
if (products.isEmpty) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
vertical: 24,
|
vertical: 24,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user