Reputation: 1
Why is showSnackBar giving the above Error. `
IconButton(
icon: const Icon(Icons.content_copy),
iconSize: 24,
onPressed: () {
Clipboard.setData(ClipboardData(text: transaction.transCode));
scaffoldKey.currentState?.showSnackBar(SnackBar(
backgroundColor: Theme.of(context).iconTheme.color,
content: Tooltip(
message: Utils.getString(context, 'transaction_detail__copy'),
child: Text(
Utils.getString(context, 'transaction_detail__copied_data'),
style: Theme.of(context)
.textTheme
.headline6!
.copyWith(color: PsColors.mainColor),
),
showDuration: const Duration(seconds: 5),
),
));
},
),
`
i have tried changing my Globalkey to Global i end up getting more errors. What to do?
Upvotes: 0
Views: 679
Reputation: 9206
this way of calling of trying to show a snackbar is deprecated, instead, you can use the ScaffoldMessenger
like this:
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
backgroundColor: Theme.of(context).iconTheme.color,
content: Tooltip(
message: Utils.getString(context, 'transaction_detail__copy'),
child: Text(
Utils.getString(context, 'transaction_detail__copied_data'),
style: Theme.of(context)
.textTheme
.headline6!
.copyWith(color: PsColors.mainColor),
),
showDuration: const Duration(seconds: 5),
),
));
Check this page
Upvotes: 1