Widgets vs helper methods | Decoding Flutter

Widgets vs helper methods | Decoding Flutter

Flutter

2 года назад

164,291 Просмотров

Flutter developers are well-acquainted with widget build methods that grow, and grow… and grow. In this video, Craig Labenz compares two different ways to break up those unwieldy build methods; and how the best option may be different than what you originally suspected.

See the differences in action in these DartPads:
Managing rebuilds with nested const widgets → https://goo.gle/3yallg1
Managing rebuilds with nested non-const widgets → https://goo.gle/3IyafpM
Preventing errors with separate widgets → https://goo.gle/3dDrR5o
Helper methods can create a requirement for Keys → https://goo.gle/31HlnQB

Get started with Flutter → http://goo.gle/Flutter
Learn more about the Dart Language → https://goo.gle/2YF9OCi

Watch more Decoding Flutter episodes → http://goo.gle/DecodingFlutter
Don’t miss an episode, subscribe to Flutter → http://goo.gle/FlutterYT

#DecodingFlutter #Flutter #Developer


product: Flutter - Development - User interface;

Тэги:

#purpose:_Educate #pr_pr:_Flutter #series:_Decoding_Flutter #type:_DevByte_(deck_cleanup_0-10min) #GDS:_Yes #developer_tutorials #Flutter #Flutter_tutorials #Flutter_developers #flutter_app_development #Flutter_course #how_Flutter_works #Flutter_best_practices #Decoding_Flutter #Google_developers #flutter_101 #get_started_with_flutter #flutter_apps #flutter_widgets #build_apps_with_flutter #flutter_developer #flutter_developers #Craig_Labenz
Ссылки и html тэги не поддерживаются


Комментарии:

iamyou
iamyou - 22.09.2023 15:52

Super video. Great good practice.

Ответить
Deadeye
Deadeye - 17.07.2023 21:37

I hope flutter / dart one day move to functioning programing, i hate classes so much boiler plate

Ответить
Alejandro MP
Alejandro MP - 13.07.2023 18:23

Yo me había preguntado eso. Gracias amigo

Ответить
Mayank Bhaisora
Mayank Bhaisora - 02.07.2023 16:54

I never thought about performance and testability but I always preferred NewWidgets instead of helper methods as it looked more natural to do in platform like flutter.

Ответить
Thông M. Trương
Thông M. Trương - 11.04.2023 11:23

That's really nice

Ответить
A. Belenky
A. Belenky - 17.11.2022 18:19

Minimizing dropped frames is nice but the real benefit is the power consumption. The vast majority of devices can run resource intensive apps effortlessly, but the power consumption is greatly affected. Making efficient apps is more for the battery life than for performance nowadays (although it's always good having faster apps as well)

Ответить
Nicollas Oliveira
Nicollas Oliveira - 13.11.2022 08:19

Thanks! These videos is really helpful!
I was in doubt about to separate the widgets (like Text('Hello');) in local variables, if it is also a bad idea... Another doubt is if for example I have a Widget with a lot of params, can I pass these params to another Widget using its instance? Like: WidgetWithALotParams(SomeChildWidget(parent: this)); (then the SomeChildWidget will have access to all WidgetWithALotParams params)

Ответить
Maria Papageorgiou
Maria Papageorgiou - 09.09.2022 20:36

What about if you use a global state management package like GetX or state rebuilder? Doesn't that mean that only the reactive part of the widget tree is rebuilt on state change?

Ответить
S R
S R - 22.08.2022 09:25

This is a extrenely valuable information. Thanks

Ответить
Julius
Julius - 19.08.2022 14:11

Thanks! I’ve been approaching the limits of readability in my current project and the „refactor widgets“ todo has been getting more and more priority recently. Now I know what to look out for :)

Ответить
NOT an English Person
NOT an English Person - 15.08.2022 12:47

I needed this

Ответить
ProgramingTales
ProgramingTales - 12.08.2022 00:40

Why not use stateful builder with the helper widget?

Ответить
Ehsan nazari145
Ehsan nazari145 - 08.08.2022 07:15

how about if we use getx?

Ответить
Simmons
Simmons - 13.06.2022 13:12

Been curious about this issue for a while now, you hit the nail on the head as always, thank you Google

Ответить
Miriam RAM Studio
Miriam RAM Studio - 27.05.2022 14:03

Great video. Thanks

Ответить
Anonymous Anonymous
Anonymous Anonymous - 17.05.2022 16:20

It is sad that const won't work with any localisation approach and most of the endpoint widgets in the widget tree brunches are Text.

Ответить
XCoder
XCoder - 15.05.2022 13:49

Good recommendations.

Ответить
Santiago Mamani
Santiago Mamani - 30.04.2022 05:39

Is there any scenario where helper methods would be a better choice than use a class?

Ответить
Chris O'Donnell
Chris O'Donnell - 01.04.2022 13:29

Geez wish someone told me this 3 years ago! I started with dozens of helper functions, slowly started using seperate widgets so the dart file wasn’t 2000 lines long. Still have a lot of refactoring to do 😅

Ответить
Raizen Sangalang
Raizen Sangalang - 01.04.2022 04:45

I really love the intro music!
can I have the full version? Hahaha

Ответить
Eugene Khumalo
Eugene Khumalo - 22.03.2022 11:35

Well this is helpful and I started doing this but hit some limitations (Either in my understanding or with Flutter)
So I have a form that has a complex dropdown that I would rather seperate it.
I still want to have access to values inside that dropdown for when I submit.

With a helper function I have access to that variable and can read it when I'm ready to submit
With a seperate class I don't have that link.
Is there a way I can share this data?

Ответить
Jim Morrison
Jim Morrison - 08.03.2022 16:58

So, using classes is better than using helper methods.
Ok, but is this a big difference?
If it is not, I would prefer to use helper methods in general for smaller sub pieces of UI.
Because using classes for these small things means you will have a huge amount of classes (all of which you have to try to name correctly), and a larger percentage of your codebase will be boiler plate.

Ответить
Danil Lubruk
Danil Lubruk - 03.03.2022 08:34

That was just soo helpful! As a new flutter developer, I just can't underestimate the value of such and advice!

Ответить
Abhishek Jain Dugar
Abhishek Jain Dugar - 22.02.2022 08:10

I also had thoughts about this topic. I started using separate classes for widgets but main problem I face with that is passing variables and callbacks are a bit challenging.

Ответить
eko purnomo
eko purnomo - 13.02.2022 21:06

Thanks

Ответить
bettercallshox
bettercallshox - 09.02.2022 15:17

Tried to apply this principle to create a countdown function but for some reason setting state in the countdown widget (which should only redraw the text every second) triggers a rebuild of its parent widget. Can't figure out why,

Ответить
Unknown
Unknown - 08.02.2022 15:36

but what if we didnt have any setState inside the helper method ? is it still okay to use helper method ?

Ответить
MobileMon
MobileMon - 04.02.2022 21:42

i wish there was some way around this. helper methods make things so much easier

if i have to create classes i have to pass in parameters and all code is more verbose

Ответить
Salahuddin Shaikh
Salahuddin Shaikh - 21.01.2022 21:14

I use methods to format code. So should I use classes for formatting also? I like it being seperated bcoz it makes me reading it easier.

Ответить
Pedro Varela
Pedro Varela - 08.01.2022 01:22

Next time wear a Batman like mask :D

Ответить
Ganesh Kgp
Ganesh Kgp - 07.01.2022 07:15

thanks ☺️☺️☺️

Ответить
LahiruDX
LahiruDX - 03.01.2022 19:17

I always used to use class constructors, because it makes code looks more readable and clearer for me. It's happy to hear that there are more valuable advantages too 😊.

Ответить
Kim
Kim - 02.01.2022 02:11

Well damn, guess i'll have to refactor my entire app

Ответить
Butbutmybutt
Butbutmybutt - 30.12.2021 18:02

Its also bad to debug because the helper method is not visible in the debug widget tree

Ответить
mars 000
mars 000 - 30.12.2021 13:27

i like your explanation style and pace... slow and clear with simple examples , makes it really easy to absord

Ответить
VerryCodes
VerryCodes - 30.12.2021 00:48

Thanks! Although I knew it already I needed to hear it from the flutter team again 😅!

Ответить
Hamza Ibrahim
Hamza Ibrahim - 29.12.2021 17:15

Thank you!

Ответить
the famousdjx
the famousdjx - 29.12.2021 16:04

Classes are always great since you can isolate them to a separate file. As your app grows bigger and complex, it becomes easier to fix bugs when things are isolated. The logic is also easier to follow when code is broken down instead of having over 2000 lines in a single file

Ответить
ahmed Albasha
ahmed Albasha - 29.12.2021 09:20

"Classes have a better default behavior. The only benefit of methods is having to write a tiny bit less code. There's no functional benefit."

- Remi Rousselet

Ответить
Hello India
Hello India - 25.12.2021 19:41

Hi sir i am beginner in a flutter
Can you please learn me one program that

1. Write dart program to generate random number of dice using class and object


2. How to use class in list and map in a dart

Ответить
OK OK
OK OK - 24.12.2021 14:05

Greeeat video, it helped me a lot!
As a novice in flutter I've started to use different classes for widgets right from the beginning as it felt logical for me. But watching more and more tutorials I've found out that people in them use helper method extensively and switched to that approach as it seemed easier to transfer data that way.
Now, this video put thing in correct perspective and explains why it's not the best way

Ответить
Thanh Đỗ
Thanh Đỗ - 24.12.2021 10:54

thanks, i understand more something from your video!!!!

Ответить
AngelHdz
AngelHdz - 24.12.2021 08:00

StatefulBuilder?

Ответить
B_Rabbit
B_Rabbit - 23.12.2021 16:54

is there a possibility that flutter will have a drag and drop method to create app in the future?

Ответить
Gottfried Chen
Gottfried Chen - 23.12.2021 13:25

That's kinda counterintuitive for a React Developer, where functional components (aka widgets) are preferred over class components. Would be great, if Flutter could somehow elevate functional widgets (aka helper methods) to the same level of performance as class widgets.

Ответить
Coding Your Life
Coding Your Life - 23.12.2021 08:58

Thanks so much.
Help me from the end of death on boilerplate coding.
😁👍

Ответить
Hamza Abbad
Hamza Abbad - 20.12.2021 23:26

I am still a Flutter intermediate programmer so I don't know much about performances, but I never liked that helper method style. I always use the classes way because it feels more natural (at least to me).

Ответить
Ryan
Ryan - 20.12.2021 00:21

Very articulate and concise delivery!

Ответить
name Is Vamshi
name Is Vamshi - 19.12.2021 14:19

Though this is not the right platform to ask...I am struggling in building an android app with flutter.. apk is not building.. There is an error in build.gradle file.. It says
could not resolve properties..even stack overflow could not resolve my query

Ответить
Shourya Shikhar
Shourya Shikhar - 19.12.2021 09:25

Solved the biggest confusion I was having. Thanks

Ответить