Questions tagged [statefulwidget]

339 questions
3
votes
2 answers

Class marked as @immutable, instance field not final using StatefulWidget

I have a Stateless widget called ToggleButtonsList and one of my instance fields, isSelectedType, is not set to final. This is the warning I am receiving because of this: "This class (or a class that this class inherits from) is marked as…
London Tran
  • 202
  • 2
  • 7
3
votes
0 answers

How do I keep my widget state when reordering them via Draggable&DragTarget?

I'm using this reorderables package. This package works by having a list of children widgets that are each wrapped with a Draggable and put inside a DragTarget. Before that the childs key is assigned to a GlobalObjectKey. After the dragTarget is…
3
votes
0 answers

StatefulWidget as a list item is recreated on every scroll in ListView.builder

class ListItem extends StatefulWidget { final Product product; ListItem(this.bloc, this.product); @override _ListItemState createState() => _ListItemState(product); } class _ListItemState extends State { Product product; …
codingmonk21
  • 73
  • 2
  • 11
3
votes
1 answer

didUpdateWidget called immediately after initState in Flutter

According to Flutter Documentation: didUpdateWidget called whenever the widget configuration changes But, in the following code, didUpdateWidget is called immediately after initState on the first time. import…
Pars
  • 4,932
  • 10
  • 50
  • 88
3
votes
2 answers

How to Call stateful widget(have form) method from another dart file?- Flutter

I have a Form in Stateful Widget, in my stateful widget i validate my form with submit method. In my app i'm showing that form in another page in another dart file. My form is visible in new page and in appbar actions i'm calling submit method but i…
MSARKrish
  • 3,355
  • 4
  • 30
  • 43
3
votes
1 answer

Why would I ever use StatelessWidget over StatefulWidget?

I know that StatefulWidget allows us to change widgets, while StatelessWidget does not. But if StatefulWidget can perform everything that StatelessWidget can perform + more, why would I ever use StatelessWidget over StatefulWidget? Is…
Yousef Gamal
  • 1,026
  • 2
  • 17
  • 32
3
votes
1 answer

Deselect a button when another button is selected

I create a custom button that changes it's Image and Text color based on the bool pressAttention parameter. class UserButton extends StatefulWidget { final String unselectedImagePath; final String selectedImagePath; final String text; …
Daniele
  • 4,163
  • 7
  • 44
  • 95
3
votes
1 answer

How to keep state using flutter page route

I have a simple app, it has named route in an appbar to a stateful widget. Currently, whenever I navigate away from the stateful widget and back again, the stateful widget loses its state (in this case my counter goes back to 0). I'd like the…
Jordan
  • 476
  • 7
  • 16
2
votes
2 answers

Issue with statefulWidget unable to make desired changes

I am working on a statefulWidget and my purpose is to make sure that the next button is not clickable until an option (in this language is selected). However it doesn't seem to work, I also added Yaesin's(Someone who answered) answer to the code …
Blue M
  • 65
  • 6
2
votes
0 answers

Under what situations would it matter whether information is stored in the stateful widget class or the state class?

Here is property as a part of the StatefulWidget class class MyWidget extends StatefulWidget { String property = ""; @override State createState() => _MyWidgetState(); } class _MyWidgetState extends State { @override …
Joel Castro
  • 485
  • 6
  • 20
2
votes
1 answer

I use Stateless Widget alongside BLoC almost everytime. Am I wrong?

I am having a hard time understanding how to deal with states in some specific situations with Flutter. For example, say I need a page where the click of a button fetches data from an API. Such a request could take time or any kind of problems could…
2
votes
1 answer

Understanding how Getx state update with specific id work with SetState((){})

while discovering Getx source code, I faced a piece of code that make me confused, it's not related 100% to Getx. it's about SetState(() {}) so, in the Getx there is a state update that targets only the widgets with a specific id: Disposer…
Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
2
votes
2 answers

why use initState() in flutter, when we can just initailize a variable in the very first line of code

is there a difference in these 3 codes: First: when i call my function inside onInit(). @override void onInit() { super.onInit(); fetchProductsFromAPI(); } Second: when i call my function inside of build method, in stateless…
Saad Mansoor
  • 199
  • 7
2
votes
1 answer

How to access a variable data from the state of a flutter stateful widget from another stateful widget class's state

Hi guys I am facing a problem which I have tried to solve through multiple approaches but failed. I have a stateful widget class which has a variable in its state I need to access the data in this variable from another stateful widget's class's…
2
votes
2 answers

Flutter setState Function

I noticed the more you got variables in your statefulWidget, the more the setState function takes time to complete. Making the app kinda slow, and this is quite annoying. Is there a way to change state for Only one variable, please? I mean something…
70B1 H4CK3R
  • 322
  • 1
  • 10
1 2
3
22 23