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

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.

Related

Want to build a guided tour for the first launch

at the moment I am building an app with flutter.
Now that I have some function done I want to build a guided tour for new user, which explains some of the basic of the app. I want this to pop up if a new user starts the app for the first time and it should also be accessible later.
Do you have some suggestions what widget can be used for that? I thought abount something like 5 pages which you can flip trough - with pictures and text.
Hope you understand what I am looking for.
An example would be great.
Thanks in advance
Patrick
maybe You can use showcaseview package.
https://pub.dev/packages/showcaseview
You're talking about an onboarding screen, there is a package you can use for that.
To "persist" the state of onbarding completion, you can use shared_preferences to create a value where you will check on app startup
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setBool('onboarding',true); // call this when onbarding is finished
var isOnbCompleted = prefs.getBool('onboarding'); // to get the value
if (isOnbCompleted)
...

what can prevent setstate from working correctly in 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

Get the previous route name in Flutter

I understand that Flutter routes works like a stack, so I want to know the previous route name which I came from.
I'm using a preview page to show a picture, but this picture can come from the camera or the gallery, I'd like to show a dialog only if it came from gallery.
I read I have to use an observer, but I think there is an easy way to do that.
Thanks in advance.
You can use getx pack to get previous Route
Get.previousRoute;
get current Route
Get.currentRoute;
Well, upon further investigation, there is no way to know the previous page.
I fixed this sending an argument previousPage with the route name value.
You can also use a NavigatorObserver.

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.

Show Loading Screen on Home Screen Widget Android

I understand the "android:initialLayout" element within the xml folder for defining the default layout of an Android homescreen widget. I want to be able to display a "loading your information" on my widget while I am waiting for data...how do I do this. I have tried to display an error message on my widget if there is no connectivity, but it doesn't get past the "android:initialLayout" , so showing code I believe is irrelevant. Correct me if I am wrong please...don't bash me. Any help greatly appreciated!
Yes, the initialLayout is so that your widget displays something before Android has had a chance to call your widget-updating code. This is a great place to put a "Loading..." message.
Once your onUpdate method is called in your widget, that is your chance to get your data. If you have a connectivity problem at that point, you can display an error message at that point. Otherwise, if you successfully get your data, then you can draw you widget with the data.
I'm not sure if I've answered your question, so apologies if I have not. Please clarify a bit more if I have not. The main questions I have are:
Is Android calling your onUpdate function? Log statements can be really helpful for this.
Are you trying to load your data in the background, such as a separate Service, and then reading the results in the widget? Or are you loading the data inside the widget?