You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.1 KiB
Dart
80 lines
3.1 KiB
Dart
import 'dart:async';
|
|
import 'dart:developer';
|
|
import 'package:car_provider_app/views/branch_management/branch/branch_list_page.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
import 'package:mc_common_app/utils/enums.dart';
|
|
import 'package:mc_common_app/view_models/dashboard_view_model_provider.dart';
|
|
import 'package:mc_common_app/views/common_fragments/requests_fragment.dart';
|
|
import 'package:mc_common_app/widgets/common_widgets/bottom_nav_bar.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'fragments/branch_appointment_fragment.dart';
|
|
import 'fragments/home_fragment.dart';
|
|
import 'package:mc_common_app/views/common_fragments/ads_fragment.dart';
|
|
|
|
class DashboardView extends StatefulWidget {
|
|
final DashboardRouteEnum dashboardRouteEnum;
|
|
|
|
const DashboardView({Key? key, required this.dashboardRouteEnum}) : super(key: key);
|
|
|
|
@override
|
|
State<DashboardView> createState() => _DashboardViewState();
|
|
}
|
|
|
|
class _DashboardViewState extends State<DashboardView> {
|
|
late DashboardVMProvider dashboardVMProvider;
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
|
|
|
@override
|
|
void initState() {
|
|
log("widget.dashboardRouteEnum: ${widget.dashboardRouteEnum}");
|
|
super.initState();
|
|
dashboardVMProvider = Provider.of<DashboardVMProvider>(context, listen: false);
|
|
|
|
// Ensure selected index is valid for individual providers (no Requests tab)
|
|
if (AppState().userType != UserType.providerDealer && AppState().userType != UserType.dealershipUser) {
|
|
// For individuals, max index is 3 (Ads), so if selected is 4, set to Home (2)
|
|
if (dashboardVMProvider.selectedNavbarBarIndex >= 4) {
|
|
dashboardVMProvider.selectedNavbarBarIndex = 2; // Home
|
|
}
|
|
}
|
|
|
|
scheduleMicrotask(() => dashboardVMProvider.onRefresh(context, dashboardRouteEnum: widget.dashboardRouteEnum));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// Build fragments list conditionally based on user type
|
|
// Individual providers should not have access to Requests
|
|
List<Widget> fragments = [
|
|
const BranchListPage(), // 0
|
|
const BranchAppointmentFragment(), // 1
|
|
const HomeFragment(), // 2
|
|
const AdsFragment(), // 3
|
|
// Only Dealerships (and dealership staff users) can access Special Requests
|
|
if (AppState().userType == UserType.providerDealer || AppState().userType == UserType.dealershipUser) const MyRequestsFragment(), // 4 (only for dealerships)
|
|
];
|
|
|
|
// Ensure the selected index is valid for the current fragments list
|
|
int validIndex = context.watch<DashboardVMProvider>().selectedNavbarBarIndex;
|
|
if (validIndex >= fragments.length) {
|
|
validIndex = fragments.length - 1; // Default to last valid fragment
|
|
}
|
|
|
|
return PopScope(
|
|
canPop: false,
|
|
child: Scaffold(
|
|
key: _scaffoldKey,
|
|
body: fragments[validIndex],
|
|
bottomNavigationBar: CustomBottomNavbar(
|
|
onSelected: (index) {
|
|
dashboardVMProvider.onNavbarTapped(index);
|
|
},
|
|
isProvider: true,
|
|
selectedNavbarBarIndex: dashboardVMProvider.selectedNavbarBarIndex,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|