load offer before view/dialog opens so the accept button isn't disabled for a second or two without any info as to why displayed
What changed, and why it matters
This commit is a user-experience refactor, not a security fix. It moves the loading of a ShopInBit offer from inside the offer screen to the moment the user taps the 'Review offer' button, so the screen opens with data already loaded. The 'Accept offer' button no longer needs to be temporarily disabled while waiting. There is no indication this change addresses a security vulnerability.
No security action required. Treat as a normal UX/code-quality change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors ShopInBitOfferView from a ConsumerStatefulWidget to a ConsumerWidget, removing the initState call to refreshOne() and the local _loading state. Instead, ShopInBitTicketDetail now calls refreshOne() inside showLoading() before navigating to the offer view. The offer view now simply watches the reactive ticket provider and displays ‘N/A’ or cached values if data is absent. No security-sensitive logic (authentication, authorization, cryptography, input validation, network trust, etc.) is changed.
Changed components
lib/pages/shopinbit/shopinbit_offer_view.dartlib/pages/shopinbit/shopinbit_ticket_detail.dartInspect captured patch +32 / −57
diff --git a/lib/pages/shopinbit/shopinbit_offer_view.dart b/lib/pages/shopinbit/shopinbit_offer_view.dart
index 4733fe7..b170407 100644
--- a/lib/pages/shopinbit/shopinbit_offer_view.dart
+++ b/lib/pages/shopinbit/shopinbit_offer_view.dart
@@ -3,7 +3,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../providers/global/shopin_bit_service_provider.dart';
import '../../themes/stack_colors.dart';
-import '../../utilities/logger.dart';
import '../../utilities/show_loading.dart';
import '../../utilities/text_styles.dart';
import '../../utilities/util.dart';
@@ -18,7 +17,7 @@ import '../../widgets/rounded_white_container.dart';
import '../../widgets/stack_dialog.dart';
import 'shopinbit_shipping_view.dart';
-class ShopInBitOfferView extends ConsumerStatefulWidget {
+class ShopInBitOfferView extends ConsumerWidget {
const ShopInBitOfferView({super.key, required this.apiTicketId});
static const String routeName = "/shopInBitOffer";
@@ -26,45 +25,9 @@ class ShopInBitOfferView extends ConsumerStatefulWidget {
final int apiTicketId;
@override
- ConsumerState<ShopInBitOfferView> createState() => _ShopInBitOfferViewState();
-}
-
-class _ShopInBitOfferViewState extends ConsumerState<ShopInBitOfferView> {
- bool _loading = false;
-
- @override
- void initState() {
- super.initState();
- if (widget.apiTicketId != 0) {
- _loadOffer();
- }
- }
-
- Future<void> _loadOffer() async {
- setState(() => _loading = true);
- try {
- // Refresh pulls /full (offer product + price) into the ticket row, which
- // we then read reactively from the DB stream.
- await ref.read(pShopinBitService).refreshOne(widget.apiTicketId);
- } catch (e, s) {
- Logging.instance.w(
- "Failed to refresh ShopInBit offer ${widget.apiTicketId}, "
- "using cached data",
- error: e,
- stackTrace: s,
- );
- } finally {
- if (mounted) setState(() => _loading = false);
- }
- }
-
- @override
- Widget build(BuildContext context) {
+ Widget build(BuildContext context, WidgetRef ref) {
final isDesktop = Util.isDesktop;
- final ticket = ref
- .watch(pShopInBitTicket(widget.apiTicketId))
- .asData
- ?.value;
+ final ticket = ref.watch(pShopInBitTicket(apiTicketId)).asData?.value;
final content = Column(
mainAxisSize: .min,
@@ -96,7 +59,7 @@ class _ShopInBitOfferViewState extends ConsumerState<ShopInBitOfferView> {
),
const SizedBox(height: 4),
Text(
- ticket?.offerProductName ?? (_loading ? "Loading..." : "N/A"),
+ ticket?.offerProductName ?? "N/A",
style: isDesktop
? STextStyles.desktopTextSmall(context)
: STextStyles.titleBold12(context),
@@ -117,9 +80,7 @@ class _ShopInBitOfferViewState extends ConsumerState<ShopInBitOfferView> {
),
const SizedBox(height: 4),
Text(
- _loading && ticket?.offerPrice == null
- ? "Loading..."
- : "${ticket?.offerPrice ?? '0'} EUR",
+ "${ticket?.offerPrice ?? '0'} EUR",
style: isDesktop
? STextStyles.desktopTextSmall(context)
: STextStyles.titleBold12(context),
@@ -146,7 +107,6 @@ class _ShopInBitOfferViewState extends ConsumerState<ShopInBitOfferView> {
PrimaryButton(
label: "Accept offer",
buttonHeight: Util.isDesktop ? ButtonHeight.l : null,
- enabled: !_loading,
onPressed: () async {
final deliveryCountry = ticket?.deliveryCountry ?? "";
diff --git a/lib/pages/shopinbit/shopinbit_ticket_detail.dart b/lib/pages/shopinbit/shopinbit_ticket_detail.dart
index a979ed8..9f5126a 100644
--- a/lib/pages/shopinbit/shopinbit_ticket_detail.dart
+++ b/lib/pages/shopinbit/shopinbit_ticket_detail.dart
@@ -269,6 +269,31 @@ class _ShopInBitTicketDetailState extends ConsumerState<ShopInBitTicketDetail>
),
);
+ Future<void> _pushOfferView() async {
+ if (_id != 0) {
+ await showLoading(
+ whileFutureAlt: () =>
+ ref.read(pShopinBitService).refreshOne(widget.apiTicketId),
+ context: context,
+ message: "Checking offer...",
+ rootNavigator: Util.isDesktop,
+ delay: const Duration(seconds: 1),
+ onException: (e) {
+ Logging.instance.w(
+ "Failed to refresh ShopInBit offer ${widget.apiTicketId}, "
+ "using cached data",
+ error: e,
+ );
+ },
+ );
+ }
+ if (context.mounted) {
+ await Navigator.of(
+ context,
+ ).pushNamed(ShopInBitOfferView.routeName, arguments: _id);
+ }
+ }
+
final offerBanner = status == ShopInBitOrderStatus.offerAvailable
? Padding(
padding: .only(bottom: isDesktop ? 12 : 8),
@@ -287,12 +312,7 @@ class _ShopInBitTicketDetailState extends ConsumerState<ShopInBitTicketDetail>
label: "Review offer",
width: 220,
buttonHeight: ButtonHeight.l,
- onPressed: () {
- Navigator.of(context).pushNamed(
- ShopInBitOfferView.routeName,
- arguments: _id,
- );
- },
+ onPressed: _pushOfferView,
),
],
),
@@ -319,12 +339,7 @@ class _ShopInBitTicketDetailState extends ConsumerState<ShopInBitTicketDetail>
PrimaryButton(
label: "Review offer",
buttonHeight: Util.isDesktop ? ButtonHeight.l : null,
- onPressed: () {
- Navigator.of(context).pushNamed(
- ShopInBitOfferView.routeName,
- arguments: _id,
- );
- },
+ onPressed: _pushOfferView,
),
],
),
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.