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