feat: ReorderWidget and ActionsWidget now handle their own navigation internally, removing external callbacks.
This commit is contained in:
@@ -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(),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,7 +150,8 @@ class ReorderWidget extends StatelessWidget {
|
||||
leadingIcon: UiIcons.zap,
|
||||
iconSize: 12,
|
||||
fullWidth: true,
|
||||
onPressed: () => onReorderPressed(<String, dynamic>{
|
||||
onPressed: () =>
|
||||
_handleReorderPressed(context, <String, dynamic>{
|
||||
'orderId': order.orderId,
|
||||
'title': order.title,
|
||||
'location': order.location,
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user