List Method .forEach() in Dart & Flutter
ฝัง
- เผยแพร่เมื่อ 22 ก.ค. 2024
- In this series, we will learn more about different list methods in #Dart and see how we can use them in #Flutter. In this episode we have a closer look at .forEach() method in different list types and see how we can use this method to change the background color of a ListTile in a flutter application.
00:00 - Introduction
00:23 - Example one: forEach method explanation on a list of String
01:55 - Example two: forEach method on list of integer
02:64 - Example three: forEach method on list of object
03:53 - Overview over the boilerplate code
05:20 - forEach method in onPressed method
06:25 - Outro
⭐️⭐️Helpful Ressources ⭐️⭐️
DartPad: dartpad.dev/1f6d7019fb38072d3...
GitHub Repository: github.com/mt-tadayon/foreach...
Tools we use to grow our TH-cam channel
TubeBuddy Review - Manage Your TH-cam Channel Easily
www.tubebuddy.com/flutterexpl...
Our current TH-cam gear
🎙 Samson Mic: amzn.to/324Gpof
📟 Satechi USB-C Adapter: amzn.to/3kUdQ5M
💻 MacBook Pro: amzn.to/3iQ9MBx
📹 Lumix FZ1000: amzn.to/3g7tW8D
⭐️⭐️Follow us ⭐️⭐️
Twitter Mahtab - / mahtab_dev
GitHub Mahtab - github.com/mt-tadayon
Twitter Max - / flutter_exp
Github Max - github.com/md-weber
Homepage - myracledesign.de/blog
⭐️⭐️ Support ⭐️⭐️
If you read this so far, thank you once more. If you like to support us, here are some links that could help us a lot.
Donation via Streamlabs - You are free to donate us a small amount, so we can keep up our work.
flutterexplained.live/
Amazon Affiliate Link - You buy for the same price and I get a small amount of it. This leads to an amazing Flutter book that I can recommend to every beginner of flutter amzn.to/2uOJXON
From someone who has very little experience of flutter and dart I just wanted to leave a comment here saying this was really helpful for me. You explained everything in details (including how to iterate in dart and what arguments it take) and went over everything step by step which is a 100x times better than someone going over some code snippets. Please do keep up making videos like this 😊
This is one of the best Dart lessons, there are many teachers, but few can explain complex stuff in an easy way.
This Kind of teaching is really great! Please keep them creating videos like this ❤
very concise. Thanks. I'm a little confused with the randomized color. Didn't know that hex code is a type of int.
Mind blowing tutorial and explaining the method is tremendous. I think you are the best i fouund for explaining in such a simple and a nice way. Please create a series on Other more and more subject and also if possible please make a series on Flutter APP to connect with a SQL data base by creating our own Rest API. Thank you very very much for providing such a nice tutorial videos.
everyone can be a coder but it's difficult to be a teacher! GREAT VIDEO
Thank you :)
++💯
Best and simple explanation
Glad you think so!
thank you so much 🥺
Thank you.
List method... clear 👍
👍
Muito bom!
Good a query if What is inside the forEach is a nested class as it would work to display the data
Hi , Thank you very much ,that was helpful . Could you please make something like that about Stream methods as well ?
Hello Superturisto and thanks a lot for your feedback. This is an amazing idea, we will definitely consider it and will create tutorials for them. :)
Hello! Thank you so much for this video! Only one doubt remains: When we call the forEach method, we put a word into the parenthesis, as you did on minute 1:31 with the word "name". My doubt is: Is this word alleatory? Can we choose whatever we want? Thanks so much!
Great that you liked our video :). The'name' in that case is a parameter inside the foreach callback. The idea is to name the parameter whatever you like but the list we are iterating over is called 'names'. Therefore it makes sense to call the element inside 'name'. I hope that helps and make sense!
@@FlutterExplained Make sense! Thank you very much
how to removed duplicates using forEach from a list
What is the difference between map and for each ?
While map creates a new array with the results of calling a provided function on every element in the calling array. forEach executes a provided function once for each array element.
If you have a List of integers and want a list of strings you would use map. If you want to print every element in a List you would use forEach.
how'd I add new data to the list?
The easiest way to add a new element to a list is by using the add function. api.dart.dev/stable/2.8.4/dart-core/List/add.html
An example can be found here: github.com/mt-tadayon/fold_tutorial/blob/61f1de522470892a7cc22ccd57551fb10caa6a02/lib/dashboard.dart#L66
@@FlutterExplained that's a very quick reply and thank you, I was instantly able to fix my issues..
That is fantastic to hear, glad that I could help :)
line 46
friend.color = (Random().nextDouble() * 0xFFFFFFFF).toInt();
same shuffle method? or no?