Flutter Tutorial for Beginners #21 - Functions as Parameters

preview_player
Показать описание
Hey gang, in this Flutter tutorial I'll show you how we can update the state of our 'parent' widget by passing a function into a nested 'child' widget.
----------------------------------------

🐱‍💻 🐱‍💻 Course Links:

🐱‍💻 🐱‍💻 Other Related Courses:

Рекомендации по теме
Комментарии
Автор

I wanted to learn flutter but even paid courses couldn't teach well. You really have given your best and it is shown. Clicking on all ads that come up :) Thank you so much

priyaiyer
Автор

can't believe how am i learning so fast, now i just watch your video once and then try to clone all the steps on my own unlike before where i have to do simultaneously with you! you are killing it!!!

brijpatel
Автор

In the latest version of Flutter, FlatButton has been replaced by TextButton . TextButton is a button without elevation that is used for secondary actions in dialogs and cards. You can customize its appearance using the styleFrom method of the TextButton.styleFrom class.

Автор

Nice One !
And those who are not creating the card without extracting the widget can simply use the delete method by adding following code in widget function::---

SizedBox(height: 6.0 ),
TextButton.icon(
onPressed:(){
setState(() {
quotes.remove(quote);
});
},
label:Text('Delete Quote'),
icon:Icon(Icons.delete),
),

PS : FlatButton is replaced as TextButton in latest update.

akdworld
Автор

if u have The argument type 'Function?' can't be assigned to the parameter type 'void Function()?
replace Function to VoidCallback
like here
final VoidCallback delete;

ahjed
Автор

Another workaround in the latest version of flutter is calling the delete() function -
TextButton.icon(
onPressed: () => delete(),
label: Text('Delete Quote'),
icon: Icon(Icons.delete),
)

amanahlawat
Автор

Thanks for this amazing course!! I finished it really fast and I came back to this project and I wanted to implement a StackBar with undo and also add button for adding new quotes. I had a hard time figuring out the stuff but after a hour I finished my application and it works. I'm really happy right now

bosnian.artillery
Автор

10 stars explanation. Been searching all over the internet to understand how to pass a function as a parameter and use it into onTap or onPressed, but couldn't find it. This is what I was looking for. THANKS

ahmadhayek
Автор

This tutorial is the best flutter beginner's tutorial I have ever learned. Easy to understand, and a lot of details explained clearly.

jojog
Автор

At 4:18, the delete function needs to be declared of type VoidCallback rather than Function. Simply didn't work otherwise.

advitiayanand
Автор

Thanks for the amazing video. Quick question: What about if the card has more then 5 actions like delete. Should we pass 5 Functions? Or is there another way to solve with one function?

xurshidbek_kurbanov
Автор

React knowledge comes in very handy for this lecture :)

nikulasoskarsson
Автор

my head just exploded...so much and fast input:D Nice!

mctopsengoolge
Автор

To understand why are we calling setState() from a StatelessWidget and why can we delete a widget from the list (quotes), we need to understand the difference between two concepts:
Lexical Scope and Dynamic Scope.

In a Lexical Scope, variables are resolved based on the structure of the code, i.e. where they were defined.

In most modern languages, such as JavaScript, Python and Dart, that use Lexical Scoping, the callback function has access to the variables that were available in the scope where it was defined, regardless of where or when it is called. This ensures predictability in the callback's behavior.

On the other hand, in Dynamic Scope languages, variables are resolved based on the sequence of calls at runtime. The language searches for the variable in the environment of the calling function. Example: in some old versions of Lisp or Perl.

As Dart (Flutter) adopts a Lexical Scope approach, in this video the delete function is “inside” a stateful environment and has access (back) to the list of widgets (quotes).

fabiogabriel
Автор

bro I cant wait to create my first application in order to help someone else’s,

Thanks so much 🌹

cjeeckazad
Автор

You are so good I just deactivated all adblocks for this page. Thanks

adekanlesimon
Автор

This is something I have been doing since past few weeks and needed to be sure if it is a right approach. Thanks :)

krupeshanadkat
Автор

I've been getting...the method 'remove' isn't defined for the type 'Quote' error for so long.

shambhavisingh
Автор

you will need to create remove method in quote.dart file or else it will give error when u create delete function, idk abt others but it gave error to me

itsmelodiouskeys
Автор

You saved my day man....great tutorial and concise explanation ... keep up the good work brother

rayanfernandes