From e7525238fe0b2e78c03e1b63d3ce4cb520bcb135 Mon Sep 17 00:00:00 2001 From: efrilm Date: Sat, 16 Aug 2025 19:56:45 +0700 Subject: [PATCH] feat: current user --- .../pages/home/widgets/header.dart | 86 ++++++----- .../pages/profile/profile_page.dart | 146 +++++++++--------- .../pages/profile/widgets/account_info.dart | 36 ++--- .../pages/profile/widgets/header.dart | 9 +- 4 files changed, 139 insertions(+), 138 deletions(-) diff --git a/lib/presentation/pages/home/widgets/header.dart b/lib/presentation/pages/home/widgets/header.dart index 2ba3973..dc74720 100644 --- a/lib/presentation/pages/home/widgets/header.dart +++ b/lib/presentation/pages/home/widgets/header.dart @@ -1,9 +1,13 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'dart:math' as math; +import '../../../../application/auth/auth_bloc.dart'; +import '../../../../common/constant/app_constant.dart'; import '../../../../common/extension/extension.dart'; import '../../../../common/painter/wave_painter.dart'; import '../../../../common/theme/theme.dart'; +import '../../../../domain/auth/auth.dart'; import '../../../components/spacer/spacer.dart'; class HomeHeader extends StatefulWidget { @@ -102,43 +106,47 @@ class _HomeHeaderState extends State with TickerProviderStateMixin { @override Widget build(BuildContext context) { - return AnimatedBuilder( - animation: Listenable.merge([ - _particleController, - _waveController, - _breathController, - ]), - builder: (context, child) { - return Container( - height: 280, - decoration: BoxDecoration( - gradient: LinearGradient( - colors: [ - AppColor.primary, - AppColor.primaryLight, - AppColor.primaryLight.withOpacity(0.8), - ], - begin: Alignment.topLeft, - end: Alignment.bottomRight, - stops: const [0.0, 0.7, 1.0], - ), - boxShadow: [ - BoxShadow( - color: AppColor.primary.withOpacity(0.3), - blurRadius: 20, - offset: const Offset(0, 10), + return BlocBuilder( + builder: (context, state) { + return AnimatedBuilder( + animation: Listenable.merge([ + _particleController, + _waveController, + _breathController, + ]), + builder: (context, child) { + return Container( + height: 280, + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + AppColor.primary, + AppColor.primaryLight, + AppColor.primaryLight.withOpacity(0.8), + ], + begin: Alignment.topLeft, + end: Alignment.bottomRight, + stops: const [0.0, 0.7, 1.0], + ), + boxShadow: [ + BoxShadow( + color: AppColor.primary.withOpacity(0.3), + blurRadius: 20, + offset: const Offset(0, 10), + ), + ], ), - ], - ), - child: Stack( - children: [ - // Enhanced animated background - _buildAnimatedBackground(), + child: Stack( + children: [ + // Enhanced animated background + _buildAnimatedBackground(), - // Main content - SafeArea(child: _buildContent(context)), - ], - ), + // Main content + SafeArea(child: _buildContent(context, state.user)), + ], + ), + ); + }, ); }, ); @@ -255,7 +263,7 @@ class _HomeHeaderState extends State with TickerProviderStateMixin { ); } - Widget _buildContent(BuildContext context) { + Widget _buildContent(BuildContext context, User user) { String greeting(BuildContext context) { final hour = DateTime.now().hour; @@ -291,7 +299,7 @@ class _HomeHeaderState extends State with TickerProviderStateMixin { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - 'AppSkel POS Owner', + AppConstant.appName, style: AppStyle.lg.copyWith( color: AppColor.white.withOpacity(0.9), fontWeight: FontWeight.w600, @@ -307,7 +315,7 @@ class _HomeHeaderState extends State with TickerProviderStateMixin { ), const SpaceHeight(2), Text( - 'Manager', + user.role.toTitleCase, style: AppStyle.sm.copyWith( color: AppColor.white.withOpacity(0.7), fontSize: 11, @@ -383,7 +391,7 @@ class _HomeHeaderState extends State with TickerProviderStateMixin { ), const SpaceHeight(2), Text( - 'Vira Vania! 👋', + '${user.name}! 👋', style: AppStyle.h4.copyWith( color: AppColor.white, fontWeight: FontWeight.w800, diff --git a/lib/presentation/pages/profile/profile_page.dart b/lib/presentation/pages/profile/profile_page.dart index 8d1a577..066f418 100644 --- a/lib/presentation/pages/profile/profile_page.dart +++ b/lib/presentation/pages/profile/profile_page.dart @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:line_icons/line_icons.dart'; import 'package:loader_overlay/loader_overlay.dart'; +import '../../../application/auth/auth_bloc.dart'; import '../../../application/auth/logout_form/logout_form_bloc.dart'; import '../../../common/theme/theme.dart'; import '../../../injection.dart'; @@ -49,78 +50,85 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper { }, ), ], - child: Scaffold( - backgroundColor: AppColor.background, - body: CustomScrollView( - slivers: [ - SliverAppBar( - backgroundColor: AppColor.primary, - elevation: 0, - pinned: true, - expandedHeight: 264.0, - flexibleSpace: LayoutBuilder( - builder: (BuildContext context, BoxConstraints constraints) { - // Calculate the collapse ratio - final double top = constraints.biggest.height; - final double collapsedHeight = - MediaQuery.of(context).padding.top + kToolbarHeight; - final double expandedHeight = 264.0; - final double shrinkRatio = - ((expandedHeight - top) / - (expandedHeight - collapsedHeight)) - .clamp(0.0, 1.0); + child: BlocBuilder( + builder: (context, state) { + return Scaffold( + backgroundColor: AppColor.background, + body: CustomScrollView( + slivers: [ + SliverAppBar( + backgroundColor: AppColor.primary, + elevation: 0, + pinned: true, + expandedHeight: 264.0, + flexibleSpace: LayoutBuilder( + builder: + (BuildContext context, BoxConstraints constraints) { + // Calculate the collapse ratio + final double top = constraints.biggest.height; + final double collapsedHeight = + MediaQuery.of(context).padding.top + + kToolbarHeight; + final double expandedHeight = 264.0; + final double shrinkRatio = + ((expandedHeight - top) / + (expandedHeight - collapsedHeight)) + .clamp(0.0, 1.0); - return FlexibleSpaceBar( - background: ProfileHeader(), - titlePadding: const EdgeInsets.only( - left: 20, - right: 12, - bottom: 16, - ), - title: Opacity( - opacity: shrinkRatio, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - 'Profile', - style: AppStyle.xl.copyWith( - fontWeight: FontWeight.w700, - fontSize: 18, - letterSpacing: -0.5, - color: AppColor.white, + return FlexibleSpaceBar( + background: ProfileHeader(user: state.user), + titlePadding: const EdgeInsets.only( + left: 20, + right: 12, + bottom: 16, ), - ), - ActionIconButton( - onTap: () {}, - icon: LineIcons.userEdit, - ), - ], - ), - ), - ); - }, - ), + title: Opacity( + opacity: shrinkRatio, + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Profile', + style: AppStyle.xl.copyWith( + fontWeight: FontWeight.w700, + fontSize: 18, + letterSpacing: -0.5, + color: AppColor.white, + ), + ), + ActionIconButton( + onTap: () {}, + icon: LineIcons.userEdit, + ), + ], + ), + ), + ); + }, + ), + ), + SliverToBoxAdapter( + child: Column( + children: [ + const SpaceHeight(20), + ProfileAccountInfo(user: state.user), + const SpaceHeight(12), + ProfileBusinessSetting(), + const SpaceHeight(12), + ProfileAppSetting(), + const SpaceHeight(12), + ProfileSupport(), + const SpaceHeight(12), + ProfileDangerZone(), + const SpaceHeight(30), + ], + ), + ), + ], ), - SliverToBoxAdapter( - child: Column( - children: [ - const SpaceHeight(20), - ProfileAccountInfo(), - const SpaceHeight(12), - ProfileBusinessSetting(), - const SpaceHeight(12), - ProfileAppSetting(), - const SpaceHeight(12), - ProfileSupport(), - const SpaceHeight(12), - ProfileDangerZone(), - const SpaceHeight(30), - ], - ), - ), - ], - ), + ); + }, ), ); } diff --git a/lib/presentation/pages/profile/widgets/account_info.dart b/lib/presentation/pages/profile/widgets/account_info.dart index 710c325..778408c 100644 --- a/lib/presentation/pages/profile/widgets/account_info.dart +++ b/lib/presentation/pages/profile/widgets/account_info.dart @@ -1,11 +1,15 @@ import 'package:flutter/material.dart'; +import 'package:line_icons/line_icons.dart'; +import '../../../../common/extension/extension.dart'; import '../../../../common/theme/theme.dart'; +import '../../../../domain/auth/auth.dart'; import 'divider.dart'; import 'profile_tile.dart'; class ProfileAccountInfo extends StatelessWidget { - const ProfileAccountInfo({super.key}); + final User user; + const ProfileAccountInfo({super.key, required this.user}); @override Widget build(BuildContext context) { @@ -38,9 +42,9 @@ class ProfileAccountInfo extends StatelessWidget { ), ProfileTile( - icon: Icons.email_outlined, + icon: LineIcons.envelope, title: 'Email', - subtitle: 'john.doe@business.com', + subtitle: user.email, onTap: () { // Edit email }, @@ -49,31 +53,9 @@ class ProfileAccountInfo extends StatelessWidget { ProfileDivider(), ProfileTile( - icon: Icons.phone_outlined, - title: 'Phone Number', - subtitle: '+62 812 3456 7890', - onTap: () { - // Edit phone - }, - ), - - ProfileDivider(), - - ProfileTile( - icon: Icons.location_on_outlined, - title: 'Address', - subtitle: 'Jl. Merdeka No. 123, Jakarta', - onTap: () { - // Edit address - }, - ), - - ProfileDivider(), - - ProfileTile( - icon: Icons.calendar_today_outlined, + icon: LineIcons.calendarAlt, title: 'Member Since', - subtitle: 'January 15, 2024', + subtitle: user.createdAt.toDate, showArrow: false, ), ], diff --git a/lib/presentation/pages/profile/widgets/header.dart b/lib/presentation/pages/profile/widgets/header.dart index 9377c8d..d83e70b 100644 --- a/lib/presentation/pages/profile/widgets/header.dart +++ b/lib/presentation/pages/profile/widgets/header.dart @@ -1,12 +1,15 @@ import 'package:flutter/material.dart'; import 'dart:math' as math; +import '../../../../common/extension/extension.dart'; import '../../../../common/painter/wave_painter.dart'; import '../../../../common/theme/theme.dart'; +import '../../../../domain/auth/auth.dart'; import '../../../components/spacer/spacer.dart'; class ProfileHeader extends StatefulWidget { - const ProfileHeader({super.key}); + final User user; + const ProfileHeader({super.key, required this.user}); @override State createState() => _ProfileHeaderState(); @@ -347,7 +350,7 @@ class _ProfileHeaderState extends State child: Column( children: [ Text( - 'John Doe', + widget.user.name, style: AppStyle.h5.copyWith( fontWeight: FontWeight.bold, color: AppColor.textWhite, @@ -408,7 +411,7 @@ class _ProfileHeaderState extends State ), const SpaceHeight(6), Text( - 'Business Owner', + widget.user.role.toTitleCase, style: AppStyle.md.copyWith( color: AppColor.textWhite, fontWeight: FontWeight.w600,