Questions tagged [statelesswidget]

121 questions
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
52
votes
2 answers

In Flutter, how do I pass data into a Stateless Widget?

I'm trying to build my first Flutter app, and have run into difficulty with passing data into Stateless Widgets. I have the following classes: class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new…
Sharon
  • 3,471
  • 13
  • 60
  • 93
46
votes
4 answers

error: The argument type 'Future' can't be assigned to the parameter type 'void Function()'

While I am passing value from home page to source page it shows an error: The argument type 'Future' can't be assigned to the parameter type 'void Function()'. (argument_type_not_assignable at [strong text] lib\home.dart:15) Where I am doing…
mdhv_kothari
  • 627
  • 1
  • 7
  • 14
44
votes
1 answer

Do stateless widgets dispose on their own?

I created a PostUpdaterWidget extending StatelessWidget which makes use of TextEditingControllers for testing out implementation of Bloc Pattern. final _usernameController = TextEditingController(); final _contentController =…
Rick
  • 2,003
  • 4
  • 16
  • 28
33
votes
1 answer

StatelessWidget vs a function returning Widgets in terms of performance

Is there any difference, performance wise, in using a StatelessWidget vs a function returning a Widget? I'm well aware of at least the differences pointed out in this flutter's repo issue which don't have a relationship with performance. The fact…
robertohuertasm
  • 846
  • 9
  • 17
22
votes
5 answers

Flutter: Where to add listeners in StatelessWidget?

If I were using a StatefulWidget, then I would be listening to a Stream for example inside the initState method. Where would I do the equivalent in a StatelessWidget (like to use Bloc with streams for state management)? I could do it in the build…
footurist
  • 1,509
  • 2
  • 16
  • 23
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
10
votes
3 answers

How to get context in the any function of StatelessWidget?

We want to show an AlertDialog after some asynchronous processing such as network processes. When calling 'showAlertDialog ()' from an external class, I want to call it without context. Is there a good way? class SplashPage extends StatelessWidget…
kyeonghwan
  • 424
  • 3
  • 7
  • 21
8
votes
1 answer

Flutter: StatelessWidget.build called multiple times

I always put code in my questions here, but this time it's not possible since the bug could be anywhere in a thousand lines of code. However: I noticed that the build method of my main screen (StatelessWidget), which is a descendant of a MaterialApp…
footurist
  • 1,509
  • 2
  • 16
  • 23
7
votes
2 answers

setState() or markNeedsBuild() called during build on ListView

So I am trying to refactor my listView logic. Basically my ListView has become cumbersome with the UI logic , so I decided, why not move certain parts of the UI logic to another class This is my code ListPage.dart import…
5
votes
2 answers

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 with a StatefulWidget as a subclass and never…
5
votes
3 answers

Stateful Widget updation on calling it with different parameters, not updating?

i just started learning flutter, im using Stateful widget the following code below is the main.dart file void main() { runApp(App()); } class App extends StatefulWidget { @override _AppState createState() => _AppState(); } class _AppState…
4
votes
4 answers

Flutter: How to fetch data from api only once while using FutureBuilder?

How can I fetch data only once while using FutureBuilder to show a loading indicator while fetching? The problem is that every time the user opens the screen it will re-fetch the data even if I set the future in initState(). I want to fetch the data…
AhWagih
  • 485
  • 5
  • 14
3
votes
1 answer

Is it possible to create a video player in stateless widget in flutter?

I was trying to create a videoplayer in a stateless widget in flutter. I could not do it.... this is the code I used ...Is it possible to create a video player in a stateless widget? class VideoWidget extends StatelessWidget { VideoWidget({Key?…
3
votes
3 answers

Why my pages are not refreshing with bottom navigation in flutter?

I am working with bottom navigation bar in flutter. I want to refresh every tab when tabs are switched. First I tried to reuse one stateless widget for all the tabs. But it is rerendering pages. My code is as follows: class _CreateOrderState extends…
1
2 3
8 9