A guide to Inherited Widgets - Flutter Widgets 101 Ep. 3

Поделиться
HTML-код
  • Опубликовано: 30 июл 2024
  • In the previous episodes, we have covered stateless widget and stateful widget. In this video Filip Hracek will be introducing inherited widgets, what it is for, how to use it, and some sample cases.
    Watch other episodes in the series → bit.ly/FlutterWidgets101
    Stay tuned and subscribe for latest releases → bit.ly/googledevs
  • НаукаНаука

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

  • @arreankit
    @arreankit 4 года назад +159

    I want this level of calmness in my life.

    • @ToshaKhan
      @ToshaKhan 14 дней назад

      Yeah he seems to get the concepts 🙌

  • @MarkDechamps
    @MarkDechamps 5 лет назад +117

    Just for those who need that little bit of extra information:
    You create the subclass of the InheritedWidget (as explained in the video) and that subclass has a constructor that takes a widget as a child. The idea is to (in the build method of your app) wrap your top widget in there and put your Inheritedwidget on the top. That way the InheritedWidget is very much on the top and accessible by everyone. (I know it is obvious...once you figure it out). Hope this saves someone some time ;)

    • @Imp0ssibleBG
      @Imp0ssibleBG 5 лет назад +1

      Is it like React's context api where you have a Context Provider at the top of your tree?

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

      thanks a lot!!!

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

      thanks

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

      This is crucial. It should've been mentioned in the video. Thanks!

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

      @@Imp0ssibleBG yeah.

  • @f13775
    @f13775 3 года назад +6

    for those who will look this video in 2020 - method context.inheritFromWidgetOfExactType(InheritedNose) is deprecated, use context.dependOnInheritedWidgetOfExactType(),
    ok, google, are you going to update videos about your framework :) ?

  • @ehorlyck
    @ehorlyck 5 лет назад +9

    Fantastic video! I can't imagine how many takes that must have required.

  • @aladdinovich
    @aladdinovich 5 лет назад +3

    I liked the part of service so much, so inspiring with these sounds in background.

  • @CodeXdev
    @CodeXdev 4 года назад +13

    "Interview question". I remember it was one of them. Nicely explained!

  • @jagdishshetty4782
    @jagdishshetty4782 5 лет назад +1

    Great short videos from the flutter team !!! Keep them coming !!!

  • @danvilela
    @danvilela 5 лет назад +123

    😂😂😂 this guy is awesome

  • @clever_dude
    @clever_dude 5 лет назад +106

    Thumbs up for Example :)

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

      Thumbs up into the big nose !

  • @heshansandeepa9471
    @heshansandeepa9471 Год назад +1

    Very nice, this guy is like a Temple. Focused, calm ( not so enthusiastic voice ). I like it :D

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

    Nice guy! Thanks for explanation, was really helpful 👍

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

    Wow! Perfect. Creative and fun example. It always will be kept on my mind. :D

  • @KuroManX
    @KuroManX 2 года назад +6

    After a year of studying flutter I finally understood this concept.

    • @epanna
      @epanna Год назад +2

      I thought only I am these much slow.

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

    Nice. If this man has a youtube channel, im subscribing.

  • @patrickngnet
    @patrickngnet 5 лет назад +1

    When you want to grow up your size of project, you must be annoying of a a lot of different widget dependency. What a good flutter team! has provided a bloc pattern support inside of flutter. You don't need to npm / yarn install something and write a lot of coding (compare with redux). I think bloc pattern is the best solution for handling dependency between widget.

  • @adamjonsson2176
    @adamjonsson2176 5 лет назад +4

    Hahah, love the sound effects!

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

    There's a mistake in the video at 2:35 - the nose object was supposed to be assigned from the asset member of inheritedNose - so the code should read final nose = InheritedNose.of(context).asset;

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

      I think it's not wrong. I guess it changed later.

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

      @@deeprock2 You're wrong and so is the video. At 2:01 the code reads
      final nose = context.inheritFromWidgetOfExactType(InheritedNose).asset;
      so the code at 2:35 should read
      final nose = InheritedNose.of(context).asset;

  • @nonybrighto
    @nonybrighto 5 лет назад +21

    Lol... Good one ! The video is both funny and educational. The sound effect made me laugh 4:06 made me laugh

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

    Haha! I like the nose example very much XD Finally I can understand InheritedWidget by this video, thanks!

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

    Awesome and hilarious ! Great video.

  • @vanau91
    @vanau91 5 лет назад

    Thank you, it's awesome!

  • @daniillipatkin8650
    @daniillipatkin8650 5 лет назад

    Amazing series XD

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

    I think some of the syntax is now outdated; correct me if I'm wrong.
    (I'm using Flutter 2.0.3)

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

    inheritFromWidgetOfExactType is deprecated since v1.12.1, use dependOnInheritedWidgetOfExactType instead.

  • @seccat
    @seccat 5 лет назад +19

    I could pick that widget... but not in public.

    • @ToshaKhan
      @ToshaKhan 14 дней назад

      that's a private function()

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

    Just started looking into flutter. This is good explanation, but the video needs to be updated. Better yet... perhaps link to some sample code in the video notes.

  • @RahimSekkouti
    @RahimSekkouti 11 месяцев назад

    Very informative video! Thanks Flutter Team 🙏
    A quick question, in order to get the asset variable in the build() method:
    final nose = InheritedNose.of(context);
    shouldn't the asset be returned from the of() method such as:
    static InheritedNode of(BuildContext context) =>
    context.inheritFromWidgetFromExactType(InheritedNose).asset;

    • @JulianoPenna
      @JulianoPenna 8 месяцев назад

      `nose` is the object reference, not the `asset` reference.
      If you want the `noseAsset`, that would be:
      final noseAsset = InheritedNose.of(context).asset;

  • @ShubhamDukare-ky8qv
    @ShubhamDukare-ky8qv 3 месяца назад

    great explaination

  • @artemmakohon212
    @artemmakohon212 5 лет назад

    Thank you!

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

    Thank's God, now I got it! Thank's for the explanation!

  • @MuhammadAdil7
    @MuhammadAdil7 5 лет назад

    i liked last part of the video :D

  • @CuiqkOfficial
    @CuiqkOfficial 5 лет назад +1

    At 1:53, I am having error in the line final nose = ... at the word asset.
    However using it InheritedNose.of(context).asset seems to work.
    Edit: I had to use
    (context.inheritFromWidgetOfExactType(InheritedNose) as InheritedNose).asset

    • @filiphracek
      @filiphracek 5 лет назад +3

      Well spotted! Thanks for the correction.
      For additional clarification: most developers will end up using the .of() way, which means they won't encounter the problem shown by Aryan. Because:
      static InheritedNose of(BuildContext context) => context.inheritFromWidgetOfExactType(InheritedNose);
      has the cast implicit in the signature of the static method. After this, InheritedNose.of(context).asset just works.

  • @mastercheetos4422
    @mastercheetos4422 5 лет назад +2

    pls make a video about context

  • @emmanuelenya
    @emmanuelenya 5 лет назад

    This guy example is just perfect

  • @davidmoreno5489
    @davidmoreno5489 5 лет назад

    nice and useful widget

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

    Thanks a lot ❤

  • @oxglowinc.1614
    @oxglowinc.1614 5 лет назад

    informative tutorial on inheritedWidgets. However, which stage can it be used in building an eCommerce app? Kindly give instance. thanks

    • @redbrogdon
      @redbrogdon 5 лет назад +3

      Our shopping sample app uses an InheritedWidget called ScopedModel to hold the shopping cart: github.com/flutter/samples/blob/master/shrine/lib/main.dart. That's one way to approach it.

    • @abhimanyu.n14
      @abhimanyu.n14 2 года назад

      @@redbrogdon Broken link 😔

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

    how do i put the stateless widget up the tree? do i have to?

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

    does final nose = InheritedNose.of(context); really work? Don't we need some .nose?
    InheritedNose.of(context).nose

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

    Hey, we need that cool grey Google Bike T-shirt in the Google Merchandise Store! It's currently not available in all sizes. Please make it available!

  • @scalybur
    @scalybur 5 лет назад

    ThankU

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

    clear and fun :)

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

    Can a child widget (eg: main app) inherit from 2 separate inherited widgets? Like I need one inherited widget for translation and another for navigation. They work fine separately but unable to make them work together... :(

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

      As far as I know flutter (actually dart) doesn't support multiple inheritance.

  • @marceli-wac
    @marceli-wac 2 года назад

    Quality content

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

    This is why we have to know a lot about a trees for the Google Interview.

  • @RobertWildling
    @RobertWildling 5 лет назад +3

    How about putting the "Flutter Widgets 101" into a playlist?

    • @GoogleDevelopers
      @GoogleDevelopers  5 лет назад +2

      Hi Robert! You can find all the Widget of the Week videos in this playlist → ruclips.net/p/PLjxrf2q8roU23XGwz3Km7sQZFTdB996iG

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

    What is the meaning of it ?
    Old school singleton or class with static members will do the same without need of context tree lookup.
    Did I miss something?

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

    This did not cover how to set the Inherited State data! How are you setting NoseService ?

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

      Ah! Never mind... just found out - you create the context as the root of the widget tree. Example: github.com/iampawan/StateExperiments/blob/d98a58df032b56ee72c46145c5e7d2bce5026ab2/lib/main.dart#L37

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

    At 02:00 should be now like this : final nose =
    context.dependOnInheritedWidgetOfExactType().asset;

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

    Finally a tutorial that KNOWS what it's talking about

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

    what if I have a scenario something like this from my first Screen I pass a boolean variable to my second screen in the constructor and when I modify it in my second screen I want it to get updated in my first Screen,How can I achieve this ?

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

      Yes, if you pass a raw boolean variable to the constructor, that doesn't give you any way to update the parent (or any other screen). Changing that variable will just change it in that widget, nothing else.
      You need to wrap the boolean in something called an "observable" -- some class that doesn't only hold the value, but also allows others to "observe" it. The lowest level class that does this in Flutter is called ChangeNotifier (that's what it does: it notifies whoever is listening that some value has changed).
      This is just something inherent to developing in a declarative framework. It's hard to grok at first but then becomes second nature.
      I wrote an introduction to this over here: flutter.dev/docs/development/data-and-backend/state-mgmt/intro. Hope that helps.

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

      @@filiphracek thank you very much I will surely take a look

  • @Imp0ssibleBG
    @Imp0ssibleBG 5 лет назад

    Is this like React's context api where you have a Context Provider at the top of your tree? (I am coming from a web dev background and I am confused)

    • @andrewbrogdon558
      @andrewbrogdon558 5 лет назад +1

      Flutter uses BuildContext (or just "context") to mean the place in the tree where a widget is being placed. If you put a StatelessWidget into a Row, for example, that Row is the context passed into the StatelessWidget's build method. It's used with inherited widget as a way of saying "Start and this point in the tree and go up until you find a widget that matches what I'm looking for."

    • @JohanHartzenberg
      @JohanHartzenberg 5 лет назад

      @@andrewbrogdon558 Why didn't you say THIS in the video!!!!?

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

      @@JohanHartzenberg cuz he wasn't in the video

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

      @@JohanHartzenberg Filip did say something similar

  • @algorithmscodes-9927
    @algorithmscodes-9927 3 года назад

    This means that the method inheritFromWidgetOfExactType is O(n) because it hast to search for the widget of that type, am I right?

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

      Good question!
      Yes and no. It would potentially need to search every ancestor element to find the right widget, so O(n) where n is the height of the tree above the context. However, Flutter is crafty enough to cache the inheritance references, so once the search is done a single time, it's O(1) after that.

    • @algorithmscodes-9927
      @algorithmscodes-9927 3 года назад

      @@andrewbrogdon558 Wow, it‘s nice to know how things work in the background…I can already imagine how the cache process is implemented (probably a dictionary in context),

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

    Finally I found the right way to move the data.

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

    Great explanation but i still confuse on how it works in pratice

  • @mohsinazeemrind
    @mohsinazeemrind 5 лет назад

    its made me laugh when i saw 2:45 and understand whole video :D

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

    Funny and informative

  • @davidbubutube
    @davidbubutube 5 лет назад

    shall I add "wow, Im the first to comment !!!" ? In any case love your videos guys, keep it on.

  • @kennedymatanda4972
    @kennedymatanda4972 5 лет назад +6

    My big Nose!! kikikiki. That made my night. Thanks futter team, you are a Revolution in Mobile dev.

  • @alfredotlacuilo6231
    @alfredotlacuilo6231 5 лет назад

    I cannot get it to work, my inherited widget is always null. Does anyone else have this problem?

  • @flutterwithvitul
    @flutterwithvitul 5 лет назад

    thank you, sir, but can we use like "widget.nose"?

  • @bhanukharbanda7956
    @bhanukharbanda7956 9 месяцев назад

    "The fact that something is 'final' only means it can not be reassigned. It does not mean it can not change internally."
    I don't understand this. Can you elaborate, please?

  • @pradeep422
    @pradeep422 5 лет назад +3

    lol blow and sneeze method calls, this is the most Funniest coding example ever!!!!!!!!

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

    useful

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

    4:04 You can hear elements of the sneezeNose and blowYourNose widgets here 😁

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

    0 information about inheritFromWidgetOfExactType being depreciated?

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

    I am a bit cruious, why not just use providers here? I followed quite a few tutorials, but I was not aware anybody taught this one thought.

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

      providers is just a wrapper around Inherited Widget and Stateful Widget. It saves you, among other things, from writing a lot of boilerplate code

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

    4:30 Keys

  • @gauravsharma1455
    @gauravsharma1455 5 лет назад

    So technically a Provider Consumer Scenario

    • @MedardRebero
      @MedardRebero 5 лет назад

      Yes but with added hierarchy!!

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

    It seems the theory is simple, but writing a complex app with flutter (declarative approach) and handling states can be a little harder than android SDK (imperative approach).

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

    You should not hold a mutable widget inside an InheritedWidget, as InheritedWidget could be recreated and state will be lost.

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

    So if I want to change the contents of the asset I need to add value update methods to the asset class? (For example, when I have a class usersettings.dart and want to distribute that in the app using inheritedwidget)?

  • @vibovitold
    @vibovitold 5 лет назад +3

    While I appreciate the humor, this sort of examples aren't really useful when it comes to programming concepts. It's like teaching OOP with the infamous "cat extends animal" analogies.

    • @neociber24
      @neociber24 5 лет назад +1

      What are you actually waiting for? I think is a perfect example, the same for the "Cat extends Animal" are pretty good examples for explain a concepts or at least were good for me.

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

      I understand your sentiments but I feel that's one problem domain any one could relate to and understand without having to be an expert in any field. If he uses a problem domain that is to specific to a field of study then a lot of people would be lost.

  • @hemaethossain4946
    @hemaethossain4946 5 лет назад

    I love Google and everything concerned to it.

  • @TranLuan89
    @TranLuan89 5 лет назад +1

    helo

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

    hilarious XD

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

    what oculd NoseService possibly have xD

  • @user-kh6rp6yx1j
    @user-kh6rp6yx1j Месяц назад

    Hi.

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

    Out of date content,please update it or remove it

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

    🙂

  • @bhavneetsingh5864
    @bhavneetsingh5864 5 лет назад

    I dont know this guy cool nature makes me laugh

  • @arestechnology6665
    @arestechnology6665 5 лет назад

    😂😂😂😂

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

    Яндекс круче..

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

    deprecated I guess :D

  • @user-tk8jw5bx4c
    @user-tk8jw5bx4c 3 месяца назад

    mark

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

    It is great to speak funny, but it is not that great to use "noseService"? it is too abstract to us... i do not understand

  • @penvblockchainz4058
    @penvblockchainz4058 5 лет назад

    Thank you!