From 1ba61d8a994181f96acf100f0579354815619d77 Mon Sep 17 00:00:00 2001 From: Restioson Date: Mon, 4 Sep 2023 18:28:47 +0200 Subject: [PATCH] refactor: pass ScaffoldMessengerState to showSnackBar so it may be used more widely --- mobile/lib/common/snack_bar.dart | 4 ++-- mobile/lib/features/wallet/share_invoice_screen.dart | 5 ++--- mobile/lib/main.dart | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mobile/lib/common/snack_bar.dart b/mobile/lib/common/snack_bar.dart index da11d7dfe..457424c77 100644 --- a/mobile/lib/common/snack_bar.dart +++ b/mobile/lib/common/snack_bar.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; /// Show a snackbar with the given message /// /// Extracted as a separate function to ensure consistent style of error messages -void showSnackBar(BuildContext context, String message) { +void showSnackBar(ScaffoldMessengerState messenger, String message) { final snackBar = SnackBar(content: Text(message)); - ScaffoldMessenger.of(context).showSnackBar(snackBar); + messenger.showSnackBar(snackBar); } diff --git a/mobile/lib/features/wallet/share_invoice_screen.dart b/mobile/lib/features/wallet/share_invoice_screen.dart index 10a9922fb..3d3d8852e 100644 --- a/mobile/lib/features/wallet/share_invoice_screen.dart +++ b/mobile/lib/features/wallet/share_invoice_screen.dart @@ -136,7 +136,7 @@ class _ShareInvoiceScreenState extends State { router.pop(); router.pop(); } catch (error) { - showSnackBar(context, error.toString()); + showSnackBar(ScaffoldMessenger.of(context), error.toString()); } finally { setState(() { _isPayInvoiceButtonDisabled = false; @@ -158,8 +158,7 @@ class _ShareInvoiceScreenState extends State { child: OutlinedButton( onPressed: () { Clipboard.setData(ClipboardData(text: widget.invoice.rawInvoice)).then((_) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Invoice copied to clipboard'))); + showSnackBar(ScaffoldMessenger.of(context), "Invoice copied to clipboard"); }); }, style: ElevatedButton.styleFrom( diff --git a/mobile/lib/main.dart b/mobile/lib/main.dart index 276e3531e..e33751f17 100644 --- a/mobile/lib/main.dart +++ b/mobile/lib/main.dart @@ -17,6 +17,7 @@ import 'package:get_10101/common/channel_status_notifier.dart'; import 'package:get_10101/common/color.dart'; import 'package:get_10101/common/domain/service_status.dart'; import 'package:get_10101/common/service_status_notifier.dart'; +import 'package:get_10101/common/snack_bar.dart'; import 'package:get_10101/features/stable/stable_screen.dart'; import 'package:get_10101/features/trade/application/candlestick_service.dart'; import 'package:get_10101/features/trade/application/order_service.dart'; @@ -265,7 +266,7 @@ class _TenTenOneAppState extends State { } } catch (e) { FLog.error(text: "Error getting coordinator version: ${e.toString()}"); - messenger.showSnackBar(const SnackBar(content: Text("Coordinator offline"))); + showSnackBar(messenger, "Coordinator offline"); } }); }