feat: Allow pre-filling order creation forms with reorder data and update reorder navigation to directly open relevant order pages.

This commit is contained in:
Achintha Isuru
2026-02-22 01:37:49 -05:00
parent 036920377e
commit 3aab5bfc26
11 changed files with 272 additions and 119 deletions

View File

@@ -137,36 +137,36 @@ extension ClientNavigator on IModularNavigator {
/// Pushes the order creation flow entry page.
///
/// This is the starting point for all order creation flows.
void toCreateOrder() {
pushNamed(ClientPaths.createOrder);
void toCreateOrder({Object? arguments}) {
pushNamed(ClientPaths.createOrder, arguments: arguments);
}
/// Pushes the rapid order creation flow.
///
/// Quick shift creation with simplified inputs for urgent needs.
void toCreateOrderRapid() {
pushNamed(ClientPaths.createOrderRapid);
void toCreateOrderRapid({Object? arguments}) {
pushNamed(ClientPaths.createOrderRapid, arguments: arguments);
}
/// Pushes the one-time order creation flow.
///
/// Create a shift that occurs once at a specific date and time.
void toCreateOrderOneTime() {
pushNamed(ClientPaths.createOrderOneTime);
void toCreateOrderOneTime({Object? arguments}) {
pushNamed(ClientPaths.createOrderOneTime, arguments: arguments);
}
/// Pushes the recurring order creation flow.
///
/// Create shifts that repeat on a defined schedule (daily, weekly, etc.).
void toCreateOrderRecurring() {
pushNamed(ClientPaths.createOrderRecurring);
void toCreateOrderRecurring({Object? arguments}) {
pushNamed(ClientPaths.createOrderRecurring, arguments: arguments);
}
/// Pushes the permanent order creation flow.
///
/// Create a long-term or permanent staffing position.
void toCreateOrderPermanent() {
pushNamed(ClientPaths.createOrderPermanent);
void toCreateOrderPermanent({Object? arguments}) {
pushNamed(ClientPaths.createOrderPermanent, arguments: arguments);
}
// ==========================================================================

View File

@@ -5,8 +5,6 @@ import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_core/core.dart';
import 'package:krow_domain/krow_domain.dart';
import 'client_home_sheets.dart';
/// A widget that allows clients to reorder recent shifts.
class ReorderWidget extends StatelessWidget {
/// Creates a [ReorderWidget].
@@ -173,29 +171,28 @@ class ReorderWidget extends StatelessWidget {
}
void _handleReorderPressed(BuildContext context, Map<String, dynamic> data) {
ClientHomeSheets.showOrderFormSheet(
context,
data,
onSubmit: (Map<String, dynamic> submittedData) {
final String? typeStr = submittedData['type']?.toString();
if (typeStr == null || typeStr.isEmpty) {
return;
}
final OrderType orderType = OrderType.fromString(typeStr);
switch (orderType) {
case OrderType.recurring:
Modular.to.toCreateOrderRecurring();
break;
case OrderType.permanent:
Modular.to.toCreateOrderPermanent();
break;
case OrderType.oneTime:
default:
Modular.to.toCreateOrderOneTime();
break;
}
},
);
// Override start date with today's date as requested
final Map<String, dynamic> populatedData = Map<String, dynamic>.from(data)
..['startDate'] = DateTime.now();
final String? typeStr = populatedData['type']?.toString();
if (typeStr == null || typeStr.isEmpty) {
return;
}
final OrderType orderType = OrderType.fromString(typeStr);
switch (orderType) {
case OrderType.recurring:
Modular.to.toCreateOrderRecurring(arguments: populatedData);
break;
case OrderType.permanent:
Modular.to.toCreateOrderPermanent(arguments: populatedData);
break;
case OrderType.oneTime:
default:
Modular.to.toCreateOrderOneTime(arguments: populatedData);
break;
}
}
}

View File

@@ -11,7 +11,9 @@ import 'one_time_order_state.dart';
/// BLoC for managing the multi-step one-time order creation form.
class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
with BlocErrorHandler<OneTimeOrderState>, SafeBloc<OneTimeOrderEvent, OneTimeOrderState> {
with
BlocErrorHandler<OneTimeOrderState>,
SafeBloc<OneTimeOrderEvent, OneTimeOrderState> {
OneTimeOrderBloc(this._createOneTimeOrderUseCase, this._service)
: super(OneTimeOrderState.initial()) {
on<OneTimeOrderVendorsLoaded>(_onVendorsLoaded);
@@ -24,6 +26,7 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
on<OneTimeOrderPositionRemoved>(_onPositionRemoved);
on<OneTimeOrderPositionUpdated>(_onPositionUpdated);
on<OneTimeOrderSubmitted>(_onSubmitted);
on<OneTimeOrderInitialized>(_onInitialized);
_loadVendors();
_loadHubs();
@@ -34,8 +37,10 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
Future<void> _loadVendors() async {
final List<Vendor>? vendors = await handleErrorWithResult(
action: () async {
final QueryResult<dc.ListVendorsData, void> result =
await _service.connector.listVendors().execute();
final QueryResult<dc.ListVendorsData, void> result = await _service
.connector
.listVendors()
.execute();
return result.data.vendors
.map(
(dc.ListVendorsVendors vendor) => Vendor(
@@ -54,11 +59,19 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
}
}
Future<void> _loadRolesForVendor(String vendorId, Emitter<OneTimeOrderState> emit) async {
Future<void> _loadRolesForVendor(
String vendorId,
Emitter<OneTimeOrderState> emit,
) async {
final List<OneTimeOrderRoleOption>? roles = await handleErrorWithResult(
action: () async {
final QueryResult<dc.ListRolesByVendorIdData, dc.ListRolesByVendorIdVariables>
result = await _service.connector.listRolesByVendorId(vendorId: vendorId).execute();
final QueryResult<
dc.ListRolesByVendorIdData,
dc.ListRolesByVendorIdVariables
>
result = await _service.connector
.listRolesByVendorId(vendorId: vendorId)
.execute();
return result.data.roles
.map(
(dc.ListRolesByVendorIdRoles role) => OneTimeOrderRoleOption(
@@ -69,7 +82,8 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
)
.toList();
},
onError: (_) => emit(state.copyWith(roles: const <OneTimeOrderRoleOption>[])),
onError: (_) =>
emit(state.copyWith(roles: const <OneTimeOrderRoleOption>[])),
);
if (roles != null) {
@@ -81,7 +95,10 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
final List<OneTimeOrderHubOption>? hubs = await handleErrorWithResult(
action: () async {
final String businessId = await _service.getBusinessId();
final QueryResult<dc.ListTeamHubsByOwnerIdData, dc.ListTeamHubsByOwnerIdVariables>
final QueryResult<
dc.ListTeamHubsByOwnerIdData,
dc.ListTeamHubsByOwnerIdVariables
>
result = await _service.connector
.listTeamHubsByOwnerId(ownerId: businessId)
.execute();
@@ -103,7 +120,8 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
)
.toList();
},
onError: (_) => add(const OneTimeOrderHubsLoaded(<OneTimeOrderHubOption>[])),
onError: (_) =>
add(const OneTimeOrderHubsLoaded(<OneTimeOrderHubOption>[])),
);
if (hubs != null) {
@@ -115,13 +133,11 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
OneTimeOrderVendorsLoaded event,
Emitter<OneTimeOrderState> emit,
) async {
final Vendor? selectedVendor =
event.vendors.isNotEmpty ? event.vendors.first : null;
final Vendor? selectedVendor = event.vendors.isNotEmpty
? event.vendors.first
: null;
emit(
state.copyWith(
vendors: event.vendors,
selectedVendor: selectedVendor,
),
state.copyWith(vendors: event.vendors, selectedVendor: selectedVendor),
);
if (selectedVendor != null) {
await _loadRolesForVendor(selectedVendor.id, emit);
@@ -140,8 +156,9 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
OneTimeOrderHubsLoaded event,
Emitter<OneTimeOrderState> emit,
) {
final OneTimeOrderHubOption? selectedHub =
event.hubs.isNotEmpty ? event.hubs.first : null;
final OneTimeOrderHubOption? selectedHub = event.hubs.isNotEmpty
? event.hubs.first
: null;
emit(
state.copyWith(
hubs: event.hubs,
@@ -155,12 +172,7 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
OneTimeOrderHubChanged event,
Emitter<OneTimeOrderState> emit,
) {
emit(
state.copyWith(
selectedHub: event.hub,
location: event.hub.name,
),
);
emit(state.copyWith(selectedHub: event.hub, location: event.hub.name));
}
void _onEventNameChanged(
@@ -261,4 +273,29 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
),
);
}
void _onInitialized(
OneTimeOrderInitialized event,
Emitter<OneTimeOrderState> emit,
) {
final Map<String, dynamic> data = event.data;
final String title = data['title']?.toString() ?? '';
final int workers = (data['workers'] as int?) ?? 1;
final DateTime? startDate = data['startDate'] as DateTime?;
emit(
state.copyWith(
eventName: title,
date: startDate ?? DateTime.now(),
positions: <OneTimeOrderPosition>[
OneTimeOrderPosition(
role: data['roleName']?.toString() ?? '',
count: workers,
startTime: data['startTime']?.toString() ?? '09:00',
endTime: data['endTime']?.toString() ?? '17:00',
),
],
),
);
}
}

View File

@@ -81,3 +81,11 @@ class OneTimeOrderPositionUpdated extends OneTimeOrderEvent {
class OneTimeOrderSubmitted extends OneTimeOrderEvent {
const OneTimeOrderSubmitted();
}
class OneTimeOrderInitialized extends OneTimeOrderEvent {
const OneTimeOrderInitialized(this.data);
final Map<String, dynamic> data;
@override
List<Object?> get props => <Object?>[data];
}

View File

@@ -10,9 +10,11 @@ import 'permanent_order_state.dart';
/// BLoC for managing the permanent order creation form.
class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
with BlocErrorHandler<PermanentOrderState>, SafeBloc<PermanentOrderEvent, PermanentOrderState> {
with
BlocErrorHandler<PermanentOrderState>,
SafeBloc<PermanentOrderEvent, PermanentOrderState> {
PermanentOrderBloc(this._createPermanentOrderUseCase, this._service)
: super(PermanentOrderState.initial()) {
: super(PermanentOrderState.initial()) {
on<PermanentOrderVendorsLoaded>(_onVendorsLoaded);
on<PermanentOrderVendorChanged>(_onVendorChanged);
on<PermanentOrderHubsLoaded>(_onHubsLoaded);
@@ -24,6 +26,7 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
on<PermanentOrderPositionRemoved>(_onPositionRemoved);
on<PermanentOrderPositionUpdated>(_onPositionUpdated);
on<PermanentOrderSubmitted>(_onSubmitted);
on<PermanentOrderInitialized>(_onInitialized);
_loadVendors();
_loadHubs();
@@ -45,8 +48,10 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
Future<void> _loadVendors() async {
final List<domain.Vendor>? vendors = await handleErrorWithResult(
action: () async {
final QueryResult<dc.ListVendorsData, void> result =
await _service.connector.listVendors().execute();
final QueryResult<dc.ListVendorsData, void> result = await _service
.connector
.listVendors()
.execute();
return result.data.vendors
.map(
(dc.ListVendorsVendors vendor) => domain.Vendor(
@@ -71,10 +76,13 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
) async {
final List<PermanentOrderRoleOption>? roles = await handleErrorWithResult(
action: () async {
final QueryResult<dc.ListRolesByVendorIdData, dc.ListRolesByVendorIdVariables>
result = await _service.connector
.listRolesByVendorId(vendorId: vendorId)
.execute();
final QueryResult<
dc.ListRolesByVendorIdData,
dc.ListRolesByVendorIdVariables
>
result = await _service.connector
.listRolesByVendorId(vendorId: vendorId)
.execute();
return result.data.roles
.map(
(dc.ListRolesByVendorIdRoles role) => PermanentOrderRoleOption(
@@ -85,7 +93,8 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
)
.toList();
},
onError: (_) => emit(state.copyWith(roles: const <PermanentOrderRoleOption>[])),
onError: (_) =>
emit(state.copyWith(roles: const <PermanentOrderRoleOption>[])),
);
if (roles != null) {
@@ -97,10 +106,13 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
final List<PermanentOrderHubOption>? hubs = await handleErrorWithResult(
action: () async {
final String businessId = await _service.getBusinessId();
final QueryResult<dc.ListTeamHubsByOwnerIdData, dc.ListTeamHubsByOwnerIdVariables>
result = await _service.connector
.listTeamHubsByOwnerId(ownerId: businessId)
.execute();
final QueryResult<
dc.ListTeamHubsByOwnerIdData,
dc.ListTeamHubsByOwnerIdVariables
>
result = await _service.connector
.listTeamHubsByOwnerId(ownerId: businessId)
.execute();
return result.data.teamHubs
.map(
(dc.ListTeamHubsByOwnerIdTeamHubs hub) => PermanentOrderHubOption(
@@ -119,7 +131,8 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
)
.toList();
},
onError: (_) => add(const PermanentOrderHubsLoaded(<PermanentOrderHubOption>[])),
onError: (_) =>
add(const PermanentOrderHubsLoaded(<PermanentOrderHubOption>[])),
);
if (hubs != null) {
@@ -131,13 +144,11 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
PermanentOrderVendorsLoaded event,
Emitter<PermanentOrderState> emit,
) async {
final domain.Vendor? selectedVendor =
event.vendors.isNotEmpty ? event.vendors.first : null;
final domain.Vendor? selectedVendor = event.vendors.isNotEmpty
? event.vendors.first
: null;
emit(
state.copyWith(
vendors: event.vendors,
selectedVendor: selectedVendor,
),
state.copyWith(vendors: event.vendors, selectedVendor: selectedVendor),
);
if (selectedVendor != null) {
await _loadRolesForVendor(selectedVendor.id, emit);
@@ -156,8 +167,9 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
PermanentOrderHubsLoaded event,
Emitter<PermanentOrderState> emit,
) {
final PermanentOrderHubOption? selectedHub =
event.hubs.isNotEmpty ? event.hubs.first : null;
final PermanentOrderHubOption? selectedHub = event.hubs.isNotEmpty
? event.hubs.first
: null;
emit(
state.copyWith(
hubs: event.hubs,
@@ -171,12 +183,7 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
PermanentOrderHubChanged event,
Emitter<PermanentOrderState> emit,
) {
emit(
state.copyWith(
selectedHub: event.hub,
location: event.hub.name,
),
);
emit(state.copyWith(selectedHub: event.hub, location: event.hub.name));
}
void _onEventNameChanged(
@@ -226,7 +233,12 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
} else {
days.add(label);
}
emit(state.copyWith(permanentDays: _sortDays(days), autoSelectedDayIndex: autoIndex));
emit(
state.copyWith(
permanentDays: _sortDays(days),
autoSelectedDayIndex: autoIndex,
),
);
}
void _onPositionAdded(
@@ -325,6 +337,31 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
);
}
void _onInitialized(
PermanentOrderInitialized event,
Emitter<PermanentOrderState> emit,
) {
final Map<String, dynamic> data = event.data;
final String title = data['title']?.toString() ?? '';
final int workers = (data['workers'] as int?) ?? 1;
final DateTime? startDate = data['startDate'] as DateTime?;
emit(
state.copyWith(
eventName: title,
startDate: startDate ?? DateTime.now(),
positions: <PermanentOrderPosition>[
PermanentOrderPosition(
role: data['roleName']?.toString() ?? '',
count: workers,
startTime: data['startTime']?.toString() ?? '09:00',
endTime: data['endTime']?.toString() ?? '17:00',
),
],
),
);
}
static List<String> _sortDays(List<String> days) {
days.sort(
(String a, String b) =>

View File

@@ -98,3 +98,11 @@ class PermanentOrderPositionUpdated extends PermanentOrderEvent {
class PermanentOrderSubmitted extends PermanentOrderEvent {
const PermanentOrderSubmitted();
}
class PermanentOrderInitialized extends PermanentOrderEvent {
const PermanentOrderInitialized(this.data);
final Map<String, dynamic> data;
@override
List<Object?> get props => <Object?>[data];
}

View File

@@ -10,9 +10,11 @@ import 'recurring_order_state.dart';
/// BLoC for managing the recurring order creation form.
class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
with BlocErrorHandler<RecurringOrderState>, SafeBloc<RecurringOrderEvent, RecurringOrderState> {
with
BlocErrorHandler<RecurringOrderState>,
SafeBloc<RecurringOrderEvent, RecurringOrderState> {
RecurringOrderBloc(this._createRecurringOrderUseCase, this._service)
: super(RecurringOrderState.initial()) {
: super(RecurringOrderState.initial()) {
on<RecurringOrderVendorsLoaded>(_onVendorsLoaded);
on<RecurringOrderVendorChanged>(_onVendorChanged);
on<RecurringOrderHubsLoaded>(_onHubsLoaded);
@@ -25,6 +27,7 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
on<RecurringOrderPositionRemoved>(_onPositionRemoved);
on<RecurringOrderPositionUpdated>(_onPositionUpdated);
on<RecurringOrderSubmitted>(_onSubmitted);
on<RecurringOrderInitialized>(_onInitialized);
_loadVendors();
_loadHubs();
@@ -46,8 +49,10 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
Future<void> _loadVendors() async {
final List<domain.Vendor>? vendors = await handleErrorWithResult(
action: () async {
final QueryResult<dc.ListVendorsData, void> result =
await _service.connector.listVendors().execute();
final QueryResult<dc.ListVendorsData, void> result = await _service
.connector
.listVendors()
.execute();
return result.data.vendors
.map(
(dc.ListVendorsVendors vendor) => domain.Vendor(
@@ -72,10 +77,13 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
) async {
final List<RecurringOrderRoleOption>? roles = await handleErrorWithResult(
action: () async {
final QueryResult<dc.ListRolesByVendorIdData, dc.ListRolesByVendorIdVariables>
result = await _service.connector
.listRolesByVendorId(vendorId: vendorId)
.execute();
final QueryResult<
dc.ListRolesByVendorIdData,
dc.ListRolesByVendorIdVariables
>
result = await _service.connector
.listRolesByVendorId(vendorId: vendorId)
.execute();
return result.data.roles
.map(
(dc.ListRolesByVendorIdRoles role) => RecurringOrderRoleOption(
@@ -86,7 +94,8 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
)
.toList();
},
onError: (_) => emit(state.copyWith(roles: const <RecurringOrderRoleOption>[])),
onError: (_) =>
emit(state.copyWith(roles: const <RecurringOrderRoleOption>[])),
);
if (roles != null) {
@@ -98,10 +107,13 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
final List<RecurringOrderHubOption>? hubs = await handleErrorWithResult(
action: () async {
final String businessId = await _service.getBusinessId();
final QueryResult<dc.ListTeamHubsByOwnerIdData, dc.ListTeamHubsByOwnerIdVariables>
result = await _service.connector
.listTeamHubsByOwnerId(ownerId: businessId)
.execute();
final QueryResult<
dc.ListTeamHubsByOwnerIdData,
dc.ListTeamHubsByOwnerIdVariables
>
result = await _service.connector
.listTeamHubsByOwnerId(ownerId: businessId)
.execute();
return result.data.teamHubs
.map(
(dc.ListTeamHubsByOwnerIdTeamHubs hub) => RecurringOrderHubOption(
@@ -120,7 +132,8 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
)
.toList();
},
onError: (_) => add(const RecurringOrderHubsLoaded(<RecurringOrderHubOption>[])),
onError: (_) =>
add(const RecurringOrderHubsLoaded(<RecurringOrderHubOption>[])),
);
if (hubs != null) {
@@ -132,13 +145,11 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
RecurringOrderVendorsLoaded event,
Emitter<RecurringOrderState> emit,
) async {
final domain.Vendor? selectedVendor =
event.vendors.isNotEmpty ? event.vendors.first : null;
final domain.Vendor? selectedVendor = event.vendors.isNotEmpty
? event.vendors.first
: null;
emit(
state.copyWith(
vendors: event.vendors,
selectedVendor: selectedVendor,
),
state.copyWith(vendors: event.vendors, selectedVendor: selectedVendor),
);
if (selectedVendor != null) {
await _loadRolesForVendor(selectedVendor.id, emit);
@@ -157,8 +168,9 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
RecurringOrderHubsLoaded event,
Emitter<RecurringOrderState> emit,
) {
final RecurringOrderHubOption? selectedHub =
event.hubs.isNotEmpty ? event.hubs.first : null;
final RecurringOrderHubOption? selectedHub = event.hubs.isNotEmpty
? event.hubs.first
: null;
emit(
state.copyWith(
hubs: event.hubs,
@@ -172,12 +184,7 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
RecurringOrderHubChanged event,
Emitter<RecurringOrderState> emit,
) {
emit(
state.copyWith(
selectedHub: event.hub,
location: event.hub.name,
),
);
emit(state.copyWith(selectedHub: event.hub, location: event.hub.name));
}
void _onEventNameChanged(
@@ -243,7 +250,12 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
} else {
days.add(label);
}
emit(state.copyWith(recurringDays: _sortDays(days), autoSelectedDayIndex: autoIndex));
emit(
state.copyWith(
recurringDays: _sortDays(days),
autoSelectedDayIndex: autoIndex,
),
);
}
void _onPositionAdded(
@@ -344,6 +356,31 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
);
}
void _onInitialized(
RecurringOrderInitialized event,
Emitter<RecurringOrderState> emit,
) {
final Map<String, dynamic> data = event.data;
final String title = data['title']?.toString() ?? '';
final int workers = (data['workers'] as int?) ?? 1;
final DateTime? startDate = data['startDate'] as DateTime?;
emit(
state.copyWith(
eventName: title,
startDate: startDate ?? DateTime.now(),
positions: <RecurringOrderPosition>[
RecurringOrderPosition(
role: data['roleName']?.toString() ?? '',
count: workers,
startTime: data['startTime']?.toString() ?? '09:00',
endTime: data['endTime']?.toString() ?? '17:00',
),
],
),
);
}
static List<String> _sortDays(List<String> days) {
days.sort(
(String a, String b) =>

View File

@@ -107,3 +107,11 @@ class RecurringOrderPositionUpdated extends RecurringOrderEvent {
class RecurringOrderSubmitted extends RecurringOrderEvent {
const RecurringOrderSubmitted();
}
class RecurringOrderInitialized extends RecurringOrderEvent {
const RecurringOrderInitialized(this.data);
final Map<String, dynamic> data;
@override
List<Object?> get props => <Object?>[data];
}

View File

@@ -21,7 +21,14 @@ class OneTimeOrderPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider<OneTimeOrderBloc>(
create: (BuildContext context) => Modular.get<OneTimeOrderBloc>(),
create: (BuildContext context) {
final OneTimeOrderBloc bloc = Modular.get<OneTimeOrderBloc>();
final dynamic args = Modular.args.data;
if (args is Map<String, dynamic>) {
bloc.add(OneTimeOrderInitialized(args));
}
return bloc;
},
child: BlocBuilder<OneTimeOrderBloc, OneTimeOrderState>(
builder: (BuildContext context, OneTimeOrderState state) {
final OneTimeOrderBloc bloc = BlocProvider.of<OneTimeOrderBloc>(

View File

@@ -16,7 +16,14 @@ class PermanentOrderPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider<PermanentOrderBloc>(
create: (BuildContext context) => Modular.get<PermanentOrderBloc>(),
create: (BuildContext context) {
final PermanentOrderBloc bloc = Modular.get<PermanentOrderBloc>();
final dynamic args = Modular.args.data;
if (args is Map<String, dynamic>) {
bloc.add(PermanentOrderInitialized(args));
}
return bloc;
},
child: BlocBuilder<PermanentOrderBloc, PermanentOrderState>(
builder: (BuildContext context, PermanentOrderState state) {
final PermanentOrderBloc bloc = BlocProvider.of<PermanentOrderBloc>(

View File

@@ -16,7 +16,14 @@ class RecurringOrderPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider<RecurringOrderBloc>(
create: (BuildContext context) => Modular.get<RecurringOrderBloc>(),
create: (BuildContext context) {
final RecurringOrderBloc bloc = Modular.get<RecurringOrderBloc>();
final dynamic args = Modular.args.data;
if (args is Map<String, dynamic>) {
bloc.add(RecurringOrderInitialized(args));
}
return bloc;
},
child: BlocBuilder<RecurringOrderBloc, RecurringOrderState>(
builder: (BuildContext context, RecurringOrderState state) {
final RecurringOrderBloc bloc = BlocProvider.of<RecurringOrderBloc>(