Questions tagged [statelesswidget]
121 questions
3
votes
1 answer
Custom Flutter widget to return two widgets for use with CustomScrollView / slivers
I have a Flutter CustomScrollView with the following structure:
body: CustomScrollView(
slivers: [
MyCustomTitle(...),
MyCustomSliverGrid(...)
MyCustomTitle(...),
MyCustomSliverGrid(...)
MyCustomTitle(...),
…

TechAurelian
- 5,561
- 5
- 50
- 65
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
2 answers
Flutter: Mutable fields in stateless widgets
The class StatelessWidget is marked as immutable. However, I am using the scoped model, which means that I avoid StatefulWidget and use the model to alter state in StatelessWidget. This leads to me having non-final fields in StatelessWidget, which…

footurist
- 1,509
- 2
- 16
- 23
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…

Myrmillion
- 78
- 6
2
votes
0 answers
What's the use of Stateless Widget if one can directly return a widget
This might be an odd question but I'm wondering what's the actual use of stateless widget if one can simply return a widget? Stateful widgets on the other hand are useful for handling states because of setState method. Are stateless widget only…

cattarantadoughan
- 509
- 1
- 6
- 15
2
votes
1 answer
Flutter StatelessWidget and Provider not updating or calling build unnecessarily
I'm trying to use Provider with a Stateless widget page to update a countdown UI.
When I run all the below, I get both print messages in the console on each 1 second tick of the stopwatch:
e.g.
flutter: build()
flutter: _buildCountDown()
Also, the…

Dave
- 5,283
- 7
- 44
- 66
2
votes
1 answer
stateless Widget Keeps Rebuilding
I'M currently working on a to-do app following a tutorial
this is the checkbox part
I'm trying to lift it's state up the tree, but when I do so the stateless widget just keeps rebuilding non stop ,
I tried adding key , adding const converting it to…

abdalla mohamed
- 21
- 2
2
votes
1 answer
Is it possible to use "formKey.currentState" inside a stateless widget with GetX?
I am trying to convert a code that uses provider package and stateful widget to use GetX package and stateless widget. One problem I do have is that I have a form that changes(from login to signup and vice versa) using animation, but when I check…

Hasani
- 3,543
- 14
- 65
- 125
2
votes
1 answer
What is the alternative for "initState()` while we using "GetX" and "statelessWidget"?
I have the following code that is inside a statefullWidget, and I want to change the statefullWidget to a statelessWidget and use GetXCintroller instead.
AnimationController? _controller;
Animation? _slideAnimation;
Animation?…

Hasani
- 3,543
- 14
- 65
- 125
2
votes
1 answer
ChangeNotifier wrap class around each instance of a model
I have an application where I display a list of cards that represent a model (Let's say a Person). These are stateless widgets as they cannot be changed directly. These instances are obtained from an API and, since the amount of items is large, I am…

Dpac99
- 21
- 2
2
votes
1 answer
How to use setState() function inside statelessWidget class
I can't use setState function inside dialogContent and I got this error :
The method 'setState' isn't defined for the class 'CustomDialog'
and here I used setState()
Row(
mainAxisAlignment: MainAxisAlignment.center,
…

Laila Mattar
- 361
- 4
- 19
2
votes
2 answers
Since a ListView in Flutter is stateless, how come it can be changed?
This is more of a philosophical question, I think, and the title pretty much says it all. It seems like a contradiction, that a ListView derives from stateless, and yet can be changed while the app is running.

Michael Rogers
- 1,318
- 9
- 22
2
votes
5 answers
Flutter call setState() to update UI in another class
I am trying to call a setState when a button is pressed so the ui can show the new list but even using functions i cant use setState or it will give me the error saying im calling setState inside a constructor.
This is my code for the…

André Sousa
- 187
- 4
- 17
2
votes
1 answer
Choosing StatelessWidget or StatefulWidget for sub-widget which has TextEditingController as a child
I'm working on a refactored code to separated small piece of widgets.
There's several columns with TextFields in each one of them.I have two options to complete the task :
Choosing StatelessWidget since it have more performance, may put…

JerryZhou
- 4,566
- 3
- 37
- 60
2
votes
1 answer
How to initialize final member with other final member in StatelessWidget subclass?
I have a simple StatelessWidget that creates a new StatefulWidget in its constructor. The problem is that to create that widget, another object needs to be created first. And then when I pass it to the constructor, I get the error
error: Only…

UglyBob
- 247
- 1
- 14