Questions tagged [statefulwidget]

The tag has no usage guidance.

statefulwidget
Filter by
Sorted by
Tagged with
353 votes
10 answers
248k views

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 ...
moonvader's user avatar
  • 20.5k
288 votes
8 answers
206k views

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; ...
Mojachiee's user avatar
  • 2,999
154 votes
12 answers
71k views

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 ...
user462455's user avatar
  • 13.3k
21 votes
5 answers
10k views

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 ...
HexaCrop's user avatar
  • 4,063
20 votes
3 answers
9k views

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 ...
Arthur Facredyn's user avatar
12 votes
3 answers
10k views

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("...
Magesh Pandian's user avatar
10 votes
1 answer
9k views

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's user avatar
  • 213
9 votes
3 answers
8k views

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<String, List<dynamic>>(); Now I need to filter the items inside the ...
Giacomo M's user avatar
  • 4,591
8 votes
2 answers
3k views

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 ...
Trần Đức Tâm's user avatar
8 votes
2 answers
10k views

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<...
Hitesh Danidhariya's user avatar
8 votes
2 answers
5k views

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<MyObject> snapshot)...
Scaraux's user avatar
  • 4,014
6 votes
1 answer
2k views

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 ...
Amdixer's user avatar
  • 91
6 votes
1 answer
3k views

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's user avatar
  • 4,622
6 votes
3 answers
8k views

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 ...
Jakub's user avatar
  • 103
5 votes
2 answers
5k views

Do all widgets in Flutter have the "bool this.mounted" property?

Peace be upon you I am researching Flutter's widget lifecycle and stopped at a point which is the this.mounted boolean variable, it does exist directly in the State class, which can only be connected ...
Salah Rashad's user avatar
5 votes
3 answers
6k views

Flutter - Stateful Widget Doesn't Save Counter State When Switching Tabs

I am learning flutter and I am working with tabBars and I am having an issue with saving the state. I have put a small working example of my issue below. Basically, there is a button and a stateful ...
casmang's user avatar
  • 385
5 votes
2 answers
6k views

When is the State object destroyed in a StatefulWidget?

One of Flutter's mantras is that widgets are immutable and liable to be rebuilt at a moment's notice. One reason for the StatefulWidget is the accompanying State object, which 'hangs around' beyond ...
larryq's user avatar
  • 16k
5 votes
4 answers
3k views

Understanding the use of StatefulWidget in Flutter

I'm just starting to fiddle with Flutter and I can't understand the point of StatefulWidget. All those widgets do anywhere I've seen in tutorials etc. is instantiate a State<MyWidget> and let it ...
Neo's user avatar
  • 3,656
5 votes
1 answer
1k views

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 ...
lycheelichi's user avatar
5 votes
2 answers
9k views

Accessing a function of stateful widget in its state class? flutter

I am trying to call _signOut function after the onPressed method for logout button. However it doesnt (recognize the function or let me call it) I can however make a call widget.Onsignedout, a ...
Tegster007's user avatar
4 votes
2 answers
5k views

Is it possible to extend a StatefulWidget that provides an extra parameter on its build method?

I would like to create a BaseScreen Widget like this to reuse in my app: class BaseScreen extends StatelessWidget { final Widget child; BaseScreen({this.child}); @override Widget build(...
Jan's user avatar
  • 2,502
4 votes
3 answers
90 views

How to manage a custom widget state in SingleChildScrollView Widget

I'm trying to design this view. I already have the basic design of the cards, but i would like to know how to change the card's background color, the card's border color and add the little green ...
MATEO VALENCIA MINOTA's user avatar
4 votes
1 answer
13k views

SetState() called in constructor

I've build a Custemized List. Now I include a Checkbox and if I would checked or unchecked , the following error was thrown: 'setState() called in constructor' class Lists extends StatefulWidget{ ...
Julia's user avatar
  • 55
4 votes
1 answer
6k views

Flutter: Change the parameter passed to a "StatefulWidget"

I have a StatefulWidget named BounceContainer. This class contains a parameter child like a typical Flutter widget. Basically, it bounces the child whenever the user taps on it. The way I pass the ...
Melvin Abraham's user avatar
4 votes
1 answer
712 views

How to recreate a single widget in flutter and make it lose the state?

I have a widget that I want to recreate the state for what can I do to achieve this? I heard there is a way by UniqueKeys but I have no idea about them well because I'm a beginner (don't worry I have ...
Hussein Al-mosawi's user avatar
4 votes
1 answer
3k views

how to setState inside streambuilder

I have a streamBuilder inside a stateful widget that gets data asynchronously from the server. Additionally, I have a list that collects those data. StreamBuilder( stream: myStream.stream, ...
MoneyBall's user avatar
  • 2,393
4 votes
1 answer
1k views

How do I access a method of the state objects for a list of stateful widgets? (Flutter)

class Astate extends State<A> { List b=new List<B>(); @override Widget build(BuildContext context){ b.add(B()); //how do I access theMethod() for the state object ...
Nand gopal's user avatar
3 votes
2 answers
6k views

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 ...
MSARKrish's user avatar
  • 3,699
3 votes
1 answer
148 views

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 ...
Yousef Gamal's user avatar
  • 1,056
3 votes
2 answers
8k views

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 ...
London Tran's user avatar
3 votes
4 answers
705 views

Flutter for web: back/forward button problem

I am facing the following problem: I have a StatefulWidget which can generate different view in case of state change: class _HomePageState extends State<HomePage> { bool _changed = false; @...
Kasata Ata's user avatar
3 votes
3 answers
1k views

One big StatefulWidget or multiple small StatefulWidgets

I have a UI that has 20+ small widgets that need to update simultaneously, while some widgets remain Stateless. I was wondering if it is more efficient to have the whole UI updated rather than having ...
hman_codes's user avatar
3 votes
1 answer
2k views

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 ...
Daniele's user avatar
  • 4,263
3 votes
1 answer
556 views

How to make Flutter rebuild nested Stateful Widgets?

I need a custom button that looks a certain way and runs simple animations on itself (really simple, like cross-fading to a different color and then back upon being pressed). I have written such a ...
Lev Tyrnov's user avatar
3 votes
4 answers
7k views

How to force initState every time the page is rendered in flutter?

I am adding some data into the SharedPreferenceson page2 of my app and I am trying to retrieve the data on the homepage. I have used an init function on page 1 as follows: @override void initState(...
ag2byte's user avatar
  • 203
3 votes
2 answers
3k views

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 ...
Pars's user avatar
  • 5,112
3 votes
2 answers
390 views

Are Statefull widget deleted and replaced when being rebuild using setState()?

As per my inforamtion, flutter has a widget tree and an element tree. For every stateful widget in the widget tree an element in the element tree is created with state object attached to it, that is ...
Ekjyot Sandhu's user avatar
3 votes
0 answers
627 views

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 ...
Levaru's user avatar
  • 51
3 votes
0 answers
190 views

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 ...
codingmonk21's user avatar
3 votes
1 answer
3k views

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 ...
Jordan's user avatar
  • 486
2 votes
2 answers
4k views

How to reuse a stateful widget in flutter

I have a following state full widget. I need to reuse it as it is by just changing two variables id and collectionName. Generally I would extract a widget, but in this case I am modifying variable ...
Aseem's user avatar
  • 6,400
2 votes
2 answers
45 views

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 ...
Blue M's user avatar
  • 65
2 votes
3 answers
3k views

Why I'm getting the error, Invalid constant value in flutter statfulwidget flutter

In the below code widget.hintText is giving the error, I am trying to make the datepicker as the seperate component and dynamically pass the hinttext value whenever calling it from the other file. ...
ibex's user avatar
  • 113
2 votes
1 answer
1k views

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 ...
Myrmillion's user avatar
2 votes
1 answer
5k views

Flutter - NoSuchMethodError: The getter 'focusScopeNode' was called on null

I am having the following error while trying to pass List from one screen to another. The data is being passed from the async function. I need to open the other Screen based on the data fetched from ...
Jamshaid's user avatar
  • 380
2 votes
1 answer
858 views

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 ...
Gwhyyy's user avatar
  • 8,322
2 votes
2 answers
637 views

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 ...
Saad Mansoor's user avatar
2 votes
2 answers
3k views

Error Missing concrete implementation of 'StatefulWidget.createState'. Try implementing the missing method, or make the class abstract

import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatefulWidget { Widget build(BuildContext context) { return Scaffold( body: Center(...
Erano-'s user avatar
  • 29
2 votes
2 answers
2k views

Flutter Stateful Widget Constructor That Does Not Include All Members

I am building a Stateful Widget in Flutter, and as such, there is a requirement for all arguments passed in the constructor to be final (since Stateful widgets are marked with the @immutable ...
tomerpacific's user avatar
  • 5,503
2 votes
1 answer
376 views

what does Inflating StatefullWidget mean in Flutter?

State objects are created by the framework by calling the StatefulWidget.createState method when inflating a StatefulWidget to insert it into the tree. Here What does inflating StatefulWidget mean?
anirudh bisht anirudh bisht's user avatar

1
2 3 4 5
7