Dart extension methods

Поделиться
HTML-код
  • Опубликовано: 30 июл 2024
  • Dart is adding a new feature called Extension Methods. It's one of the features that you can live without, but it does make some things very convenient. Learn more now!
    Overview → goo.gle/2PJunfp
    A more indepth article → goo.gle/2sNgfsj
    Some code samples → goo.gle/36VhZyr
    Learn everything about Flutter at → flutter.dev
    Subscribe! → goo.gle/FlutterYT
    #dart #darttopic

Комментарии • 118

  • @raffaelenicolapiazzolla3927
    @raffaelenicolapiazzolla3927 4 года назад +70

    I didn't use to program, but i used to watch Flutter and dart videos just because they're funny🤣. Now I know dart and I use Flutter every day. Thanks!

  • @CodeWithAndrea
    @CodeWithAndrea 4 года назад +62

    Haha. I made a video about Dart extensions a few weeks ago and also said “with great power comes great responsibility” 😀
    Very well explained!

    • @yousifsma8855
      @yousifsma8855 4 года назад +2

      Your videos are great

    • @ajbe6393
      @ajbe6393 2 года назад +1

      Love your video tutorials!

  • @dilshan3372
    @dilshan3372 3 года назад +8

    Flutter :- We have a widget for that.
    Dart :- We have a method for that.

  • @isurujn
    @isurujn 2 года назад +3

    Coming from Swift-land, I'm glad Dart has extension methods. They're one of my favorite language features.

    • @flutterdev
      @flutterdev  2 года назад +2

      Hey there, Isuru! Thanks so much for your feedback. It's great to see users so excited about new features!
      Don't forget to check out this article for more on Dart Extension Methods! → goo.gle/2sNgfsj

  • @yanlimaju
    @yanlimaju 4 года назад +6

    I'm a C# program and Extension Method is one of my favorites features on this language. It's very exciting see this feature in Flutter too. Thank for this guys!

  • @JSANL
    @JSANL 4 года назад +49

    Thanks for the video!
    2:10 was too damn funny

    • @danvilela
      @danvilela 4 года назад

      JSAN L. Hahah filip is the best!

  • @dmitriyobidin6049
    @dmitriyobidin6049 4 года назад +12

    If at some point in your career you had created atleast one StringUtil class, you'll definitely love extension methods :)

  • @mehmetedex
    @mehmetedex 4 года назад +4

    I've been in and out of top 20 programming languages & never had this much fun
    thank you flutter team

  • @communityband1
    @communityband1 4 года назад +17

    This functionality should be useful. I hope that Dart doesn't go too much down the C# path, though, in the sense of adding tons of features that make the language less approachable. Often when a language is made more efficient for its experienced users, it becomes more intimidating and less readable for newcomers.

  • @_Aarius_
    @_Aarius_ 4 года назад +1

    Thats pretty cool.
    and the 'principle of least astonishment' you mentioned is one of the main reasons I love dart...everything seems to work more or less as i expect it to.

  • @verryondrums
    @verryondrums 4 года назад +3

    Awesome video, thanks for sharing 😊! This funny, authentic, well prepared and informative videos are part of the future success of flutter and dart. Keep it going 🙏

  • @tr3umphant.designs632
    @tr3umphant.designs632 4 года назад +1

    I remember using extensions in Swift and thought it was the coolest feature ever. So glad it's being used in Dart as well!

  • @julian_pp
    @julian_pp 4 года назад +2

    I'm trying to learn flutter, and must say it's the coolest framework, so fun! Thank you for your work dev team👌😉

  • @rebarius
    @rebarius 4 года назад +10

    Just what I was searching for! No need to fork repos anymore 😂

    • @mosthated1775
      @mosthated1775 4 года назад

      Right? That is exactly what brought me here. I have like 5-6 repos I forked in this current project with changes and was just thinking how much of a pain it will be down the road trying to maintain.

  • @amauridossantosalves2672
    @amauridossantosalves2672 4 года назад +2

    I really liked the 2:10 minute, when the “revelation” was showed out! 😁

  • @AdnanAli-xy9zg
    @AdnanAli-xy9zg 4 года назад

    That’s Awesome
    Really happy to see Extension methods

  • @superslayerguy
    @superslayerguy 4 года назад +1

    VERY GOOD NEWS!. extensions were very useful to me when I was writing Swift, can't wait to use them in my new favorite language :)

  • @alessandroautiero5414
    @alessandroautiero5414 4 года назад +1

    This is sick, in Java I have been waiting for this forever

  • @alejosandu
    @alejosandu 4 года назад

    this remembers me about prototypes in javascript, very useful!!

  • @bartekpacia
    @bartekpacia 4 года назад

    Awesome tutorial, fun and informative, thanks!

  • @FethiEd
    @FethiEd 2 года назад

    Very well explained! Thanks

  • @MindThePoliticalGap
    @MindThePoliticalGap 4 года назад

    Fantastic!!! this is just what I needed!

  • @gjlmotea
    @gjlmotea 5 месяцев назад

    fantastic features! 💯
    I love the emoji at 2:10 ha

  • @milasmarko
    @milasmarko 4 года назад

    This is amazing, thank you guys :D

  • @gosoccerboy5
    @gosoccerboy5 3 года назад

    Woah, this is awesome! This will probably save a bit of work :)

  • @desther
    @desther 4 года назад

    Seems pretty powerful. Nice feature.

  • @hasansalim1868
    @hasansalim1868 Год назад

    Brilliant. Very useful feature.

  • @SEGVeenstra
    @SEGVeenstra 4 года назад +2

    The Flutter videos should be a series on Netflix, they're so entertaining!
    Can't wait for the movie.

  • @sayyidj6406
    @sayyidj6406 10 месяцев назад

    i am not even a programmer, never in any school or university, but hooly ss, its so easy to coding because of dart language. iam even got score in stackoverflow answer bounty question about flutter, aroud 1k just answer people question, and its fun, and i am proud of it(because iam newbie). i do it for hobby, right know i get my first serious project since 2018(my first lang is java btw). :D. thanks flutter team

  • @sawyerandjackfucking
    @sawyerandjackfucking 4 года назад

    It's beautiful to be able to add a 'hasValue' or 'hasNonEmptyValue' method to strings. Saves a ton of null and empty checking.

  • @blank-vw2sb
    @blank-vw2sb 4 года назад

    Who doesn't wants to learn more features? Everybody loves it

  • @kahanx10
    @kahanx10 2 года назад

    Hey beautiful Flutter team, I hope that one day, Flutter's website will have an official 'Google Certified Flutter Developer' exam facility. It's really impressive to witness such a growth of a framework.

  • @blablablabla29382
    @blablablabla29382 4 года назад

    Gonna be fun ! Translation, serialisation, converter waouh :) !

  • @alex_moreno
    @alex_moreno 4 года назад

    Dart and flutter are amazing!

  • @pjpac7555
    @pjpac7555 10 месяцев назад

    Very nice.
    Still, a short section around 2'52'' caught my attention when it referred to
    ' verb(object) vs object.verb '
    I've been unsuccessfully looking for information about it for a while as there is something there that keeps bothering me. Would anyone have any suggestion of material to check on this topic ?
    Cheers

  • @tamiladdiction
    @tamiladdiction 4 года назад

    Hi i have a question here i have windows dll for to collect the meter reading from meter using optical probe flutter support windows dll ? please answer

  • @RahulRaj-fv7ki
    @RahulRaj-fv7ki 4 года назад

    Awesome. Next we want 'Trailing closures'

  • @danvilela
    @danvilela 4 года назад

    WOW!!! This will be awesome for generated code!!!

  • @grigolsirbiladze1872
    @grigolsirbiladze1872 4 года назад

    Awesome feature

  • @midhunrajr372
    @midhunrajr372 3 года назад

    You can also extend enum classes right? explaining that also would be nice.

  • @89stoev
    @89stoev 4 года назад

    Guys i have a question. If i intend to build an app thats private and not Open Sourced with a sublicense, can i do that with Flutter as its licensed under BSD-3 license ?

  • @saibotblack
    @saibotblack 4 года назад

    absolutely great, i love it. :-)

  • @weizhixie9678
    @weizhixie9678 4 года назад

    Wow, EXTENSION rocks!

  • @abuyusufsherakhmatov
    @abuyusufsherakhmatov 2 года назад

    Thanks :)

  • @JacquesFernandes
    @JacquesFernandes 4 года назад +2

    I'm going to ask a silly question.
    I get the whole "with great power, comes great responsibility" bit, but what's to stop someone from adding that "scream" method (although, more insidious things could be done)?
    It feels like this might just be something extra for codebase maintainers to look out for when merging pull requests, no?

    • @filiphracek
      @filiphracek 4 года назад +2

      You're right. If, for example, person A silently adds the scream() method to String in their popular package P, and other people import that file , then they'll have .scream() on every string. But! You can't "override" with extension methods - so people would also have to actively call .scream() for this to have effect. Extension methods aren't actually added to the class, so it wouldn't even have performance implications.

  • @benmarcus3044
    @benmarcus3044 4 года назад

    but what happens if the extensions method is already used in the parent class?
    does the extension override??
    anyone?
    thanks!!

  • @geoffreylee1780
    @geoffreylee1780 4 года назад +1

    5:14 is the source_gen lib already implement with extension? I cant find the official documentation about it anywhere

    • @Charlie-zd2dr
      @Charlie-zd2dr 4 года назад

      As far as I can recall you need to include in your yaml file build_runner and do build run script in the console and it will generate that.

  • @loganrussell48
    @loganrussell48 4 года назад

    Can the extension methods be shown in a stylized portion of the source file that was extended, inside IDEs? Sometimes when I'm thinking about how to solve some issue I just browse around the source files, see what my options are, and go from there(because sometimes documentation is lacking, and I wasn't the original author of the code). If some of the methods are already created elsewhere (via extensions) I might end up re-writiting an already created method. If the extension methods could be superimposed into the original source file (while still being clear that these are extensions and not actually part of the original source) that would be super helpful.
    For example: in a Pizza Delivery App, I might not think to look in the FAQ.dart class for the bestBy(Pizza p) method that tells me for how long a pizza is safe to eat. I would want to see the definition in the Pizza.dart file, and, ideally, be able to Ctrl+click(as I do in IntelliJ) on the method name to take me to the file with the actual code definition so I can modify it, if needed, or just review the implementation of that particular extension.

  • @pameng5235
    @pameng5235 4 года назад

    salamun aleykum. can the app run on ios android if i use flutter as front end and python as back end?

  • @tonycasillacoaquira4231
    @tonycasillacoaquira4231 9 дней назад

    I understood the "Jujustu Kaisen" reference

  • @heshansandeepa9471
    @heshansandeepa9471 2 года назад +1

    very nice

  • @SAPierce2006
    @SAPierce2006 4 года назад +1

    Adding extension methods is great, but not adding extension lambda parameters so that Flutter DSLs can be created is a big missed opportunity. The syntax chosen isn't flexible enough that it can be used to add this feature later.
    For those who don't know what a DSL is, it's a way to create structured strongly typed type hierarchies. They are VERY popular in Kotlin, Scala, Groovy, and a few other modern languages. The most obvious use case is getting rid of Flutters widget creation Constructor hell, and replacing it with a proper DSL. This would be so much better than what's currently there.

  • @remoteportal
    @remoteportal 4 года назад +1

    Okay, let's face it--dart is becoming AWESOME! It's now my favorite language.

  • @alexandrumunteann
    @alexandrumunteann 4 года назад

    Awesome!

  • @blank-vw2sb
    @blank-vw2sb 4 года назад

    COOL
    Can I override a function using extension function?

  • @blank-vw2sb
    @blank-vw2sb 4 года назад

    Dart ROCKS!!!

  • @king4053
    @king4053 3 года назад +1

    I'm unable to understand this 5:20
    How fromJson can be called?
    1. Planet.fromJson(json)
    2. Declaring Planet _planet ; then call method _planet.fromJson(json)
    3. Planet(what if there's required parameters here).fromJson(json)
    My current work around is to name the extension and just call the static method.
    Example: PlanetExtension.fromJson(json)
    Not currently possible to add static extension method
    github.com/dart-lang/language/issues/723

  • @user-hh4zq9jj8d
    @user-hh4zq9jj8d 3 года назад

    dart is the future

  • @chetan6406
    @chetan6406 4 года назад +1

    Dart becoming better and better as flutter framework becomes popular......2020 is the time of both dart and flutter.

  • @avi8034
    @avi8034 4 года назад

    Is there any Dart tutorial from the official for beginners?

  • @alizamani5772
    @alizamani5772 4 года назад +1

    I think android studio version 3.5.3 have problem with flutter.
    If it possible make a video tutorial how to fix it

  • @mavvdeus
    @mavvdeus 4 года назад +7

    They are quite similar to the class extensions in Swift, aren't they?

    • @rachmatwahyupramono1811
      @rachmatwahyupramono1811 4 года назад +1

      Pretty much

    • @nadeemshaikh7863
      @nadeemshaikh7863 4 года назад +1

      Looks like the folks at dart will take a lot of stuff from Swift and Kotlin.

    • @zenande699
      @zenande699 4 года назад +1

      Which is a good thing!

    • @ShivamJha00
      @ShivamJha00 4 года назад +2

      And Kotlin as well

    • @communityband1
      @communityband1 4 года назад +1

      @@nadeemshaikh7863 I wouldn't want the task of trying to track down the origin of every feature in any of these languages. :-)

  • @ziedRegaieg
    @ziedRegaieg 4 года назад

    I've been around Android, Firebase and Flutter channels for a while and 2:10 it the first joke attempt that i find actually funny

  • @CarlosCornejoWanoo
    @CarlosCornejoWanoo 4 года назад +12

    Nice, like Kotlin Extensions!

    • @chickenbloodmachine
      @chickenbloodmachine 4 года назад +5

      *cough* like Swift extensions :)

    • @DimiterStanev
      @DimiterStanev 4 года назад +3

      cough, cough... like Objective C extens... categories!

    • @Krokoklemmee
      @Krokoklemmee 4 года назад

      inb4 C# extensions (though the syntax isn't as clean ._.)

  • @broooth
    @broooth 4 года назад +10

    Can I access private members from extensions?

    • @RazvanCristianLung
      @RazvanCristianLung 4 года назад +3

      Awesome question

    • @neociber24
      @neociber24 4 года назад

      Well, are private.
      Maybe with reflection.

    • @woprandi
      @woprandi 4 года назад +1

      That should be easy to check

    • @enriccamarero5601
      @enriccamarero5601 4 года назад +2

      It’s just some syntactic sugar. No super powers involved (although it can improve semantics quite a lot).

  • @NextLevelCode
    @NextLevelCode 4 года назад +1

    2:06 are you sure these aren’t called inception methods?

  • @hexchad765
    @hexchad765 4 года назад

    I like long time.
    Facade is good too

  • @TianmenDream
    @TianmenDream 3 года назад

    Is the code anywhere I can find?

  • @datvuong7420
    @datvuong7420 3 месяца назад

    I don't understand the part "Source generation" 4:48

  • @Stranepjeme
    @Stranepjeme Год назад

    How to make extension Global?

  • @tapaswisatyapanthi9075
    @tapaswisatyapanthi9075 4 года назад

    Just like swift ! 😉

  • @efreibe
    @efreibe 4 года назад +2

    Nice, but AFAIK classes cannot be extended with static methods using this approach. (As shown in the video)

    • @marcovoetberg6618
      @marcovoetberg6618 4 года назад

      You are right and I am extremely disappointed!
      I came to this video by a google search because I was wondering if I could use extension methods together with code generation. I was really happy when he mentioned exactly what I had in mind... And then to find out it is a lie. That yes, you can declare a static extension method, but no it isn't applied to the class being extended.

  • @manishdhruw5237
    @manishdhruw5237 3 года назад

    2:32 font name ?

  • @lolicon1416
    @lolicon1416 4 года назад

    Already use it last month
    , I think it's a little bit late for the video

  • @sla0x00
    @sla0x00 4 года назад +1

    2:10 🤣👍

  • @Jashaswee
    @Jashaswee 3 года назад

    Just came from Kotlin and this is so much simpler

  • @LeagueRandomPlayer
    @LeagueRandomPlayer 4 года назад

    2:11 hahahahha here you have your like mr.

  • @Kooshad1
    @Kooshad1 3 года назад

    I wish vs code would be able to automatically import ext files..

  • @user-py7sq5yb9z
    @user-py7sq5yb9z 4 года назад

    The same thing as in Swift.

  • @hepin1989
    @hepin1989 4 года назад

    Scala has too:) kotlin has too:) how about make type variance syntax go with `+T` and `-T`

  • @yuanli3524
    @yuanli3524 4 года назад

    So, why do not use kotlin?

  • @diego.coder26
    @diego.coder26 4 года назад

    Name font in editor ?

    • @filiphracek
      @filiphracek 4 года назад +1

      It's Input. My favorite.

  • @prabinlamsal74
    @prabinlamsal74 Месяц назад

    gold

  • @ghost_7701
    @ghost_7701 Год назад

    why not use Mixin !

  • @enriccamarero5601
    @enriccamarero5601 4 года назад +1

    Love that! Now that’s all said and done, migrate Flutter to Kotlin ❤️

  • @ymi_yugy3133
    @ymi_yugy3133 4 года назад +1

    I think this is a really awesome addition. I think I will use it to clean up my widget tree in flutter.
    Quite often when you read the tree, you will encounter lot's of clutter like Center, SizedBox, Padding, etc. I think MeaningfulWidget(...).padding() is much more readable than Padding(
    child: MeaningfulWidget(...)
    ),

  • @AggieNC
    @AggieNC 4 года назад

    Why is this in the Flutter channel instead of...you know...a channel for the Dart language?

  • @remoteportal
    @remoteportal 4 года назад

    Someone needs to update: en.wikipedia.org/wiki/Extension_method and add dart.

  • @alexandrromanishin9906
    @alexandrromanishin9906 4 года назад

    Hmm. This implementation of extension methods is better than kotlin's. 🧐I like it.
    The first thing of dart, which is better than in Kotlin 😁

  • @007Mirodil
    @007Mirodil 4 года назад

    It is supper, but the flutter itself failing to support this kind of methods

  • @Zhuinden
    @Zhuinden 4 года назад

    ruclips.net/video/D3j0OSfT9ZI/видео.html BRAAAAAP

  • @grainfrizz
    @grainfrizz 4 года назад

    I feel bad for C#. It has all the best convenience like these for years now but because of its closeness, it hasn't really been embraced by the community the way it deserves to be.

    • @aaronhoush7184
      @aaronhoush7184 4 года назад +1

      closeness? .Net core has been open source for over 4 years, and is one of the most used enterprise languages to date. I don't think C# is having a problem of not being embraced :P

    • @grainfrizz
      @grainfrizz 4 года назад

      @@aaronhoush7184 ikr. Like the staggering number of nix based softwares written on C# out there. I can't even choose which one to consume