Initial draft
This commit is contained in:
28
lib/widget/home/bloc/navigation_bloc.dart
Normal file
28
lib/widget/home/bloc/navigation_bloc.dart
Normal file
@ -0,0 +1,28 @@
|
||||
// Navigation events
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'navigation_event.dart';
|
||||
import 'navigation_state.dart';
|
||||
|
||||
// Navigation BLoC
|
||||
class NavigationBloc extends Bloc<NavigationEvent, NavigationState> {
|
||||
NavigationBloc() : super(NavigateToRoute('/scan', index: 0)) {
|
||||
on<NavigateToCars>((event, emit) {
|
||||
emit(NavigateToRoute('/cars', index: 2));
|
||||
});
|
||||
|
||||
on<NavigateToDeliveries>((event, emit) {
|
||||
emit(NavigateToRoute('/deliveries', index: 1));
|
||||
});
|
||||
|
||||
on<NavigateToDelivery>((event, emit) {
|
||||
emit(NavigateToRoute('/delivery'));
|
||||
});
|
||||
|
||||
on<NavigateToScan>((event, emit) {
|
||||
emit(NavigateToRoute('/scan', index: 0));
|
||||
});
|
||||
|
||||
// Add more navigation handlers...
|
||||
}
|
||||
}
|
||||
8
lib/widget/home/bloc/navigation_event.dart
Normal file
8
lib/widget/home/bloc/navigation_event.dart
Normal file
@ -0,0 +1,8 @@
|
||||
abstract class NavigationEvent {}
|
||||
|
||||
class NavigateToHome extends NavigationEvent {}
|
||||
class NavigateToDeliveries extends NavigationEvent {}
|
||||
class NavigateToDelivery extends NavigationEvent {}
|
||||
class NavigateToScan extends NavigationEvent {}
|
||||
class NavigateToCars extends NavigationEvent {}
|
||||
class GoBack extends NavigationEvent {}
|
||||
11
lib/widget/home/bloc/navigation_state.dart
Normal file
11
lib/widget/home/bloc/navigation_state.dart
Normal file
@ -0,0 +1,11 @@
|
||||
// Navigation states
|
||||
abstract class NavigationState {}
|
||||
|
||||
class NavigationInitial extends NavigationState {}
|
||||
class NavigateToRoute extends NavigationState {
|
||||
final String routeName;
|
||||
final int? index;
|
||||
final Object? arguments;
|
||||
|
||||
NavigateToRoute(this.routeName, {this.arguments, this.index});
|
||||
}
|
||||
79
lib/widget/home/presentation/home.dart
Normal file
79
lib/widget/home/presentation/home.dart
Normal file
@ -0,0 +1,79 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/bloc/auth_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/bloc/auth_state.dart';
|
||||
import 'package:hl_lieferservice/feature/cars/presentation/car_management_page.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_event.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/presentation/delivery_overview_page.dart';
|
||||
import 'package:hl_lieferservice/widget/navigation_bar/presentation/navigation_bar.dart';
|
||||
|
||||
import '../../../bloc/app_bloc.dart';
|
||||
import '../../../bloc/app_states.dart';
|
||||
import '../../../feature/cars/bloc/cars_bloc.dart';
|
||||
import '../../../feature/cars/repository/cars_repository.dart';
|
||||
import '../../../feature/cars/service/cars_service.dart';
|
||||
import '../../operations/bloc/operation_bloc.dart';
|
||||
|
||||
class Home extends StatefulWidget {
|
||||
const Home({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _HomeState();
|
||||
}
|
||||
|
||||
class _HomeState extends State<Home> {
|
||||
int _selectedPage = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// Load deliveries
|
||||
Authenticated state = context.read<AuthBloc>().state as Authenticated;
|
||||
context.read<TourBloc>().add(LoadTour(teamId: state.teamId));
|
||||
}
|
||||
|
||||
Widget _buildPage(index) {
|
||||
if (index == 0) {
|
||||
return Container();
|
||||
}
|
||||
|
||||
if (index == 1) {
|
||||
return DeliveryOverviewPage();
|
||||
}
|
||||
|
||||
if (index == 2) {
|
||||
final currentAppState = context.read<AppBloc>().state as AppConfigLoaded;
|
||||
return BlocProvider(
|
||||
create:
|
||||
(context) => CarsBloc(
|
||||
repository: CarsRepository(
|
||||
service: CarService(config: currentAppState.config),
|
||||
),
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
),
|
||||
child: CarManagementPage(),
|
||||
);
|
||||
}
|
||||
|
||||
return Container();
|
||||
}
|
||||
|
||||
void _onSelect(int index) {
|
||||
setState(() {
|
||||
_selectedPage = index;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Center(child: Text("Holzleitner Lieferservice")),
|
||||
),
|
||||
body: _buildPage(_selectedPage),
|
||||
bottomNavigationBar: AppNavigationBar(onSelect: _onSelect),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user