Skip to content

Commit

Permalink
增加了快递追踪
Browse files Browse the repository at this point in the history
  • Loading branch information
mazj committed Jan 26, 2024
1 parent 7d3c658 commit 5b0c265
Show file tree
Hide file tree
Showing 8 changed files with 770 additions and 171 deletions.
39 changes: 38 additions & 1 deletion lib/api/dash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,62 @@ class DashInfo with _$DashInfo {
@Default(DashTemp()) DashTemp tempFutureInfo,
@Default(DashFit()) DashFit fitnessInfo,
@Default("") String debugInfo,
@Default("") String lastError}) = _DashInfo;
@Default("") String lastError,
@Default([]) List<DashExpress> express}) = _DashInfo;

factory DashInfo.fromJson(Map<String, dynamic> json) =>
_$DashInfoFromJson(json);
}

@freezed
class DashExpress with _$DashExpress {
factory DashExpress({
@Default("") String id,
@Default("") String name,
@Default(0) int status,
@Default("") @JsonKey(name: "last_update") String lastUpdate,
@Default("") String info,
@Default([]) List<DashExpressExtra> extra,
}) = _DashExpress;

factory DashExpress.fromJson(Map<String, dynamic> json) =>
_$DashExpressFromJson(json);
}

@freezed
class DashExpressExtra with _$DashExpressExtra {
const factory DashExpressExtra(
{@Default("") String time, @Default("") status}) = _DashExpressExtra;
factory DashExpressExtra.fromJson(Map<String, dynamic> json) =>
_$DashExpressExtraFromJson(json);
}

@riverpod
Future<List<DashExpress>> getExpress(GetExpressRef ref) async {
final (res, ok) = await requestFromList("/cyber/express/recent",
(p) => p.map((e) => DashExpress.fromJson(e)).toList(growable: false));
if (ok.isNotEmpty) {
debugPrint(ok);
}
return res ?? [];
}

@riverpod
Future<DashInfo> getDash(GetDashRef ref) async {
if (ref.read(configsProvider).value?.demoMode ?? false) {
return fakeDashInfo();
}
debugPrint("req for dash");
try {
final express = await ref.watch(getExpressProvider.future);
final (res, d) =
await requestFromRaw("/cyber/client/ios-widget", DashInfo.fromJson);
return res?.copyWith(
express: express,
debugInfo:
"[normal] ver: $version, req: ${Configs.data.copyWith(password: "***")}") ??
DashInfo(
express: express,
debugInfo:
"[empty] ver: $version, req: ${Configs.data.copyWith(password: "***")}, origin or err $d",
lastError: d);
Expand Down

0 comments on commit 5b0c265

Please sign in to comment.