Tab Community, tombol Bayar di navbar, logo placeholder, fix crash PIN
- Bottom navbar: Home, Pesanan, Bayar (tombol tengah ke kode bayar), Community, Profil; menu EnakCommunity di beranda pindah ke tab - Image placeholder: logo Enaklo diperbesar, ilustrasi gelas dihapus - Fix assertion Navigator saat PIN gagal karena error non-PIN: flushbar kini tampil lewat onFailure setelah sheet PIN tertutup (bayar, tukar, transfer) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f5e3075205
commit
bc751246d8
@@ -93,6 +93,7 @@ class _CommunityPageState extends State<CommunityPage> {
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
pinned: true,
|
||||
automaticallyImplyLeading: false,
|
||||
backgroundColor: CommunityColor.background,
|
||||
title: const Text('EnakCommunity'),
|
||||
actions: [
|
||||
|
||||
@@ -21,6 +21,14 @@ class _MainPageState extends State<MainPage> {
|
||||
context.read<AuthBloc>().add(const AuthEvent.fetchCurrentUser());
|
||||
}
|
||||
|
||||
/// Kode bayar di kasir; PIN diminta di halamannya sendiri.
|
||||
void _openPay() {
|
||||
final isAuthenticated = context.read<AuthBloc>().state.isAuthenticated;
|
||||
context.router.push(
|
||||
isAuthenticated ? const PaymentCodeRoute() : const OnboardingRoute(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AutoTabsRouter.pageView(
|
||||
@@ -28,15 +36,26 @@ class _MainPageState extends State<MainPage> {
|
||||
HomeRoute(),
|
||||
// VoucherRoute(),
|
||||
OrderRoute(),
|
||||
CommunityRoute(),
|
||||
ProfileRoute(),
|
||||
],
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
builder: (context, child, pageController) => Scaffold(
|
||||
body: child,
|
||||
bottomNavigationBar: MainBottomNavbar(
|
||||
tabsRouter: AutoTabsRouter.of(context),
|
||||
),
|
||||
),
|
||||
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
|
||||
: MainPayButton(onPressed: _openPay),
|
||||
floatingActionButtonLocation: const MainPayButtonLocation(),
|
||||
bottomNavigationBar: MainBottomNavbar(
|
||||
tabsRouter: AutoTabsRouter.of(context),
|
||||
onPayTap: _openPay,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ class _HomeMenu {
|
||||
required this.icon,
|
||||
this.route,
|
||||
this.requiresLogin = false,
|
||||
this.opensTab = false,
|
||||
});
|
||||
|
||||
final String label;
|
||||
@@ -23,6 +24,9 @@ class _HomeMenu {
|
||||
/// `null` berarti fitur belum tersedia.
|
||||
final PageRouteInfo? route;
|
||||
final bool requiresLogin;
|
||||
|
||||
/// [route] adalah tab di bottom navbar; dibuka dengan pindah tab, bukan push.
|
||||
final bool opensTab;
|
||||
}
|
||||
|
||||
class HomeServiceSection extends StatelessWidget {
|
||||
@@ -78,6 +82,7 @@ class HomeServiceSection extends StatelessWidget {
|
||||
label: 'EnakCommunity',
|
||||
icon: Assets.icons.enakcommunityIcon,
|
||||
route: const CommunityRoute(),
|
||||
opensTab: true,
|
||||
),
|
||||
];
|
||||
|
||||
@@ -94,6 +99,11 @@ class HomeServiceSection extends StatelessWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
if (menu.opensTab) {
|
||||
context.tabsRouter.navigate(route);
|
||||
return;
|
||||
}
|
||||
|
||||
context.router.push(route);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../common/theme/theme.dart';
|
||||
|
||||
class MainBottomNavbar extends StatelessWidget {
|
||||
final TabsRouter tabsRouter;
|
||||
const MainBottomNavbar({super.key, required this.tabsRouter});
|
||||
final VoidCallback onPayTap;
|
||||
const MainBottomNavbar({
|
||||
super.key,
|
||||
required this.tabsRouter,
|
||||
required this.onPayTap,
|
||||
});
|
||||
|
||||
/// Slot tengah hanya tempat label tombol Bayar; lingkarannya
|
||||
/// [MainPayButton] yang menempel di atas navbar.
|
||||
static const int _payIndex = 2;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final activeIndex = tabsRouter.activeIndex;
|
||||
|
||||
return BottomNavigationBar(
|
||||
currentIndex: tabsRouter.activeIndex,
|
||||
currentIndex: activeIndex >= _payIndex ? activeIndex + 1 : activeIndex,
|
||||
onTap: (index) {
|
||||
tabsRouter.setActiveIndex(index);
|
||||
if (index == _payIndex) {
|
||||
onPayTap();
|
||||
return;
|
||||
}
|
||||
tabsRouter.setActiveIndex(index > _payIndex ? index - 1 : index);
|
||||
},
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
@@ -28,6 +45,16 @@ class MainBottomNavbar extends StatelessWidget {
|
||||
label: 'Pesanan',
|
||||
tooltip: 'Pesanan',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: SizedBox(height: 24),
|
||||
label: 'Bayar',
|
||||
tooltip: 'Bayar di kasir',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.groups),
|
||||
label: 'Community',
|
||||
tooltip: 'Community',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person),
|
||||
label: 'Profil',
|
||||
@@ -37,3 +64,40 @@ class MainBottomNavbar extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Seperti [FloatingActionButtonLocation.centerDocked], tapi tombolnya lebih
|
||||
/// menonjol ke atas supaya tidak menempel ke label "Bayar".
|
||||
class MainPayButtonLocation extends StandardFabLocation
|
||||
with FabCenterOffsetX, FabDockedOffsetY {
|
||||
const MainPayButtonLocation();
|
||||
|
||||
static const double _raise = 10;
|
||||
|
||||
@override
|
||||
double getOffsetY(
|
||||
ScaffoldPrelayoutGeometry scaffoldGeometry,
|
||||
double adjustment,
|
||||
) => super.getOffsetY(scaffoldGeometry, adjustment) - _raise;
|
||||
}
|
||||
|
||||
/// Tombol bulat di tengah navbar, dipasang di [MainPayButtonLocation].
|
||||
class MainPayButton extends StatelessWidget {
|
||||
final VoidCallback onPressed;
|
||||
const MainPayButton({super.key, required this.onPressed});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FloatingActionButton(
|
||||
onPressed: onPressed,
|
||||
// Halaman tab (mis. Community) juga punya FAB; tanpa hero supaya tag
|
||||
// default tidak bentrok saat pindah halaman.
|
||||
heroTag: null,
|
||||
tooltip: 'Bayar di kasir',
|
||||
elevation: 4,
|
||||
backgroundColor: AppColor.primary,
|
||||
foregroundColor: AppColor.white,
|
||||
shape: const CircleBorder(),
|
||||
child: const Icon(Icons.qr_code_scanner_rounded, size: 28),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,21 @@ typedef PinSubmitCallback = Future<WalletFailure?> Function(String pin);
|
||||
enum _PinSheetResult { success, failed, forgotPin, pinNotSet }
|
||||
|
||||
/// Meminta PIN lalu menjalankan [onSubmit]. Error PIN (§6.5) ditangani di dalam
|
||||
/// sheet; failure lain menutup sheet dan ditampilkan oleh halaman pemanggil.
|
||||
/// sheet; failure lain menutup sheet lalu diteruskan ke [onFailure].
|
||||
/// Mengembalikan `true` bila [onSubmit] sukses.
|
||||
///
|
||||
/// Tampilkan failure lewat [onFailure], jangan dari listener bloc: flushbar juga
|
||||
/// berupa route, jadi bila muncul selagi sheet masih terbuka, pop milik sheet
|
||||
/// justru menutup flushbar dan Navigator gagal assertion.
|
||||
Future<bool> showPinSheet(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
String? subtitle,
|
||||
required PinSubmitCallback onSubmit,
|
||||
ValueChanged<WalletFailure>? onFailure,
|
||||
}) async {
|
||||
WalletFailure? lastFailure;
|
||||
|
||||
final result = await showModalBottomSheet<_PinSheetResult>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
@@ -30,8 +37,11 @@ Future<bool> showPinSheet(
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
builder: (_) =>
|
||||
_PinSheet(title: title, subtitle: subtitle, onSubmit: onSubmit),
|
||||
builder: (_) => _PinSheet(
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
onSubmit: (pin) async => lastFailure = await onSubmit(pin),
|
||||
),
|
||||
);
|
||||
|
||||
if (!context.mounted) return false;
|
||||
@@ -46,6 +56,8 @@ Future<bool> showPinSheet(
|
||||
context.router.push(PinSetupRoute(purpose: PinOtpPurpose.setup));
|
||||
return false;
|
||||
case _PinSheetResult.failed:
|
||||
if (lastFailure != null) onFailure?.call(lastFailure!);
|
||||
return false;
|
||||
case null:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ class _ExchangePageState extends State<ExchangePage> {
|
||||
final result = await bloc.stream.firstWhere((s) => !s.isSubmitting);
|
||||
return result.failureOption.toNullable();
|
||||
},
|
||||
onFailure: _showFailure,
|
||||
);
|
||||
|
||||
if (success && mounted) {
|
||||
@@ -173,11 +174,6 @@ class _ExchangePageState extends State<ExchangePage> {
|
||||
Widget build(BuildContext context) {
|
||||
return MultiBlocListener(
|
||||
listeners: [
|
||||
BlocListener<ExchangeFormBloc, ExchangeFormState>(
|
||||
listenWhen: (p, c) => p.failureOption != c.failureOption,
|
||||
listener: (context, state) =>
|
||||
state.failureOption.fold(() {}, _showFailure),
|
||||
),
|
||||
BlocListener<ExchangeFormBloc, ExchangeFormState>(
|
||||
listenWhen: (p, c) => p.preview != c.preview && c.preview != null,
|
||||
listener: (context, state) => setState(() => _rate = state.preview),
|
||||
|
||||
@@ -73,18 +73,13 @@ class _PaymentCodePageState extends State<PaymentCodePage> {
|
||||
final state = await bloc.stream.firstWhere((s) => !s.isSubmitting);
|
||||
return state.failureOption.toNullable();
|
||||
},
|
||||
onFailure: (f) => AppFlushbar.showError(context, walletFailureMessage(f)),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<PaymentCodeFormBloc, PaymentCodeFormState>(
|
||||
listenWhen: (p, c) => p.failureOption != c.failureOption,
|
||||
listener: (context, state) => state.failureOption.fold(() {}, (f) {
|
||||
if (!f.isPinError) {
|
||||
AppFlushbar.showError(context, walletFailureMessage(f));
|
||||
}
|
||||
}),
|
||||
return BlocBuilder<PaymentCodeFormBloc, PaymentCodeFormState>(
|
||||
builder: (context, state) {
|
||||
final code = state.paymentCode;
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
final result = await bloc.stream.firstWhere((s) => !s.isSubmitting);
|
||||
return result.failureOption.toNullable();
|
||||
},
|
||||
onFailure: _showFailure,
|
||||
);
|
||||
|
||||
if (success && mounted) {
|
||||
@@ -201,11 +202,6 @@ class _TransferPageState extends State<TransferPage> {
|
||||
Widget build(BuildContext context) {
|
||||
return MultiBlocListener(
|
||||
listeners: [
|
||||
BlocListener<TransferFormBloc, TransferFormState>(
|
||||
listenWhen: (p, c) => p.failureOption != c.failureOption,
|
||||
listener: (context, state) =>
|
||||
state.failureOption.fold(() {}, _showFailure),
|
||||
),
|
||||
BlocListener<TransferFormBloc, TransferFormState>(
|
||||
listenWhen: (p, c) =>
|
||||
p.recipient != c.recipient && c.recipient != null,
|
||||
|
||||
Reference in New Issue
Block a user