73 lines
2.1 KiB
Dart
73 lines
2.1 KiB
Dart
import 'package:citycards_customer/home/views/registered_user_home_page.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import '../../attractions/views/attractions_page_view.dart';
|
|
import '../../common_bloc/bottom_navigation_bloc.dart';
|
|
import '../../common_packages/custom_bottom_navbar.dart';
|
|
import '../../core/route_constants.dart';
|
|
import 'first_time_user_home_page.dart';
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
State<HomePage> createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> {
|
|
final _navigatorKeys = [
|
|
GlobalKey<NavigatorState>(), // tab 0
|
|
GlobalKey<NavigatorState>(), // tab 1
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<NavigationBloc, NavigationState>(
|
|
builder: (context, state) {
|
|
final currentIndex = state.selectedIndex;
|
|
|
|
return SafeArea(
|
|
top: false,
|
|
child: Scaffold(
|
|
body: Stack(
|
|
children: [
|
|
_buildOffstageNavigator(0, currentIndex, const FirstTimeUserHomePage()),
|
|
_buildOffstageNavigator(1, currentIndex, const RegisteredUserHomePage()),
|
|
],
|
|
),
|
|
bottomNavigationBar: CustomBottomNavBar(),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildOffstageNavigator(int index, int currentIndex, Widget child) {
|
|
return Offstage(
|
|
offstage: currentIndex != index,
|
|
child: Navigator(
|
|
key: _navigatorKeys[index],
|
|
onGenerateRoute: (settings) {
|
|
switch (settings.name) {
|
|
case '/':
|
|
return MaterialPageRoute(builder: (_) => child);
|
|
|
|
case RouteConstants.attractionsPage:
|
|
return MaterialPageRoute(
|
|
builder: (_) => const AttractionsPage(),
|
|
);
|
|
|
|
default:
|
|
return MaterialPageRoute(
|
|
builder: (_) => const Scaffold(
|
|
body: Center(child: Text('Page not found')),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
}
|