State Is Authenticated
This commit is contained in:
parent
3c596461c6
commit
a5d66c63b7
@ -1,13 +1,26 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../application/auth/auth_bloc.dart';
|
||||
import '../../router/app_router.gr.dart';
|
||||
import 'widgets/bottom_navbar.dart';
|
||||
|
||||
@RoutePage()
|
||||
class MainPage extends StatelessWidget {
|
||||
class MainPage extends StatefulWidget {
|
||||
const MainPage({super.key});
|
||||
|
||||
@override
|
||||
State<MainPage> createState() => _MainPageState();
|
||||
}
|
||||
|
||||
class _MainPageState extends State<MainPage> {
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
context.read<AuthBloc>().add(const AuthEvent.fetchCurrentUser());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AutoTabsRouter.pageView(
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../../../application/auth/auth_bloc.dart';
|
||||
import '../../../../../router/app_router.gr.dart';
|
||||
import 'feature_card.dart';
|
||||
|
||||
@ -8,6 +10,8 @@ class HomeFeatureSection extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
@ -35,10 +39,14 @@ class HomeFeatureSection extends StatelessWidget {
|
||||
icon: Icons.blur_circular,
|
||||
title: 'Wheels',
|
||||
iconColor: const Color(0xFF388E3C),
|
||||
onTap: () => context.router.push(FerrisWheelRoute()),
|
||||
onTap: () => state.isAuthenticated
|
||||
? context.router.push(FerrisWheelRoute())
|
||||
: context.router.push(OnboardingRoute()),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../../application/auth/auth_bloc.dart';
|
||||
import '../../../../../../common/theme/theme.dart';
|
||||
import '../../../../../router/app_router.gr.dart';
|
||||
|
||||
@ -9,8 +11,12 @@ class HomePointCard extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
return GestureDetector(
|
||||
onTap: () => context.router.push(PoinRoute()),
|
||||
onTap: () => state.isAuthenticated
|
||||
? context.router.push(PoinRoute())
|
||||
: context.router.push(OnboardingRoute()),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.white,
|
||||
@ -33,8 +39,20 @@ class HomePointCard extends StatelessWidget {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
!state.isAuthenticated
|
||||
? Expanded(
|
||||
child: Text(
|
||||
'Hi, Selamat Datang Di Enaklo',
|
||||
style: AppStyle.md.copyWith(
|
||||
color: AppColor.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
@ -43,7 +61,9 @@ class HomePointCard extends StatelessWidget {
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.primary,
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
borderRadius: BorderRadius.circular(
|
||||
25,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@ -74,7 +94,8 @@ class HomePointCard extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
width: 120,
|
||||
height: 40,
|
||||
@ -119,7 +140,9 @@ class HomePointCard extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'Tukarkan poinmu dengan hadiah menarik',
|
||||
state.isAuthenticated
|
||||
? 'Tukarkan poinmu dengan hadiah menarik'
|
||||
: 'Silahkan login untuk tukarkan poinmu',
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.textPrimary,
|
||||
fontSize: 13,
|
||||
@ -141,6 +164,8 @@ class HomePointCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCoinPattern() {
|
||||
|
||||
@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../application/auth/auth_bloc.dart';
|
||||
import '../../../../../application/auth/logout_form/logout_form_bloc.dart';
|
||||
import '../../../../../common/theme/theme.dart';
|
||||
import '../../../../../injection.dart';
|
||||
@ -20,7 +21,7 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
() => null,
|
||||
(either) => either.fold(
|
||||
(f) => AppFlushbar.showAuthFailureToast(context, f),
|
||||
(_) => context.router.replaceAll([LoginRoute()]),
|
||||
(_) => context.router.replaceAll([OnboardingRoute()]),
|
||||
),
|
||||
);
|
||||
},
|
||||
@ -28,7 +29,9 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
child: Scaffold(
|
||||
backgroundColor: AppColor.background,
|
||||
appBar: AppBar(title: Text('Profil'), automaticallyImplyLeading: false),
|
||||
body: SingleChildScrollView(
|
||||
body: BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
// Profile Header
|
||||
@ -40,7 +43,9 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
children: [
|
||||
// Profile Avatar & Info
|
||||
GestureDetector(
|
||||
onTap: () => context.router.push(AccountMyRoute()),
|
||||
onTap: () => state.isAuthenticated
|
||||
? context.router.push(AccountMyRoute())
|
||||
: context.router.push(OnboardingRoute()),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
@ -123,7 +128,22 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
// Main Content
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
child: !state.isAuthenticated
|
||||
? Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Silahkan Masuk',
|
||||
style: AppStyle.lg.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.white,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: Row(
|
||||
children: [
|
||||
// Avatar
|
||||
Container(
|
||||
@ -134,9 +154,8 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColor.black.withOpacity(
|
||||
0.1,
|
||||
),
|
||||
color: AppColor.black
|
||||
.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
@ -156,20 +175,20 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'EFRIL',
|
||||
state.user.name,
|
||||
style: AppStyle.lg.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontWeight:
|
||||
FontWeight.bold,
|
||||
color: AppColor.white,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'+6283873987851',
|
||||
state.user.phoneNumber,
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.white.withOpacity(
|
||||
0.9,
|
||||
),
|
||||
color: AppColor.white
|
||||
.withOpacity(0.9),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -195,6 +214,7 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Menu Items
|
||||
if (state.isAuthenticated) ...[
|
||||
Container(
|
||||
color: AppColor.white,
|
||||
child: Column(
|
||||
@ -223,8 +243,8 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
|
||||
// Legal & Privacy Section
|
||||
Container(
|
||||
@ -329,6 +349,7 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Footer Section
|
||||
if (state.isAuthenticated)
|
||||
Container(
|
||||
color: AppColor.white,
|
||||
padding: const EdgeInsets.all(20),
|
||||
@ -344,9 +365,9 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
GestureDetector(
|
||||
onTap: () => _showLogoutDialog(
|
||||
context,
|
||||
onLogout: () => context.read<LogoutFormBloc>().add(
|
||||
const LogoutFormEvent.submitted(),
|
||||
),
|
||||
onLogout: () => context
|
||||
.read<LogoutFormBloc>()
|
||||
.add(const LogoutFormEvent.submitted()),
|
||||
),
|
||||
child: Text(
|
||||
'Logout',
|
||||
@ -363,6 +384,8 @@ class ProfilePage extends StatelessWidget implements AutoRouteWrapper {
|
||||
const SizedBox(height: 100), // Bottom spacing
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user