62 lines
1.8 KiB
Dart
62 lines
1.8 KiB
Dart
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 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());
|
|
}
|
|
|
|
/// Beranda EnakPoint & EnakCoin: tukar, transfer, game, dan voucher.
|
|
void _openWallet() {
|
|
final isAuthenticated = context.read<AuthBloc>().state.isAuthenticated;
|
|
context.router.push(
|
|
isAuthenticated ? const WalletRoute() : const OnboardingRoute(),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AutoTabsRouter.pageView(
|
|
routes: [
|
|
HomeRoute(),
|
|
// VoucherRoute(),
|
|
OrderRoute(),
|
|
CommunityRoute(),
|
|
ProfileRoute(),
|
|
],
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
builder: (context, child, pageController) {
|
|
// Docked FAB ikut naik ke atas keyboard; sembunyikan saat mengetik.
|
|
final isKeyboardOpen = MediaQuery.viewInsetsOf(context).bottom > 0;
|
|
|
|
return Scaffold(
|
|
body: child,
|
|
floatingActionButton: isKeyboardOpen
|
|
? null
|
|
: MainWalletButton(onPressed: _openWallet),
|
|
floatingActionButtonLocation: const MainWalletButtonLocation(),
|
|
bottomNavigationBar: MainBottomNavbar(
|
|
tabsRouter: AutoTabsRouter.of(context),
|
|
onWalletTap: _openWallet,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|