what can prevent setstate from working correctly in flutter? - flutter

i am new to flutter in one of my project pages set state doesn't work at all no matter what I do I tried every almost everything every time doesn't work so what think can stop set state from working?
note: I am using provider and shared preference

setState(){} only works in StatefulWidget class, I think you are using StatelessWidget. If you want to use it change your class to StatefulWidget.

actually, nothing can stop it from working, and because you are new I am inviting you to accept that there is not something wrong with flutter but with your skill in flutter.
if you provide some code we might be able to help

Related

Build connection between flame and flutter

I have a flutter widget ProgressBar, which needs to be notified when a change happens to a value in Flame,
I followed a tutorial which is using overlays.notifyListeners(); to update the StatelessWidget progressBar, but after I updated to the newest Flame version (v1.6.0), this method can not be used anymore, what is the correct way of doing this now?
There are a few different ways to do this, either you can use state management libraries like flame_riverpod or flame_bloc to achieve this, or you can wrap your value in a ChangeNotifier/ValueNotifier and update the state once the value updates.

Flutter - GetX - Changing theme needs hot reload when using Get.theme

When changing theme to Darkmode with GetX via Get.changeThemeMode(ThemeMode.dark), most widgets change accordingly. But those widgets using some parameter with Get.theme need a hot reload for the effect to take place.
As a comment suggested here, that is because Get.theme is immutable. Using the extension method context.theme does resolve the issue, however, I do not always have access to a context. Get.context.theme does not resolve the issue. What should I do in this case? Since passing the context to wherever needed kinda defeats the purpose of using GetX.
I am not sure what 'some parameters' you are talking about since you didn't include any code, but you can use the Get.changeTheme() method which takes a ThemeData object and changes the theme accordingly without hot restart.

Flutter - Listening to one value through whole app

Iam using EventChannel to handle events from hardware barcode scanner. EventChannel is initialized in initState, in main class - it works through whole app. While change is detected, it inserts value into global variable (ValueNotifier - i dont know, if it is right) and then I need to work with that value in multiple widgets. I need some sort of widget, which will tell me, that value updated and it will trigger onEvent function - something like RawKeyboardListener. I tried using listeners, but when i do pushNamed, the listener is still listening and it runs code from previous pages, while scanning.
Is there any widget, that would be suitable for me? (cant use ValueListenableBuilder, because it has no "onEvent" function) Or is there any way, to remove and add listeners while moving between pages, or while modal bottom sheet is opened? (I need to access previous listeners, after Navigator.pop)
I solved my problem by using listeners and ModalRoute.of(context).isCurrent.

Best practice on how to display a widget which content is depending on an async call?

Basically topic.
I am trying to display an image slider with content that I pull from a db. I'm calling for this data in the initstate method. I have managed to do a couple of workarounds, but none of them seem clean enough. I don't necessarily need to call it from initstate, but I need that it shows up as I open the screen.
Thanks in advance.
If it's an image, you can use a package called blurhash, Google it for more information regarding that.

One page, multiple contexts ? Is that possible?

Here is my problem: I have an app that has 2 list view.builders. You can imagine the scenario.
within the Stateful widget, we have:
Widget build(ct)
{
and this returns a column widget that has TWO list views.
The problem I have is that one list view changes (or should change) the items in another list view.
So what are my options? To create two Widget build(ct1) and Widget build(ct2)??
Do we do that? How can I communicate changes to ct1?
Oh my goodness, I've tried a lot, even setState etc... nothing works.. Perhaps could someone tell me how I can invoke the page to be refreshed?? That would work.
I keep on finding the answers myself - but for anyone who has this issue, Flutter apparently has evolved... if you are using the latest version, I really believe that SetState() function should work for you.. you just need to use it in the right place.