List Method .reduce() in Dart and Flutter
ฝัง
- เผยแพร่เมื่อ 8 ก.ค. 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 the #reduce method in different list types in Dart. Additionally, we will see how we can use this method to calculate the total expenses in a flutter application and show it in a DataTable. Also, we will calculate the rest budget with the fold method in our flutter application.
00:00 - Introduction
00:34 - Example one: reduce method explanation on a list of integer
01:40 - Example two: reduce method on the list of String
02:15 - Example three: reduce method on a list of object
03:20 - Overview over the boilerplate code
04:00 - Tasks explanation
04:22 - Reduce method to calculate the total expenses in the Flutter app
06:00 - Fold method to calculate the rest budget in the Flutter app
07:00 - Outro
⭐️⭐️Helpful Ressources ⭐️⭐️
DartPad: dartpad.dev/ba2544c47094780e0...
GitHub Repository: github.com/mt-tadayon/reduce_...
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 - flutter-explained.org/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 BuyMeACoffee - www.buymeacoffee.com/flutterexp
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
Well done.
You have the best tutorials for flutter and dart! Awesome! Thanks a lot
You are very welcome :) I hope it helps you.
Thanks a lot
Very well done, thank you!
You are most welcome :)
رائع ومبدع لايك كبير
Good job! Clearly explained.
Thanks for your feedback! :)
Thank you very much for your work. Your expression is excellent. I wish you and your loved ones health and happiness.
Thanks a lot for your kind words!
This video is extremely helpful. Thank you
You are most welcome :)
thank q
Please create a series on Map like this list tutorial. Thanks for great explanation.
nicely explained....
Thank you :)
These vids are gold 🥇
Question:
Is there a method to group list\map by value?
i.e grouping the list below by brand...
[Car(brand: 'BMW', color: Red), Car(brand: 'BMW', color: Black), Car(brand: 'Mercedes', color: White)]
I'd go with
myList.map((e) => e.brand).toSet().toList();
If you want to get a list of different brands from myList without repeating the same brands, this is exactly the right solution. And if you want to create a list of all brands, you don't need toSet().
I create a Gist for that and hope it can help you :)
dartpad.dev/f9fcc3cd62b67e7304a7b6a5589f416f
@@FlutterExplained Thanks for the thorough reply you are awesome ❤
I'm sorry but I think my example was misleading.
Let's say I have a shopping list:
[
Cart(date: 19/8/2020, item: shirt, price: 20),
Cart(date: 19/8/2020, item: glasses, price: 10),
Cart(date: 18/8/2020, item: pants, price: 30),
Cart(date: 18/8/2020, item: shirt, price: 15),
Cart(date: 17/8/2020, item: hat, price: 5)
]
My question is how to I group the list by date to get the total cart amount for a single date?
Result:
19/8/2020 > total price: 30 (2 items)
18/8/2020 > total price: 45 (2 items)
17/8/2020 > total price: 5 (1 item)
No worries, it's fine. I create a new DartPad with the solution for you. I hope it can help you. :)
DartPad Link: dartpad.dev/9f6d129ef8b35551575254fb65830cf5
BTW for practicing dart algorithms, I can highly recommend you the exercism. This helped me a lot. exercism.io/my/tracks/dart
hi, I've watched your video th-cam.com/video/wngN0vLYwlw/w-d-xo.html and there is something that I don't understand. I have an assignment for dart that I need to do subtraction. input: 21, 23, 12, 45, 39, 40. I was asked to split the input into a list by using .split() function. how do I do the subtraction for all the inputs in the list? I couldn't find any ways possible yet. thank you! :)