save
This commit is contained in:
@@ -81,32 +81,24 @@ class AppRouter {
|
||||
),
|
||||
|
||||
/// Products List Route
|
||||
/// Path: /products
|
||||
/// Takes warehouse, warehouseName, and operationType as extra parameter
|
||||
/// Path: /products/:warehouseId/:operationType
|
||||
/// Query params: name (warehouse name)
|
||||
/// Shows products for selected warehouse and operation
|
||||
GoRoute(
|
||||
path: '/products',
|
||||
path: '/products/:warehouseId/:operationType',
|
||||
name: 'products',
|
||||
builder: (context, state) {
|
||||
final params = state.extra as Map<String, dynamic>?;
|
||||
// Extract path parameters
|
||||
final warehouseIdStr = state.pathParameters['warehouseId'];
|
||||
final operationType = state.pathParameters['operationType'];
|
||||
|
||||
if (params == null) {
|
||||
// If no params, redirect to warehouses
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.go('/warehouses');
|
||||
});
|
||||
return const _ErrorScreen(
|
||||
message: 'Product parameters are required',
|
||||
);
|
||||
}
|
||||
// Extract query parameter
|
||||
final warehouseName = state.uri.queryParameters['name'];
|
||||
|
||||
// Extract required parameters
|
||||
final warehouse = params['warehouse'] as WarehouseEntity?;
|
||||
final warehouseName = params['warehouseName'] as String?;
|
||||
final operationType = params['operationType'] as String?;
|
||||
// Parse and validate parameters
|
||||
final warehouseId = int.tryParse(warehouseIdStr ?? '');
|
||||
|
||||
// Validate parameters
|
||||
if (warehouse == null || warehouseName == null || operationType == null) {
|
||||
if (warehouseId == null || warehouseName == null || operationType == null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.go('/warehouses');
|
||||
});
|
||||
@@ -116,7 +108,7 @@ class AppRouter {
|
||||
}
|
||||
|
||||
return ProductsPage(
|
||||
warehouseId: warehouse.id,
|
||||
warehouseId: warehouseId,
|
||||
warehouseName: warehouseName,
|
||||
operationType: operationType,
|
||||
);
|
||||
@@ -124,34 +116,28 @@ class AppRouter {
|
||||
),
|
||||
|
||||
/// Product Detail Route
|
||||
/// Path: /product-detail
|
||||
/// Takes warehouseId, productId, warehouseName, and optional stageId as extra parameter
|
||||
/// Path: /product-detail/:warehouseId/:productId/:operationType
|
||||
/// Query params: name (warehouse name), stageId (optional)
|
||||
/// Shows detailed information for a specific product
|
||||
/// If stageId is provided, only that stage is shown, otherwise all stages are shown
|
||||
GoRoute(
|
||||
path: '/product-detail',
|
||||
path: '/product-detail/:warehouseId/:productId/:operationType',
|
||||
name: 'product-detail',
|
||||
builder: (context, state) {
|
||||
final params = state.extra as Map<String, dynamic>?;
|
||||
// Extract path parameters
|
||||
final warehouseIdStr = state.pathParameters['warehouseId'];
|
||||
final productIdStr = state.pathParameters['productId'];
|
||||
final operationType = state.pathParameters['operationType'] ?? 'import';
|
||||
|
||||
if (params == null) {
|
||||
// If no params, redirect to warehouses
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.go('/warehouses');
|
||||
});
|
||||
return const _ErrorScreen(
|
||||
message: 'Product detail parameters are required',
|
||||
);
|
||||
}
|
||||
// Extract query parameters
|
||||
final warehouseName = state.uri.queryParameters['name'];
|
||||
final stageIdStr = state.uri.queryParameters['stageId'];
|
||||
|
||||
// Extract required parameters
|
||||
final warehouseId = params['warehouseId'] as int?;
|
||||
final productId = params['productId'] as int?;
|
||||
final warehouseName = params['warehouseName'] as String?;
|
||||
// Extract optional stageId
|
||||
final stageId = params['stageId'] as int?;
|
||||
// Parse and validate parameters
|
||||
final warehouseId = int.tryParse(warehouseIdStr ?? '');
|
||||
final productId = int.tryParse(productIdStr ?? '');
|
||||
final stageId = stageIdStr != null ? int.tryParse(stageIdStr) : null;
|
||||
|
||||
// Validate parameters
|
||||
if (warehouseId == null || productId == null || warehouseName == null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.go('/warehouses');
|
||||
@@ -166,6 +152,7 @@ class AppRouter {
|
||||
productId: productId,
|
||||
warehouseName: warehouseName,
|
||||
stageId: stageId,
|
||||
operationType: operationType,
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -360,18 +347,11 @@ extension AppRouterExtension on BuildContext {
|
||||
///
|
||||
/// [warehouse] - Selected warehouse entity
|
||||
/// [operationType] - Either 'import' or 'export'
|
||||
void goToProducts({
|
||||
void pushToProducts({
|
||||
required WarehouseEntity warehouse,
|
||||
required String operationType,
|
||||
}) {
|
||||
go(
|
||||
'/products',
|
||||
extra: {
|
||||
'warehouse': warehouse,
|
||||
'warehouseName': warehouse.name,
|
||||
'operationType': operationType,
|
||||
},
|
||||
);
|
||||
push('/products/${warehouse.id}/$operationType?name=${Uri.encodeQueryComponent(warehouse.name)}');
|
||||
}
|
||||
|
||||
/// Navigate to product detail page
|
||||
@@ -379,22 +359,23 @@ extension AppRouterExtension on BuildContext {
|
||||
/// [warehouseId] - ID of the warehouse
|
||||
/// [productId] - ID of the product to view
|
||||
/// [warehouseName] - Name of the warehouse (for display)
|
||||
/// [operationType] - Either 'import' or 'export'
|
||||
/// [stageId] - Optional ID of specific stage to show (if null, show all stages)
|
||||
void goToProductDetail({
|
||||
required int warehouseId,
|
||||
required int productId,
|
||||
required String warehouseName,
|
||||
required String operationType,
|
||||
int? stageId,
|
||||
}) {
|
||||
push(
|
||||
'/product-detail',
|
||||
extra: {
|
||||
'warehouseId': warehouseId,
|
||||
'productId': productId,
|
||||
'warehouseName': warehouseName,
|
||||
if (stageId != null) 'stageId': stageId,
|
||||
},
|
||||
);
|
||||
final queryParams = <String, String>{
|
||||
'name': warehouseName,
|
||||
if (stageId != null) 'stageId': stageId.toString(),
|
||||
};
|
||||
final queryString = queryParams.entries
|
||||
.map((e) => '${e.key}=${Uri.encodeQueryComponent(e.value)}')
|
||||
.join('&');
|
||||
push('/product-detail/$warehouseId/$productId/$operationType?$queryString');
|
||||
}
|
||||
|
||||
/// Pop current route
|
||||
@@ -421,11 +402,13 @@ extension AppRouterNamedExtension on BuildContext {
|
||||
}) {
|
||||
goNamed(
|
||||
'products',
|
||||
extra: {
|
||||
'warehouse': warehouse,
|
||||
'warehouseName': warehouse.name,
|
||||
pathParameters: {
|
||||
'warehouseId': warehouse.id.toString(),
|
||||
'operationType': operationType,
|
||||
},
|
||||
queryParameters: {
|
||||
'name': warehouse.name,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user