Load list from api for dropdown only when tapped - flutter

I want a situation whereby when I tap a flutter dropdown, it pulls an updated list from api and render. I have tried using gestureDetector. So on tap it loads the list. But I don't know how to display the loaded list
In order words, how do I make flutter dopdownButtom item a future

Related

How to validate TextFormFields, that are at different pages inside a PageView

So lets say I have 3 Pages : [StartingPage, NamePage, AdressPage] inside a PageView.
Each of those children has a TextFormField inside it.
When I am at StartingPage I want to call .validate() on the keys of the TextFormFields on NamePage and AdressPage and I want the errorLabels to show, when the user navigates to the other pages. The problem is that currently, the validation only works for the TextFormFields that are on screen.
So basically there are two questions:
Is it possible to pre-build pages of a pageview? Otherwise when I call formFieldKey.currentState the state is null if I haven't navigated to the respective page.
Is there another way to validate offscreen TextFormField content and show the errorlabel, when they come into view?
Unfortunately Flutter Dosen't Support Multi-Page Forms So You Need To Implement Advanced State Management To Make This Happen.
I Used Riverpod To Create a 4 Page Form By Creating A Form Key For Every Page And Saving The State of the Forms, This Way Every Form Will keep Its State Until You Dispose Of it, Hope This Helped.

Flutter Dropdown Button not saving state during Screen Navigation

Hi I am running into an issue where I am unable to save the state of the DropdownButton (the text shown in the Dropdown Button itself, which is the value that I have selected). I am using GetX for state navigation.
Due to the way my code has been structured, when I navigate from one screen to a second one, and wish to navigate back, I am utilising Get.to(First() instead of Get.back().
Here is my logic:
I will save the value the user has selected from the DropdownButton into SharedPreferences. This value will also be immediately shown to the user on the button itself due to the nature of the button.
When user navigates away (e.g. he is now on the second screen), and visits first screen again, I will load the selected value from SharedPreferences and construct the DropdownButton item such that this value will be shown at the top.
The issue I am facing:
Retrieving data from SharedPreferences is asynchronous, so I don't know how to construct the FirstScreen again while I am waiting for data to be retrieved from SharedPreferences. Could anyone help me out? Thank you!
Use GetStorage() instead of shared-preference . No Async issue
dependencies:
get_storage: ^2.0.3
use GetStorage through an instance or use directly GetStorage().read('key')
final box = GetStorage();
To write information you must use write :
box.write('quote', 'GetX is the best');
To read values you use read:
print(box.read('quote'));
// out: GetX is the best

Searchable spinner in Flutter

I want to get effect similar as here:
https://github.com/michaelprimez/searchablespinner
Flutter includes a dropdown button, but can we add searching functionality to it? Where can I start?
You should create a StatefulWidget (button for example) which its root widget is a GestureDetector, then showDialog on button tap.
Dialog should contain a list of items as state and a ListView.builder() to build items. When you search you should render items with items.where() to filter items.

How to load data on a screen on the press of a button without routing and rebuilding whole screen

Pardon me if this is a naive question but I am trying to figure out a way in Flutter to load different data when the user clicks a button. The way I currently see is routing the user to a new screen everytime but I am sure there would be a better approach without loading the whole screen everytime
You should use a Stateful Widget
I would create a Future Builder / ListView Builder. Depending on how you want it to behave you could have the ListView items clear before regenerating the list of items to show.
Future Builder you could create a function to return certain widgets depending on the request you make with the function.

how to avoid rebuilding duplicate widgets when navigating back to previous page in flutter?

When the user logs in, they get pushed to the homepage and their data is retrieved from database on initstate and then the widgets are built. However, i noticed for the widgets that are built without a streambuilder, where i manually retrieve data once, are duplicated if i navigate to another page and then come back. When I say duplicated I mean the exact same data is redundantly copied again using the same widget, so like a users' profile pic could show up twice. I am using a listview most of the time for these cases/
How do i avoid this and just built the widgets once so if the user goes back the page stays the same?