I have an old side project that requires to be modified once in a while to match different customers needs. That said, It's not mandatory to me to update to latest version of frameworks since everything works just fine.
However in my last modification, when building the app flutter complains about my ScaffoldState.showSnackBar
since it doesn't exist anymore. Doing some research I found that in order to achieve this now one have to use the ScaffoldMessenger
class. Though, when implementing it, the class can't be found. So, now I can't use any of the methods and the app is broken. Again, I won't update to latest version now since changes are minors to the app. And, a couple months ago, it still worked fine.
Here is how I usually show my snackbar:
_loadSuccessSnackBar() {
_scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Se han subido con exito los registros",
style: TextStyle(
color: Color.fromARGB(255, 186, 18, 57),
fontSize: 15,
),
),
SizedBox(width: 5),
Icon(
Icons.download_done_outlined,
color: Colors.green,
),
],
),
),
);
}
where _scaffoldKey, is a Globalkey instance of type ScaffoldState:
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
Is there any workaround or solution to keep using this approach or update to newer versions that don't break the entire app? (I'm using flutter v2.7.0).
Just a note: debug building works just fine...
Thanks in advance for any help!