Questions tagged [statefulwidget]
339 questions
342
votes
8 answers
Passing data to StatefulWidget and accessing it in its state in Flutter
I have 2 screens in my Flutter app: a list of records and a screen for creating and editing records.
If I pass an object to the second screen that means I am going to edit this and if I pass null it means that I am creating a new item. The editing…

moonvader
- 19,761
- 18
- 67
- 116
274
votes
8 answers
Passing Data to a Stateful Widget in Flutter
I'm wondering what the recommended way of passing data to a stateful widget, while creating it, is.
The two styles I've seen are:
class ServerInfo extends StatefulWidget {
Server _server;
ServerInfo(Server server) {
this._server = server;
…

Mojachiee
- 2,859
- 4
- 14
- 9
155
votes
12 answers
What is the relation between stateful and stateless widgets in Flutter?
A stateful widget is defined as any widget which changes its state within its lifetime. But it is a very common practice for a StatelessWidget to have a StatefulWidget as one of its children. Doesn't StatelessWidget become stateful if it has…

user462455
- 12,838
- 18
- 65
- 96
20
votes
5 answers
Why do we need stateless widgets if the same can be achieved by stateful widgets in flutter?
I am a newbie in the world of flutter, and I recently learned (or I think I did) about stateful and stateless widgets which is kind of the base for flutter widgets.
We use stateless widgets for things that are not redrawn on the display, (like text,…

HexaCrop
- 3,863
- 2
- 23
- 50
16
votes
3 answers
Preserve widget state when temporarily removed from tree in Flutter
I'm trying to preserve the state of a widget, so that if I temporarily remove the stateful widget from the widget tree, and then re-add it later on, the widget will have the same state as it did before I removed it. Here's a simplified example I…

Arthur Facredyn
- 1,017
- 1
- 9
- 16
12
votes
3 answers
StatefulWidget Page recreate when keyboard is open
In my profile page have edit option when use click edit icon i change Text widget to TextField Widget using Boolean condition like
widget.isUpdate ? new Flexible(child: new TextField()) : Text("Text Widget") it working but when TextField focused the…

Magesh Pandian
- 8,789
- 12
- 45
- 60
9
votes
3 answers
type '(dynamic) => dynamic' is not a subtype of type '(dynamic) => bool' of 'test' when I use map function
I have a StatefulWidget widget with a LinkedHashMap member done like this:
LinkedHashMap _items = new LinkedHashMap>();
Now I need to filter the items inside the List items of the Map.
I use this code to…

Giacomo M
- 4,450
- 7
- 28
- 57
8
votes
1 answer
Get parent widget height in flutter
I want create statefulWidget and want in this widget get parent widget height. Don't want do this by sending height data from parent widget. How can I do this?

esfsef
- 193
- 3
- 11
8
votes
2 answers
Flutter reset StatefulWidget state when Widget is recreated
In my Flutter Widget I have a StreamBuilder that checks for snapshot.hasError and in this specific case it will return my ErrorRetryWidget().
builder: (context, AsyncSnapshot snapshot) {
...
if (snapshot.hasError) {
return…

Scaraux
- 3,841
- 4
- 40
- 80
8
votes
2 answers
How to stop a widget to reload on setState() method in StatefulWidget Class in Flutter
What I am trying to achieve is to save the state of the Widget i.e it should not refresh when the setState() method is been called.
class _GenderSelectionPageState extends State {
bool isFemaleSelected = false;
…

Hitesh Danidhariya
- 709
- 1
- 7
- 14
6
votes
1 answer
Multiple instances of same Statefulwidget seem to share the same State object?
I'm trying to build an app using Flutter and am running into a small problem. I'm trying to implement a BottomNavigaionBar style app with three pages. (see first snippet) The layout makes use of three objects of type "ChorePage". It seems like the…

Amdixer
- 91
- 4
6
votes
2 answers
Why build method isn't defined inside StatefulWidget?
I'm currently learning Flutter. I tried to deep dive into Flutter Widget life-cycle, and I wonder why StatefulWidget are written like this :
class Example extends StatefulWidget {
@override
_ExampleState createState() =>…

Trần Đức Tâm
- 4,037
- 3
- 30
- 58
6
votes
3 answers
How to change a State of a StatefulWidget inside a StatelessWidget?
Just testing out flutter. The code sample below is a very simple flutter app. The problem is that I don't know how to call the setState() function inside the TestTextState class in order to change the text each time when the change button is…

Jakub
- 103
- 1
- 6
5
votes
1 answer
Flutter : keep an persistent( timer )widget open and running across multiple screens
I have an app that needs a persistent, across multiple screen timer feature in it, which can be launched from one or two different screens.
I can build a timer widget and countdown part. But I can't seem to figure it out how to keep it running and…

lycheelichi
- 185
- 1
- 2
- 9
5
votes
1 answer
What's the scope of an UniqueKey in flutter?
I'm an unique person. I mean I'm different from all other persons in this world. When I create an UniqueKey in flutter, what's the world in which it's different from all the others?

John Wang
- 4,562
- 9
- 37
- 54