merge branches
This commit is contained in:
@@ -143,16 +143,17 @@ class YourTendersRouteData extends GoRouteData with _$YourTendersRouteData {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return const YourTendersScreen();
|
||||
return YourTendersScreen();
|
||||
}
|
||||
}
|
||||
|
||||
@TypedGoRoute<TenderDetailRouteData>(path: '/tender-detail')
|
||||
class TenderDetailRouteData extends GoRouteData with _$TenderDetailRouteData {
|
||||
const TenderDetailRouteData();
|
||||
final String tenderId;
|
||||
const TenderDetailRouteData({required this.tenderId});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, GoRouterState state) {
|
||||
return const TenderDetailScreen();
|
||||
return TenderDetailScreen(tenderId: tenderId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,10 +175,15 @@ RouteBase get $tenderDetailRouteData => GoRouteData.$route(
|
||||
|
||||
mixin _$TenderDetailRouteData on GoRouteData {
|
||||
static TenderDetailRouteData _fromState(GoRouterState state) =>
|
||||
const TenderDetailRouteData();
|
||||
TenderDetailRouteData(tenderId: state.uri.queryParameters['tender-id']!);
|
||||
|
||||
TenderDetailRouteData get _self => this as TenderDetailRouteData;
|
||||
|
||||
@override
|
||||
String get location => GoRouteData.$location('/tender-detail');
|
||||
String get location => GoRouteData.$location(
|
||||
'/tender-detail',
|
||||
queryParams: {'tender-id': _self.tenderId},
|
||||
);
|
||||
|
||||
@override
|
||||
void go(BuildContext context) => context.go(location);
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class DateUtils {
|
||||
/// Converts Unix timestamp (seconds since epoch) to a formatted date string
|
||||
static String unixToDate(int? unixTimestamp, {String format = 'yyyy-MM-dd'}) {
|
||||
if (unixTimestamp == null) return '';
|
||||
|
||||
// Convert seconds to milliseconds if needed
|
||||
int timestampInMs =
|
||||
unixTimestamp > 1000000000000 ? unixTimestamp : unixTimestamp * 1000;
|
||||
|
||||
final DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
|
||||
timestampInMs,
|
||||
);
|
||||
return DateFormat(format).format(dateTime);
|
||||
}
|
||||
|
||||
/// Converts Unix timestamp to a readable date string
|
||||
static String unixToReadableDate(int? unixTimestamp) {
|
||||
if (unixTimestamp == null) return '';
|
||||
|
||||
int timestampInMs =
|
||||
unixTimestamp > 1000000000000 ? unixTimestamp : unixTimestamp * 1000;
|
||||
|
||||
final DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
|
||||
timestampInMs,
|
||||
);
|
||||
final DateTime now = DateTime.now();
|
||||
final Duration difference = now.difference(dateTime);
|
||||
|
||||
if (difference.inDays == 0) {
|
||||
return 'Today';
|
||||
} else if (difference.inDays == 1) {
|
||||
return 'Yesterday';
|
||||
} else if (difference.inDays < 7) {
|
||||
return '${difference.inDays} days ago';
|
||||
} else {
|
||||
return DateFormat('MMM dd, yyyy').format(dateTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts Unix timestamp to a short date format
|
||||
static String unixToShortDate(int? unixTimestamp) {
|
||||
if (unixTimestamp == null) return '';
|
||||
|
||||
int timestampInMs =
|
||||
unixTimestamp > 1000000000000 ? unixTimestamp : unixTimestamp * 1000;
|
||||
|
||||
final DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
|
||||
timestampInMs,
|
||||
);
|
||||
return DateFormat('MMM dd').format(dateTime);
|
||||
}
|
||||
|
||||
/// Converts Unix timestamp to a full date and time format
|
||||
static String unixToDateTime(int? unixTimestamp) {
|
||||
if (unixTimestamp == null) return '';
|
||||
|
||||
int timestampInMs =
|
||||
unixTimestamp > 1000000000000 ? unixTimestamp : unixTimestamp * 1000;
|
||||
|
||||
final DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
|
||||
timestampInMs,
|
||||
);
|
||||
return DateFormat('MMM dd, yyyy HH:mm').format(dateTime);
|
||||
}
|
||||
|
||||
/// Checks if a Unix timestamp is in the past
|
||||
static bool isPast(int? unixTimestamp) {
|
||||
if (unixTimestamp == null) return false;
|
||||
|
||||
int timestampInMs =
|
||||
unixTimestamp > 1000000000000 ? unixTimestamp : unixTimestamp * 1000;
|
||||
|
||||
final DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
|
||||
timestampInMs,
|
||||
);
|
||||
return dateTime.isBefore(DateTime.now());
|
||||
}
|
||||
|
||||
/// Gets the number of days remaining until a Unix timestamp
|
||||
static int daysRemaining(int? unixTimestamp) {
|
||||
if (unixTimestamp == null) return 0;
|
||||
|
||||
int timestampInMs =
|
||||
unixTimestamp > 1000000000000 ? unixTimestamp : unixTimestamp * 1000;
|
||||
|
||||
final DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
|
||||
timestampInMs,
|
||||
);
|
||||
final DateTime now = DateTime.now();
|
||||
final Duration difference = dateTime.difference(now);
|
||||
|
||||
return difference.inDays;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user