Skip to content

Commit

Permalink
refactor: pass ScaffoldMessengerState to showSnackBar so it may be us…
Browse files Browse the repository at this point in the history
…ed more widely
  • Loading branch information
Restioson committed Sep 4, 2023
1 parent 6a9bb51 commit 1ba61d8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions mobile/lib/common/snack_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 2 additions & 3 deletions mobile/lib/features/wallet/share_invoice_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class _ShareInvoiceScreenState extends State<ShareInvoiceScreen> {
router.pop();
router.pop();
} catch (error) {
showSnackBar(context, error.toString());
showSnackBar(ScaffoldMessenger.of(context), error.toString());
} finally {
setState(() {
_isPayInvoiceButtonDisabled = false;
Expand All @@ -158,8 +158,7 @@ class _ShareInvoiceScreenState extends State<ShareInvoiceScreen> {
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(
Expand Down
3 changes: 2 additions & 1 deletion mobile/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -265,7 +266,7 @@ class _TenTenOneAppState extends State<TenTenOneApp> {
}
} catch (e) {
FLog.error(text: "Error getting coordinator version: ${e.toString()}");
messenger.showSnackBar(const SnackBar(content: Text("Coordinator offline")));
showSnackBar(messenger, "Coordinator offline");
}
});
}
Expand Down

0 comments on commit 1ba61d8

Please sign in to comment.