list orders

This commit is contained in:
Phuoc Nguyen
2025-11-24 16:25:54 +07:00
parent 354df3ad01
commit 75d6507719
24 changed files with 1004 additions and 982 deletions

View File

@@ -0,0 +1,141 @@
/// Status Color Enum
///
/// Defines status types with their associated color values.
/// Used for status badges, alerts, and other UI elements that need
/// consistent color coding across the app.
library;
import 'package:flutter/material.dart';
/// Status Color Enum
///
/// Each status type has an associated color value.
enum StatusColor {
/// Warning status - Yellow/Orange
/// Used for cautionary states, pending actions, or items requiring attention
warning(Color(0xFFFFC107)),
/// Info status - Primary Blue
/// Used for informational states, neutral notifications, or general information
info(Color(0xFF005B9A)),
/// Danger status - Red
/// Used for error states, critical alerts, or destructive actions
danger(Color(0xFFDC3545)),
/// Success status - Green
/// Used for successful operations, completed states, or positive confirmations
success(Color(0xFF28A745)),
/// Secondary status - Light Grey
/// Used for secondary information, disabled states, or less important elements
secondary(Color(0xFFE5E7EB));
/// Constructor
const StatusColor(this.color);
/// The color value associated with this status
final Color color;
/// Get a lighter version of the color (with opacity)
/// Useful for backgrounds and subtle highlights
Color get light => color.withValues(alpha: 0.1);
/// Get a slightly darker version for borders
/// Useful for card borders and dividers
Color get border => color.withValues(alpha: 0.3);
/// Get the color with custom opacity
Color withOpacity(double opacity) => color.withValues(alpha: opacity);
/// Convert from string name (case-insensitive)
///
/// Example:
/// ```dart
/// final status = StatusColor.fromString('warning');
/// // Returns StatusColor.warning
/// ```
static StatusColor? fromString(String name) {
try {
return StatusColor.values.firstWhere(
(e) => e.name.toLowerCase() == name.toLowerCase(),
);
} catch (e) {
return null;
}
}
/// Get status color from order status string
///
/// Maps common order status strings to appropriate colors.
/// Returns null if no mapping exists.
///
/// Example:
/// ```dart
/// final color = StatusColor.fromOrderStatus('Processing');
/// // Returns StatusColor.warning
/// ```
static StatusColor? fromOrderStatus(String status) {
final statusLower = status.toLowerCase();
// Success states
if (statusLower.contains('completed') ||
statusLower.contains('delivered') ||
statusLower.contains('paid') ||
statusLower.contains('approved')) {
return StatusColor.success;
}
// Warning/Pending states
if (statusLower.contains('pending') ||
statusLower.contains('processing') ||
statusLower.contains('shipping') ||
statusLower.contains('reviewing')) {
return StatusColor.warning;
}
// Danger/Error states
if (statusLower.contains('cancelled') ||
statusLower.contains('rejected') ||
statusLower.contains('failed') ||
statusLower.contains('expired')) {
return StatusColor.danger;
}
// Info states
if (statusLower.contains('draft') ||
statusLower.contains('sent') ||
statusLower.contains('viewed')) {
return StatusColor.info;
}
return null;
}
/// Get status color from payment status string
///
/// Maps common payment status strings to appropriate colors.
/// Returns null if no mapping exists.
static StatusColor? fromPaymentStatus(String status) {
final statusLower = status.toLowerCase();
// Success states
if (statusLower.contains('completed') || statusLower.contains('paid')) {
return StatusColor.success;
}
// Warning/Pending states
if (statusLower.contains('pending') || statusLower.contains('processing')) {
return StatusColor.warning;
}
// Danger/Error states
if (statusLower.contains('failed') ||
statusLower.contains('rejected') ||
statusLower.contains('refunded')) {
return StatusColor.danger;
}
return StatusColor.info;
}
}