feat: ReorderWidget and ActionsWidget now handle their own navigation internally, removing external callbacks.

This commit is contained in:
Achintha Isuru
2026-02-22 01:25:57 -05:00
parent 3b139adc33
commit 036920377e
3 changed files with 49 additions and 69 deletions

View File

@@ -1,22 +1,13 @@
import 'package:core_localization/core_localization.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_core/core.dart';
/// A widget that displays quick actions for the client.
class ActionsWidget extends StatelessWidget {
/// Creates an [ActionsWidget].
const ActionsWidget({
super.key,
required this.onRapidPressed,
required this.onCreateOrderPressed,
this.subtitle,
});
/// Callback when RAPID is pressed.
final VoidCallback onRapidPressed;
/// Callback when Create Order is pressed.
final VoidCallback onCreateOrderPressed;
const ActionsWidget({super.key, this.subtitle});
/// Optional subtitle for the section.
final String? subtitle;
@@ -40,7 +31,7 @@ class ActionsWidget extends StatelessWidget {
iconColor: UiColors.textError,
textColor: UiColors.textError,
subtitleColor: UiColors.textError.withValues(alpha: 0.8),
onTap: onRapidPressed,
onTap: () => Modular.to.toCreateOrderRapid(),
),
),
Expanded(
@@ -54,7 +45,7 @@ class ActionsWidget extends StatelessWidget {
iconColor: UiColors.primary,
textColor: UiColors.textPrimary,
subtitleColor: UiColors.textSecondary,
onTap: onCreateOrderPressed,
onTap: () => Modular.to.toCreateOrder(),
),
),
],

View File

@@ -1,7 +1,6 @@
import 'package:core_localization/core_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_domain/krow_domain.dart';
import 'package:krow_core/core.dart';
import '../blocs/client_home_state.dart';
import '../widgets/actions_widget.dart';
@@ -10,7 +9,6 @@ import '../widgets/draggable_widget_wrapper.dart';
import '../widgets/live_activity_widget.dart';
import '../widgets/reorder_widget.dart';
import '../widgets/spending_widget.dart';
import 'client_home_sheets.dart';
/// A widget that builds dashboard content based on widget ID.
///
@@ -63,41 +61,9 @@ class DashboardWidgetBuilder extends StatelessWidget {
switch (id) {
case 'actions':
return ActionsWidget(
onRapidPressed: () => Modular.to.toCreateOrderRapid(),
onCreateOrderPressed: () => Modular.to.toCreateOrder(),
subtitle: subtitle,
);
return ActionsWidget(subtitle: subtitle);
case 'reorder':
return ReorderWidget(
orders: state.reorderItems,
onReorderPressed: (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;
}
},
);
},
subtitle: subtitle,
);
return ReorderWidget(orders: state.reorderItems, subtitle: subtitle);
case 'spending':
return SpendingWidget(
weeklySpending: state.dashboardData.weeklySpending,

View File

@@ -1,24 +1,20 @@
import 'package:core_localization/core_localization.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
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].
const ReorderWidget({
super.key,
required this.orders,
required this.onReorderPressed,
this.subtitle,
});
const ReorderWidget({super.key, required this.orders, this.subtitle});
/// Recent completed orders for reorder.
final List<ReorderItem> orders;
/// Callback when a reorder button is pressed.
final Function(Map<String, dynamic> shiftData) onReorderPressed;
/// Optional subtitle for the section.
final String? subtitle;
@@ -154,16 +150,17 @@ class ReorderWidget extends StatelessWidget {
leadingIcon: UiIcons.zap,
iconSize: 12,
fullWidth: true,
onPressed: () => onReorderPressed(<String, dynamic>{
'orderId': order.orderId,
'title': order.title,
'location': order.location,
'hourlyRate': order.hourlyRate,
'hours': order.hours,
'workers': order.workers,
'type': order.type,
'totalCost': order.totalCost,
}),
onPressed: () =>
_handleReorderPressed(context, <String, dynamic>{
'orderId': order.orderId,
'title': order.title,
'location': order.location,
'hourlyRate': order.hourlyRate,
'hours': order.hours,
'workers': order.workers,
'type': order.type,
'totalCost': order.totalCost,
}),
),
],
),
@@ -174,6 +171,32 @@ 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;
}
},
);
}
}
class _Badge extends StatelessWidget {