Implemented settings, new scan, enhanced UI/UX
This commit is contained in:
@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/bloc/app_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/bloc/auth_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/presentation/login_enforcer.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/service/userinfo.dart';
|
||||
import 'package:hl_lieferservice/feature/cars/presentation/car_management_page.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/delivery_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/bloc/note_bloc.dart';
|
||||
@ -11,14 +12,13 @@ import 'package:hl_lieferservice/feature/delivery/detail/repository/note_reposit
|
||||
import 'package:hl_lieferservice/feature/delivery/detail/service/notes_service.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/bloc/tour_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/repository/tour_repository.dart';
|
||||
import 'package:hl_lieferservice/repository/user_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/settings/bloc/settings_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/home/bloc/navigation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/presentation/operation_view_enforcer.dart';
|
||||
|
||||
import 'package:hl_lieferservice/bloc/app_states.dart';
|
||||
import '../feature/delivery/overview/service/delivery_info_service.dart';
|
||||
import 'home/bloc/navigation_state.dart';
|
||||
import 'home/presentation/home.dart';
|
||||
|
||||
class DeliveryApp extends StatefulWidget {
|
||||
@ -42,7 +42,9 @@ class _DeliveryAppState extends State<DeliveryApp> {
|
||||
BlocProvider(
|
||||
create:
|
||||
(context) => AuthBloc(
|
||||
repository: UserRepository(),
|
||||
service: UserInfoService(
|
||||
url: currentAppState.config.backendUrl,
|
||||
),
|
||||
operationBloc: context.read<OperationBloc>(),
|
||||
),
|
||||
),
|
||||
@ -50,7 +52,7 @@ class _DeliveryAppState extends State<DeliveryApp> {
|
||||
create:
|
||||
(context) => TourBloc(
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
deliveryRepository: TourRepository(
|
||||
tourRepository: TourRepository(
|
||||
service: DeliveryInfoService(
|
||||
config: currentAppState.config,
|
||||
),
|
||||
@ -70,6 +72,9 @@ class _DeliveryAppState extends State<DeliveryApp> {
|
||||
create:
|
||||
(context) => DeliveryBloc(
|
||||
opBloc: context.read<OperationBloc>(),
|
||||
noteRepository: NoteRepository(
|
||||
service: NoteService(config: currentAppState.config),
|
||||
),
|
||||
repository: DeliveryRepository(
|
||||
service: DeliveryInfoService(
|
||||
config: currentAppState.config,
|
||||
@ -93,20 +98,7 @@ class _DeliveryAppState extends State<DeliveryApp> {
|
||||
}
|
||||
|
||||
if (state is AppConfigLoaded) {
|
||||
return BlocConsumer<NavigationBloc, NavigationState>(
|
||||
listener: (context, state) {
|
||||
if (state is NavigateToRoute) {
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
state.routeName,
|
||||
arguments: state.arguments,
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (BuildContext context, NavigationState state) {
|
||||
return LoginEnforcer(child: Home());
|
||||
},
|
||||
);
|
||||
return LoginEnforcer(child: Home());
|
||||
}
|
||||
|
||||
return Container();
|
||||
|
||||
25
lib/widget/app_bar.dart
Normal file
25
lib/widget/app_bar.dart
Normal file
@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hl_lieferservice/feature/settings/presentation/settings_page.dart';
|
||||
|
||||
class CustomAppBar extends StatelessWidget {
|
||||
const CustomAppBar({super.key});
|
||||
|
||||
void _openSettings(BuildContext context) {
|
||||
Navigator.of(
|
||||
context,
|
||||
).push(MaterialPageRoute(builder: (context) => SettingsPage()));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppBar(
|
||||
title: Center(child: Text("Holzleitner Lieferservice")),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () => _openSettings(context),
|
||||
icon: Icon(Icons.settings),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -6,23 +6,11 @@ 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...
|
||||
NavigationBloc() : super(NavigationInfo(navigationIndex: 0)) {
|
||||
on<NavigateToIndex>(_navigate);
|
||||
}
|
||||
}
|
||||
|
||||
void _navigate(NavigateToIndex event, Emitter<NavigationState> emit) {
|
||||
emit(NavigationInfo(navigationIndex: event.index));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
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 {}
|
||||
class NavigateToIndex extends NavigationEvent {
|
||||
int index;
|
||||
|
||||
NavigateToIndex({required this.index});
|
||||
}
|
||||
@ -1,11 +1,8 @@
|
||||
// Navigation states
|
||||
abstract class NavigationState {}
|
||||
|
||||
class NavigationInitial extends NavigationState {}
|
||||
class NavigateToRoute extends NavigationState {
|
||||
final String routeName;
|
||||
final int? index;
|
||||
final Object? arguments;
|
||||
class NavigationInfo extends NavigationState {
|
||||
int navigationIndex;
|
||||
|
||||
NavigateToRoute(this.routeName, {this.arguments, this.index});
|
||||
}
|
||||
NavigationInfo({required this.navigationIndex});
|
||||
}
|
||||
|
||||
@ -6,6 +6,10 @@ import 'package:hl_lieferservice/feature/cars/presentation/car_management_page.d
|
||||
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/feature/scan/presentation/scan_page.dart';
|
||||
import 'package:hl_lieferservice/widget/app_bar.dart';
|
||||
import 'package:hl_lieferservice/widget/home/bloc/navigation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/home/bloc/navigation_state.dart';
|
||||
import 'package:hl_lieferservice/widget/navigation_bar/presentation/navigation_bar.dart';
|
||||
|
||||
import '../../../bloc/app_bloc.dart';
|
||||
@ -23,20 +27,18 @@ class Home extends StatefulWidget {
|
||||
}
|
||||
|
||||
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));
|
||||
context.read<TourBloc>().add(LoadTour(teamId: state.user.number));
|
||||
}
|
||||
|
||||
Widget _buildPage(index) {
|
||||
if (index == 0) {
|
||||
return Container();
|
||||
return ScanPage();
|
||||
}
|
||||
|
||||
if (index == 1) {
|
||||
@ -60,20 +62,21 @@ class _HomeState extends State<Home> {
|
||||
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),
|
||||
return BlocBuilder<NavigationBloc, NavigationState>(
|
||||
builder: (context, state) {
|
||||
final currentState = state as NavigationInfo;
|
||||
|
||||
return Scaffold(
|
||||
appBar: PreferredSize(
|
||||
preferredSize: Size.fromHeight(kToolbarHeight),
|
||||
child: CustomAppBar(),
|
||||
),
|
||||
body: _buildPage(currentState.navigationIndex),
|
||||
bottomNavigationBar: AppNavigationBar(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,27 +1,24 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/home/bloc/navigation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/home/bloc/navigation_event.dart';
|
||||
import 'package:hl_lieferservice/widget/home/bloc/navigation_state.dart';
|
||||
|
||||
class AppNavigationBar extends StatefulWidget {
|
||||
final Function(int) onSelect;
|
||||
|
||||
const AppNavigationBar({required this.onSelect});
|
||||
const AppNavigationBar({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _AppNavigationBarState();
|
||||
}
|
||||
|
||||
class _AppNavigationBarState extends State<AppNavigationBar> {
|
||||
int _selectedPage = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<NavigationBloc, NavigationState>(
|
||||
builder: (context, state) {
|
||||
if (state is NavigateToRoute) {
|
||||
if (state is NavigationInfo) {
|
||||
return NavigationBar(
|
||||
selectedIndex: _selectedPage,
|
||||
selectedIndex: state.navigationIndex,
|
||||
destinations: const [
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.barcode_reader),
|
||||
@ -37,11 +34,7 @@ class _AppNavigationBarState extends State<AppNavigationBar> {
|
||||
),
|
||||
],
|
||||
onDestinationSelected: (int index) {
|
||||
widget.onSelect(index);
|
||||
|
||||
setState(() {
|
||||
_selectedPage = index;
|
||||
});
|
||||
context.read<NavigationBloc>().add(NavigateToIndex(index: index));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user