Flutter SetState is not refreshing UI - flutter

I'm building multiple form pages in one class, I create 4 widgets each widgets is represent a page with text fields or cards or radio buttons.
and I create a method to switch between pages when. I press next.
This works as expected ^^
My issue UI inside first page is not refreshed unless I press ctrl + S,,
inside the first page of the form, I have created custom radio buttons they're simply cards.
and when tap on any card, there's set state method, to highlight the selected card by changing its style..
This works perfectly! at the beginning when I call the first page 1 directly as a child inside the scaffold..
However, after I created the method to switch between pages.. The UI in page 1 does not refresh..
I will put a picture..
Picture of the method to switch pages
Picture of pages widgets
picture of scaffold and how I call the widget pages
this is a picture of custom radio button which has cards, the card color change if it's selected
I tried many ways! but it didn't work..
Is what I'm trying to do correct? I'm a beginner in flutter
& I have a project to submit :(
I couldn't find a solution in google,,

Try making the widgets StatefulWidget and call setState((){}) inside the widget when you tap on the cards.

So here's what I did ^^
because the issue was just in page 1, so I in the scaffold I added page 1 as it's child directly without Switch page method..
Then inside page1, a button that will navigate to another class,
the second class has exactly the same scaffold and app bar as previous page.. But, in it's child I added calledWidget which switch between pages from 2 to 4 in my case ^^
So short words, I put page 1 in a separate page and the rest of the pages in a switch method in separate class
it works, but I hope I don't find any difficulties When saving values & integrating API to post the values
what you think?

Related

Sending ListView Builder data to Next Screen

I have a ListView in Flutter and want to send Multiple data into Next widget, but when I add a checkout button, it's showing 3 times because I have 3 items in my cart List so I can't add button in my ListView but when I have tried this button in bottomNavigationBar but I can't access Listing view data. Below is the Screenshot.
I am not able to understand your question, can you phrase it more clearly, try short sentences. Also make sure to add your code, if it is too large then add your GitHub, or any other public repo link so we can see the code. Final thing, I can't see any screenshots.

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.

Screenshot Controller flutter - capture method returns a null Uint8List when record is added

On the home screen on my app :
I have a list view with a bunch of card widgets and a screenshot action associated with each card widget. When I click on the screenshot action it captures the screenshot of that widget as it’s supposed to.
I have a floating action button which when clicked takes me to an add screen where I add data and save it to the database. Once saved a snackbar message is displayed and screen is popped out. The list view now displays the new record as a card widget.
PROBLEM :
After adding the record, when I click the screenshot action no widget screenshot is captured and on debugging I noticed the “Uint8List? image” is null.
Now if I scroll the list view and perform the screenshot action again everything seems to work.
It sounds to me that this might be a widget tree rebuild issue, but I am not sure how to go about with it. I have other actions, edit and delete on the card widget and they work without any issue.
Package used: screenshot 1.2.3

Flutter, my inputs getting cleared when re-openning page with bottomnavbar

I have a bottomnavigation bar and 3 pages. I move between these 3 pages with Get.to() in bottomnavigationbar. I have some input fields in one of those pages. I write inputs then I go to another page with bottomnavigationbar and then I reopen that page again but every input I wrote is cleared. I want to save the state of that page or with other words, I don't want these inputs to get cleared when moving to another page. How can I achieve it?
Because you are using Get.to(), meaning you using get libbrary.
In this case you need to put your TextEditingController to your GetxController and binding in the page that contains your bottomnavigationbar. Now the parent page was hold the GetxController who will store your textfield state instead of widget state.
Or just adding permanent: true to your controller binding.

Flutter Webview reloads every time I switch screen

I'm making an app with a BottomNavigationBar with 5 different screens, each of them has a web view. The problem is that everytime I come back to a screen that was previously loaded, it reloads. I have tried using AutomaticKeepAliveClient from copy pasting this code but I doesn't seem to work. I'm new with Flutter so be precise please, thank you.
AutomaticKeepAliveClient is mainly used for keeping a child alive in lazily rendered list views. In your case whenever you switch tabs your current page get disposed and new page materializes on top of it, that means each time when you switch tab a new page is created including all it's widgets.
So if you want to keep your previously loaded web views alive, you have to go with either PageView widget or use Stack widget to load your pages programmatically while the user clicks on a tab.
This is a detailed example about implementing your requirement using PageView widget . you can also find an example with Stack widget under that question.