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:core_localization/core_localization.dart';
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.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.
|
/// A widget that displays quick actions for the client.
|
||||||
class ActionsWidget extends StatelessWidget {
|
class ActionsWidget extends StatelessWidget {
|
||||||
/// Creates an [ActionsWidget].
|
/// Creates an [ActionsWidget].
|
||||||
const ActionsWidget({
|
const ActionsWidget({super.key, this.subtitle});
|
||||||
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;
|
|
||||||
|
|
||||||
/// Optional subtitle for the section.
|
/// Optional subtitle for the section.
|
||||||
final String? subtitle;
|
final String? subtitle;
|
||||||
@@ -40,7 +31,7 @@ class ActionsWidget extends StatelessWidget {
|
|||||||
iconColor: UiColors.textError,
|
iconColor: UiColors.textError,
|
||||||
textColor: UiColors.textError,
|
textColor: UiColors.textError,
|
||||||
subtitleColor: UiColors.textError.withValues(alpha: 0.8),
|
subtitleColor: UiColors.textError.withValues(alpha: 0.8),
|
||||||
onTap: onRapidPressed,
|
onTap: () => Modular.to.toCreateOrderRapid(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -54,7 +45,7 @@ class ActionsWidget extends StatelessWidget {
|
|||||||
iconColor: UiColors.primary,
|
iconColor: UiColors.primary,
|
||||||
textColor: UiColors.textPrimary,
|
textColor: UiColors.textPrimary,
|
||||||
subtitleColor: UiColors.textSecondary,
|
subtitleColor: UiColors.textSecondary,
|
||||||
onTap: onCreateOrderPressed,
|
onTap: () => Modular.to.toCreateOrder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import 'package:core_localization/core_localization.dart';
|
import 'package:core_localization/core_localization.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_modular/flutter_modular.dart';
|
import 'package:flutter_modular/flutter_modular.dart';
|
||||||
import 'package:krow_domain/krow_domain.dart';
|
|
||||||
import 'package:krow_core/core.dart';
|
import 'package:krow_core/core.dart';
|
||||||
import '../blocs/client_home_state.dart';
|
import '../blocs/client_home_state.dart';
|
||||||
import '../widgets/actions_widget.dart';
|
import '../widgets/actions_widget.dart';
|
||||||
@@ -10,7 +9,6 @@ import '../widgets/draggable_widget_wrapper.dart';
|
|||||||
import '../widgets/live_activity_widget.dart';
|
import '../widgets/live_activity_widget.dart';
|
||||||
import '../widgets/reorder_widget.dart';
|
import '../widgets/reorder_widget.dart';
|
||||||
import '../widgets/spending_widget.dart';
|
import '../widgets/spending_widget.dart';
|
||||||
import 'client_home_sheets.dart';
|
|
||||||
|
|
||||||
/// A widget that builds dashboard content based on widget ID.
|
/// A widget that builds dashboard content based on widget ID.
|
||||||
///
|
///
|
||||||
@@ -63,41 +61,9 @@ class DashboardWidgetBuilder extends StatelessWidget {
|
|||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 'actions':
|
case 'actions':
|
||||||
return ActionsWidget(
|
return ActionsWidget(subtitle: subtitle);
|
||||||
onRapidPressed: () => Modular.to.toCreateOrderRapid(),
|
|
||||||
onCreateOrderPressed: () => Modular.to.toCreateOrder(),
|
|
||||||
subtitle: subtitle,
|
|
||||||
);
|
|
||||||
case 'reorder':
|
case 'reorder':
|
||||||
return ReorderWidget(
|
return ReorderWidget(orders: state.reorderItems, subtitle: subtitle);
|
||||||
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,
|
|
||||||
);
|
|
||||||
case 'spending':
|
case 'spending':
|
||||||
return SpendingWidget(
|
return SpendingWidget(
|
||||||
weeklySpending: state.dashboardData.weeklySpending,
|
weeklySpending: state.dashboardData.weeklySpending,
|
||||||
|
|||||||
@@ -1,24 +1,20 @@
|
|||||||
import 'package:core_localization/core_localization.dart';
|
import 'package:core_localization/core_localization.dart';
|
||||||
import 'package:design_system/design_system.dart';
|
import 'package:design_system/design_system.dart';
|
||||||
import 'package:flutter/material.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 'package:krow_domain/krow_domain.dart';
|
||||||
|
|
||||||
|
import 'client_home_sheets.dart';
|
||||||
|
|
||||||
/// A widget that allows clients to reorder recent shifts.
|
/// A widget that allows clients to reorder recent shifts.
|
||||||
class ReorderWidget extends StatelessWidget {
|
class ReorderWidget extends StatelessWidget {
|
||||||
/// Creates a [ReorderWidget].
|
/// Creates a [ReorderWidget].
|
||||||
const ReorderWidget({
|
const ReorderWidget({super.key, required this.orders, this.subtitle});
|
||||||
super.key,
|
|
||||||
required this.orders,
|
|
||||||
required this.onReorderPressed,
|
|
||||||
this.subtitle,
|
|
||||||
});
|
|
||||||
|
|
||||||
/// Recent completed orders for reorder.
|
/// Recent completed orders for reorder.
|
||||||
final List<ReorderItem> orders;
|
final List<ReorderItem> orders;
|
||||||
|
|
||||||
/// Callback when a reorder button is pressed.
|
|
||||||
final Function(Map<String, dynamic> shiftData) onReorderPressed;
|
|
||||||
|
|
||||||
/// Optional subtitle for the section.
|
/// Optional subtitle for the section.
|
||||||
final String? subtitle;
|
final String? subtitle;
|
||||||
|
|
||||||
@@ -154,16 +150,17 @@ class ReorderWidget extends StatelessWidget {
|
|||||||
leadingIcon: UiIcons.zap,
|
leadingIcon: UiIcons.zap,
|
||||||
iconSize: 12,
|
iconSize: 12,
|
||||||
fullWidth: true,
|
fullWidth: true,
|
||||||
onPressed: () => onReorderPressed(<String, dynamic>{
|
onPressed: () =>
|
||||||
'orderId': order.orderId,
|
_handleReorderPressed(context, <String, dynamic>{
|
||||||
'title': order.title,
|
'orderId': order.orderId,
|
||||||
'location': order.location,
|
'title': order.title,
|
||||||
'hourlyRate': order.hourlyRate,
|
'location': order.location,
|
||||||
'hours': order.hours,
|
'hourlyRate': order.hourlyRate,
|
||||||
'workers': order.workers,
|
'hours': order.hours,
|
||||||
'type': order.type,
|
'workers': order.workers,
|
||||||
'totalCost': order.totalCost,
|
'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 {
|
class _Badge extends StatelessWidget {
|
||||||
|
|||||||
Reference in New Issue
Block a user