Implemented settings, new scan, enhanced UI/UX
This commit is contained in:
@ -8,6 +8,24 @@ class CarsLoading extends CarsState {}
|
||||
|
||||
class CarsLoadingFailed extends CarsState {}
|
||||
|
||||
class CarAdded extends CarsState {
|
||||
Car car;
|
||||
|
||||
CarAdded({required this.car});
|
||||
}
|
||||
|
||||
class CarDeleted extends CarsState {
|
||||
String plate;
|
||||
|
||||
CarDeleted({required this.plate});
|
||||
}
|
||||
|
||||
class CarEdited extends CarsState {
|
||||
Car car;
|
||||
|
||||
CarEdited({required this.car});
|
||||
}
|
||||
|
||||
class CarsLoaded extends CarsState {
|
||||
List<Car> cars;
|
||||
String teamId;
|
||||
@ -15,9 +33,6 @@ class CarsLoaded extends CarsState {
|
||||
CarsLoaded({required this.cars, required this.teamId});
|
||||
|
||||
CarsLoaded copyWith({List<Car>? cars, String? teamId}) {
|
||||
return CarsLoaded(
|
||||
cars: cars ?? this.cars,
|
||||
teamId: teamId ?? this.teamId,
|
||||
);
|
||||
return CarsLoaded(cars: cars ?? this.cars, teamId: teamId ?? this.teamId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,9 @@ import 'package:hl_lieferservice/feature/cars/bloc/cars_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/cars/bloc/cars_event.dart';
|
||||
import 'package:hl_lieferservice/feature/cars/bloc/cars_state.dart';
|
||||
import 'package:hl_lieferservice/feature/cars/presentation/car_management.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/bloc/tour_state.dart';
|
||||
import 'package:hl_lieferservice/model/car.dart';
|
||||
|
||||
class CarManagementPage extends StatefulWidget {
|
||||
@ -24,18 +27,18 @@ class _CarManagementPageState extends State<CarManagementPage> {
|
||||
|
||||
// Load cars
|
||||
_authState = context.read<AuthBloc>().state as Authenticated;
|
||||
context.read<CarsBloc>().add(CarLoad(teamId: _authState.teamId));
|
||||
context.read<CarsBloc>().add(CarLoad(teamId: _authState.user.number));
|
||||
}
|
||||
|
||||
void _add(String plate) {
|
||||
context.read<CarsBloc>().add(
|
||||
CarAdd(teamId: _authState.teamId, plate: plate),
|
||||
CarAdd(teamId: _authState.user.number, plate: plate),
|
||||
);
|
||||
}
|
||||
|
||||
void _remove(String id) {
|
||||
context.read<CarsBloc>().add(
|
||||
CarDelete(carId: id, teamId: _authState.teamId),
|
||||
CarDelete(carId: id, teamId: _authState.user.number),
|
||||
);
|
||||
}
|
||||
|
||||
@ -43,7 +46,7 @@ class _CarManagementPageState extends State<CarManagementPage> {
|
||||
context.read<CarsBloc>().add(
|
||||
CarEdit(
|
||||
newCar: Car(id: int.parse(id), plate: plate),
|
||||
teamId: _authState.teamId,
|
||||
teamId: _authState.user.number,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -51,7 +54,14 @@ class _CarManagementPageState extends State<CarManagementPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: BlocBuilder<CarsBloc, CarsState>(
|
||||
body: BlocConsumer<CarsBloc, CarsState>(
|
||||
listener: (context, state) {
|
||||
if (state is CarsLoaded) {
|
||||
var tour = (context.read<TourBloc>().state as TourLoaded).tour.copyWith();
|
||||
tour.driver.cars = state.cars;
|
||||
context.read<TourBloc>().add(UpdateTour(tour: tour));
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
debugPrint('BlocBuilder rebuilding with state: $state');
|
||||
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:docuframe/docuframe.dart' as df;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/exceptions.dart';
|
||||
import 'package:hl_lieferservice/services/erpframe.dart';
|
||||
import 'package:hl_lieferservice/util.dart';
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../../dto/basic_response.dart';
|
||||
import '../../../dto/car_add.dart';
|
||||
@ -14,23 +17,31 @@ class CarService extends ErpFrameService {
|
||||
CarService({required super.config});
|
||||
|
||||
Future<Car> addCar(String plate, int teamId) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session).execute(
|
||||
"_web_addCar",
|
||||
parameter: CarAddDTO.make(teamId, plate).toJson()
|
||||
as Map<String, dynamic>);
|
||||
debugPrint(jsonEncode({"team_id": teamId.toString(), "plate": plate}));
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
debugPrint(responseJson.toString());
|
||||
var response = await post(
|
||||
urlBuilder("_web_addCar"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"team_id": teamId.toString(), "plate": plate},
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
var body = response.body;
|
||||
|
||||
debugPrint("BODY: $body");
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(body);
|
||||
CarAddResponseDTO responseDto = CarAddResponseDTO.fromJson(responseJson);
|
||||
|
||||
if (responseDto.succeeded == true) {
|
||||
return Car(
|
||||
id: int.parse(responseDto.car.id), plate: responseDto.car.plate);
|
||||
id: int.parse(responseDto.car.id),
|
||||
plate: responseDto.car.plate,
|
||||
);
|
||||
} else {
|
||||
throw responseDto.message;
|
||||
}
|
||||
@ -40,26 +51,22 @@ class CarService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> editCar(Car car) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
var response = await post(
|
||||
urlBuilder("_web_editCar"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"id": car.id.toString(), "plate": car.plate},
|
||||
);
|
||||
|
||||
debugPrint(car.plate);
|
||||
debugPrint(car.id.toString());
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session).execute(
|
||||
"_web_editCar",
|
||||
parameter: {"id": car.id, "plate": car.plate});
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
debugPrint(responseJson.toString());
|
||||
|
||||
BasicResponseDTO responseDto = BasicResponseDTO.fromJson(responseJson);
|
||||
@ -75,22 +82,22 @@ class CarService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeCar(int carId, int teamId) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session).execute(
|
||||
"_web_removeCar",
|
||||
parameter: {"team_id": teamId, "id": carId});
|
||||
var response = await post(
|
||||
urlBuilder("_web_removeCar"),
|
||||
headers: getSessionOrThrow(),
|
||||
body: {"team_id": teamId.toString(), "id": carId.toString()},
|
||||
);
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
debugPrint(responseJson.toString());
|
||||
BasicResponseDTO responseDto = BasicResponseDTO.fromJson(responseJson);
|
||||
|
||||
@ -105,25 +112,28 @@ class CarService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<Car>> getCars(int teamId) async {
|
||||
df.LoginSession? session;
|
||||
|
||||
try {
|
||||
session = await getSession();
|
||||
df.DocuFrameMacroResponse response =
|
||||
await df.Macro(config: dfConfig, session: session)
|
||||
.execute("_web_getCars", parameter: {"team_id": teamId});
|
||||
|
||||
debugPrint(teamId.toString());
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body!);
|
||||
debugPrint("RESPONSE");
|
||||
debugPrint(responseJson.toString());
|
||||
var response = await post(
|
||||
urlBuilder("_web_getCars"),
|
||||
headers: getSessionOrThrow(),
|
||||
body:{"team_id": teamId.toString()},
|
||||
);
|
||||
|
||||
if (response.statusCode == HttpStatus.unauthorized) {
|
||||
throw UserUnauthorized();
|
||||
}
|
||||
|
||||
var body = response.body;
|
||||
|
||||
debugPrint("BODY: $body");
|
||||
|
||||
Map<String, dynamic> responseJson = jsonDecode(response.body);
|
||||
CarGetResponseDTO responseDto = CarGetResponseDTO.fromJson(responseJson);
|
||||
|
||||
if (responseDto.succeeded == true) {
|
||||
@ -139,8 +149,6 @@ class CarService extends ErpFrameService {
|
||||
debugPrint(st.toString());
|
||||
|
||||
rethrow;
|
||||
} finally {
|
||||
await logout(session);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user