Skip to content

Commit 28cc575

Browse files
committed
refactor(shopinbit): resume car research with inline row spinner
1 parent 2d5c5b4 commit 28cc575

1 file changed

Lines changed: 39 additions & 20 deletions

File tree

lib/pages/shopinbit/shopinbit_tickets_view.dart

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import "../../providers/global/shopin_bit_service_provider.dart";
1313
import "../../services/shopinbit/src/models/car_research.dart";
1414
import "../../themes/stack_colors.dart";
1515
import "../../utilities/assets.dart";
16-
import "../../utilities/show_loading.dart";
1716
import "../../utilities/text_styles.dart";
1817
import "../../utilities/util.dart";
1918
import "../../widgets/background.dart";
2019
import "../../widgets/conditional_parent.dart";
2120
import "../../widgets/custom_buttons/app_bar_icon_button.dart";
2221
import "../../widgets/desktop/desktop_dialog_close_button.dart";
2322
import "../../widgets/dialogs/s_dialog.dart";
23+
import "../../widgets/loading_indicator.dart";
2424
import "../../widgets/refresh_control.dart";
2525
import "../../widgets/rounded_container.dart";
2626
import "shopinbit_car_fee_view.dart";
@@ -42,6 +42,7 @@ class _ShopInBitTicketsViewState extends ConsumerState<ShopInBitTicketsView> {
4242
ShopInBitTicket? _pendingTicket;
4343
StreamSubscription<List<ShopInBitTicket>>? _ticketsSub;
4444
bool _refreshing = false;
45+
bool _resuming = false;
4546

4647
@override
4748
void initState() {
@@ -77,23 +78,27 @@ class _ShopInBitTicketsViewState extends ConsumerState<ShopInBitTicketsView> {
7778
}
7879

7980
Future<void> _resumeFlow(ShopInBitTicket pending) async {
81+
if (_resuming) return;
8082
final model = ShopInBitOrderModel.fromDriftRow(pending);
8183

8284
// Recover the live invoice from the server first so resume works even if
8385
// local invoice state was lost.
84-
final response = await showLoading(
85-
context: context,
86-
rootNavigator: true,
87-
message: "Checking your car research payment",
88-
whileFuture: ref
89-
.read(pShopinBitService)
90-
.client
91-
.getCurrentCarResearchInvoices(),
92-
delay: const Duration(seconds: 1),
93-
);
86+
setState(() => _resuming = true);
87+
List<CarResearchCurrentInvoice>? current;
88+
try {
89+
current = (await ref
90+
.read(pShopinBitService)
91+
.client
92+
.getCurrentCarResearchInvoices())
93+
.value;
94+
} catch (_) {
95+
// Fall back to locally stored invoice state below.
96+
} finally {
97+
if (mounted) setState(() => _resuming = false);
98+
}
9499
if (!mounted) return;
95100

96-
final invoice = _liveInvoiceFrom(response?.value, pending);
101+
final invoice = _liveInvoiceFrom(current, pending);
97102

98103
if (invoice != null) {
99104
await Navigator.of(context).pushNamed(
@@ -186,14 +191,17 @@ class _ShopInBitTicketsViewState extends ConsumerState<ShopInBitTicketsView> {
186191
children.add(
187192
RoundedContainer(
188193
color: Theme.of(context).extension<StackColors>()!.popupBG,
189-
onPressed: () => unawaited(_resumeFlow(pending)),
194+
onPressed: _resuming ? null : () => unawaited(_resumeFlow(pending)),
190195
child: _RequestRow(
191196
title: "Car Research (In Progress)",
192-
subtitle: "Tap to continue your car research payment",
197+
subtitle: _resuming
198+
? "Checking your car research payment..."
199+
: "Tap to continue your car research payment",
193200
badgeText: "Resume",
194201
badgeColor: Theme.of(
195202
context,
196203
).extension<StackColors>()!.accentColorYellow,
204+
loading: _resuming,
197205
),
198206
),
199207
);
@@ -328,12 +336,14 @@ class _RequestRow extends StatelessWidget {
328336
required this.subtitle,
329337
required this.badgeText,
330338
required this.badgeColor,
339+
this.loading = false,
331340
});
332341

333342
final String title;
334343
final String subtitle;
335344
final String badgeText;
336345
final Color badgeColor;
346+
final bool loading;
337347

338348
@override
339349
Widget build(BuildContext context) {
@@ -374,12 +384,21 @@ class _RequestRow extends StatelessWidget {
374384
),
375385
),
376386
SizedBox(width: isDesktop ? 16 : 8),
377-
SvgPicture.asset(
378-
Assets.svg.chevronRight,
379-
width: 20,
380-
height: 20,
381-
colorFilter: ColorFilter.mode(stackColors.textSubtitle1, .srcIn),
382-
),
387+
loading
388+
? const SizedBox(
389+
width: 20,
390+
height: 20,
391+
child: LoadingIndicator(),
392+
)
393+
: SvgPicture.asset(
394+
Assets.svg.chevronRight,
395+
width: 20,
396+
height: 20,
397+
colorFilter: ColorFilter.mode(
398+
stackColors.textSubtitle1,
399+
.srcIn,
400+
),
401+
),
383402
],
384403
);
385404
}

0 commit comments

Comments
 (0)