refactor(staff_main): enforce strict architecture and clean code
- Added StaffMainRoutes constants to avoid magic strings - Enhanced StaffMainNavigator with typed tab navigation - Updated StaffMainCubit to use typed navigation - Updated StaffMainModule to use route constants
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import 'package:staff_main/src/presentation/blocs/staff_main_state.dart';
|
||||
import 'package:staff_main/src/presentation/constants/staff_main_routes.dart';
|
||||
import 'package:staff_main/src/presentation/navigation/staff_main_navigator.dart';
|
||||
|
||||
class StaffMainCubit extends Cubit<StaffMainState> implements Disposable {
|
||||
StaffMainCubit() : super(const StaffMainState()) {
|
||||
@@ -14,15 +16,15 @@ class StaffMainCubit extends Cubit<StaffMainState> implements Disposable {
|
||||
|
||||
// Detect which tab is active based on the route path
|
||||
// Using contains() to handle child routes and trailing slashes
|
||||
if (path.contains('/staff-main/shifts')) {
|
||||
if (path.contains(StaffMainRoutes.shiftsFull)) {
|
||||
newIndex = 0;
|
||||
} else if (path.contains('/staff-main/payments')) {
|
||||
} else if (path.contains(StaffMainRoutes.paymentsFull)) {
|
||||
newIndex = 1;
|
||||
} else if (path.contains('/staff-main/home')) {
|
||||
} else if (path.contains(StaffMainRoutes.homeFull)) {
|
||||
newIndex = 2;
|
||||
} else if (path.contains('/staff-main/clock-in')) {
|
||||
} else if (path.contains(StaffMainRoutes.clockInFull)) {
|
||||
newIndex = 3;
|
||||
} else if (path.contains('/staff-main/profile')) {
|
||||
} else if (path.contains(StaffMainRoutes.profileFull)) {
|
||||
newIndex = 4;
|
||||
}
|
||||
|
||||
@@ -36,19 +38,19 @@ class StaffMainCubit extends Cubit<StaffMainState> implements Disposable {
|
||||
|
||||
switch (index) {
|
||||
case 0:
|
||||
Modular.to.navigate('/staff-main/shifts');
|
||||
Modular.to.navigateToShifts();
|
||||
break;
|
||||
case 1:
|
||||
Modular.to.navigate('/staff-main/payments');
|
||||
Modular.to.navigateToPayments();
|
||||
break;
|
||||
case 2:
|
||||
Modular.to.navigate('/staff-main/home');
|
||||
Modular.to.navigateToHome();
|
||||
break;
|
||||
case 3:
|
||||
Modular.to.navigate('/staff-main/clock-in');
|
||||
Modular.to.navigateToClockIn();
|
||||
break;
|
||||
case 4:
|
||||
Modular.to.navigate('/staff-main/profile');
|
||||
Modular.to.navigateToProfile();
|
||||
break;
|
||||
}
|
||||
// State update will happen via _onRouteChanged
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
abstract class StaffMainRoutes {
|
||||
static const String modulePath = '/staff-main';
|
||||
|
||||
static const String shifts = '/shifts';
|
||||
static const String payments = '/payments';
|
||||
static const String home = '/home';
|
||||
static const String clockIn = '/clock-in';
|
||||
static const String profile = '/profile';
|
||||
|
||||
// Full paths
|
||||
static const String shiftsFull = '$modulePath$shifts';
|
||||
static const String paymentsFull = '$modulePath$payments';
|
||||
static const String homeFull = '$modulePath$home';
|
||||
static const String clockInFull = '$modulePath$clockIn';
|
||||
static const String profileFull = '$modulePath$profile';
|
||||
}
|
||||
@@ -1,10 +1,36 @@
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import '../constants/staff_main_routes.dart';
|
||||
|
||||
/// Extension to provide typed navigation for the Staff Main feature.
|
||||
extension StaffMainNavigator on IModularNavigator {
|
||||
/// Navigates to the Staff Main Shell (Home).
|
||||
/// This replaces the current navigation stack.
|
||||
void navigateStaffMain() {
|
||||
navigate('/staff-main/');
|
||||
navigate('${StaffMainRoutes.modulePath}/');
|
||||
}
|
||||
|
||||
/// Navigates to the Shifts tab.
|
||||
void navigateToShifts() {
|
||||
navigate(StaffMainRoutes.shiftsFull);
|
||||
}
|
||||
|
||||
/// Navigates to the Payments tab.
|
||||
void navigateToPayments() {
|
||||
navigate(StaffMainRoutes.paymentsFull);
|
||||
}
|
||||
|
||||
/// Navigates to the Home tab.
|
||||
void navigateToHome() {
|
||||
navigate(StaffMainRoutes.homeFull);
|
||||
}
|
||||
|
||||
/// Navigates to the Clock In tab.
|
||||
void navigateToClockIn() {
|
||||
navigate(StaffMainRoutes.clockInFull);
|
||||
}
|
||||
|
||||
/// Navigates to the Profile tab.
|
||||
void navigateToProfile() {
|
||||
navigate(StaffMainRoutes.profileFull);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
|
||||
import 'package:staff_main/src/presentation/blocs/staff_main_cubit.dart';
|
||||
import 'package:staff_main/src/presentation/constants/staff_main_routes.dart';
|
||||
import 'package:staff_main/src/presentation/pages/placeholder_page.dart';
|
||||
import 'package:staff_main/src/presentation/pages/staff_main_page.dart';
|
||||
|
||||
@@ -18,26 +19,26 @@ class StaffMainModule extends Module {
|
||||
child: (BuildContext context) => const StaffMainPage(),
|
||||
children: <ParallelRoute<dynamic>>[
|
||||
ChildRoute<dynamic>(
|
||||
'/shifts',
|
||||
StaffMainRoutes.shifts,
|
||||
child: (BuildContext context) =>
|
||||
const PlaceholderPage(title: 'Shifts'),
|
||||
),
|
||||
ChildRoute<dynamic>(
|
||||
'/payments',
|
||||
StaffMainRoutes.payments,
|
||||
child: (BuildContext context) =>
|
||||
const PlaceholderPage(title: 'Payments'),
|
||||
),
|
||||
ChildRoute<dynamic>(
|
||||
'/home',
|
||||
StaffMainRoutes.home,
|
||||
child: (BuildContext context) => const PlaceholderPage(title: 'Home'),
|
||||
),
|
||||
ChildRoute<dynamic>(
|
||||
'/clock-in',
|
||||
StaffMainRoutes.clockIn,
|
||||
child: (BuildContext context) =>
|
||||
const PlaceholderPage(title: 'Clock In'),
|
||||
),
|
||||
ChildRoute<dynamic>(
|
||||
'/profile',
|
||||
StaffMainRoutes.profile,
|
||||
child: (BuildContext context) =>
|
||||
const PlaceholderPage(title: 'Profile'),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user