Skip to content

Commit

Permalink
feat(packet): Parse packet status: all taken away
Browse files Browse the repository at this point in the history
  • Loading branch information
realth000 committed Feb 2, 2024
1 parent 9fc58d4 commit f65478f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Added

- 新增提示帖子内的红包已经领完了。
- 缓存首页轮播图。

### Fixed
Expand Down
3 changes: 3 additions & 0 deletions lib/features/packet/cubit/packet_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class PacketCubit extends Cubit<PacketState> {
if (result != null &&
(result.contains('已经领取过') || result.contains('领取成功'))) {
emit(state.copyWith(status: PacketStatus.success, reason: result));
} else if (result != null &&
result.contains('err_packet_has_gone_away')) {
emit(state.copyWith(status: PacketStatus.takenAway));
} else {
emit(state.copyWith(status: PacketStatus.failed, reason: result));
}
Expand Down
3 changes: 3 additions & 0 deletions lib/features/packet/cubit/packet_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ enum PacketStatus {

/// Load failed.
failed,

/// All packets were taken away.
takenAway,
}

/// 红包
Expand Down
3 changes: 2 additions & 1 deletion lib/i18n/strings.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
"packetCard": {
"title": "You found a packet!",
"open": "Open It",
"failedToOpen": "Failed to open"
"failedToOpen": "Failed to open",
"allTakenAway": "All packets were taken away"
}
}
3 changes: 2 additions & 1 deletion lib/i18n/strings_zh-CN.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
"packetCard": {
"title": "你找到了一个红包!",
"open": "打开",
"failedToOpen": "打开失败"
"failedToOpen": "打开失败",
"allTakenAway": "红包都领完了"
}
}
3 changes: 2 additions & 1 deletion lib/i18n/strings_zh-TW.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
"packetCard": {
"title": "你找到一個紅包了!",
"open": "開啟",
"failedToOpen": "打開失敗"
"failedToOpen": "打開失敗",
"allTakenAway": "红包都領完了"
}
}
15 changes: 12 additions & 3 deletions lib/widgets/card/packet_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class PacketCard extends StatelessWidget {
} else if (state.status == PacketStatus.success) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(state.reason!)));
} else if (state.status == PacketStatus.takenAway) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(context.t.packetCard.allTakenAway)),
);
}
},
child: BlocBuilder<PacketCubit, PacketState>(
Expand All @@ -49,20 +53,25 @@ class PacketCard extends StatelessWidget {
const Center(child: sizedCircularProgressIndicator),
PacketStatus.initial ||
PacketStatus.success ||
PacketStatus.failed =>
PacketStatus.failed ||
PacketStatus.takenAway =>
const Icon(FontAwesomeIcons.solidEnvelopeOpen),
};

final label = switch (state.status) {
PacketStatus.loading => const Text(''),
PacketStatus.initial ||
PacketStatus.success ||
PacketStatus.failed =>
PacketStatus.failed ||
PacketStatus.takenAway =>
Text(context.t.packetCard.open),
};

final callback = switch (state.status) {
PacketStatus.loading || PacketStatus.success => null,
PacketStatus.loading ||
PacketStatus.success ||
PacketStatus.takenAway =>
null,
PacketStatus.initial || PacketStatus.failed => () async =>
context.read<PacketCubit>().receivePacket(packetUrl),
};
Expand Down

0 comments on commit f65478f

Please sign in to comment.