r/FlutterDev • • May 13 '20

Discussion Get? Get!

So, I'm new to Flutter. I've only been learning it over the past month — only been coding for the past six months or so. State management has been really tough to come to grips with. I've been trying out a few different approaches and Provider, or the Stacked ... uhm, stack, have seemed the simplest approach to get started.

But then I started reading up on how Stacked uses a library called Get for routing. So I read-up on Get's pub page and see that the library has its own stupidly simple approach to managing state. Like, it's too easy.

Has anyone else had a chance to play around with it? I'd like to know if there's a reason not to ditch all of the other approaches in favor of this total simplicity.

19 Upvotes

32 comments sorted by

View all comments

12

u/ajinasokan May 14 '20

It looks very simple. But the following line from readme threw me off:

Using StatefulWidgets means storing the state of entire screens unnecessarily. With Get the use of StatefulWidget is optional. Avoid them and save your users' RAM.

Who is teaching these?!

9

u/Fienases May 14 '20

That readme spread so many false information

1

u/JoeJoe_Nguyen May 14 '20

Holy moly! Is StatefulWidgets really that scary?

7

u/dancovich May 14 '20

Not even close. This information is very inaccurate.

Widgets in Flutter are only configurations. They tell how to render an element, they are not the element themselves.

StatefulWidgets store only what you want. A stateful widget with a single field "String name" will keep in memory just that.

2

u/jonataborges May 18 '20

It is okay to use StatefulWidget, even GetBuilder is a StatefulWidget. What the documentation makes clear is that saving an entire stateless class inside a statefulWidget will consume more RAM, you don't need to create a theory of the beyond for that, the documentation is clear in saying that statefulwidgets are more expensive than statelesswidget, not much more expensive, but it is a larger class, with functions that will be totally unnecessary in a widget that has no change of state. On the desktop Flutter, I am right now with a StatelessWidget class with nothing inside but a Scaffold, and a StatefulWidget with nothing inside but a Scaffold, and the difference between them is 1mb. Obviously this does not resonate in all cases, the difference in mobile in release with AOT should be at most 500kb, but definitely, creating a Stateful class for everything will spend more RAM, in addition to being bad practice. And you don't need to theorize that, just open the Dart inspect and see for yourself.

5

u/remirousselet May 21 '20

This is wrong information.

The difference between a Stateless and Stateful RAM wise can be measured in bytes. It is by no mean close to 1mb.

And even then, a tree that looks like this:

StatefulWidget > Scaffold > Text

will still consume less memory than:

StatelessWidget > Scaffold > WhateverBuilder > Text

0

u/jonataborges May 23 '20

Your comment doesn't make any sense! We are not talking about ephemeral state management, but application state management!

StatefulWidget > Scaffold > WhateverBuilder > Text is more expensive of StatelessWidget > Scaffold > WhateverBuilder > Text

Creating a StatefulWidget will not prevent you from using the Provider's Consumer, for example, so honestly, I couldn't find any sense in your comment.

3

u/remirousselet May 23 '20

Your Readme arguments that StatefulWidgets consumes a lot of memory, and that get fix it by changing:

StatefulWidget > Scaffold > Text

Into

StatelessWidget > Scaffold > GetBuilder > Text

Which is supposed to consume less memory.

I pointed out how argumenting that doesn't make sense.

And if we'll mention provider, then people mostly use Provider.of/context.watch instead of Consumer.

So we'd have:

StatelessWidget > Scaffold > Text

So there's no StatefulWidget involved at all. Not even a builder.

But that doesn't matter. Because the premise that StatefulWidgets consume a lot of memory is wrong, so provider won't argue that it's architecture saves memory.