ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

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

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ส.ค. 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/FlutterW...
    Stay tuned and subscribe for latest releases → bit.ly/googledevs

ความคิดเห็น • 125

  • @arreankit
    @arreankit 4 ปีที่แล้ว +161

    I want this level of calmness in my life.

    • @ToshaKhan
      @ToshaKhan หลายเดือนก่อน

      Yeah he seems to get the concepts 🙌

  • @MarkDechamps
    @MarkDechamps 5 ปีที่แล้ว +118

    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 :) ?

  • @danvilela
    @danvilela 5 ปีที่แล้ว +123

    😂😂😂 this guy is awesome

  • @CodeXdev
    @CodeXdev 4 ปีที่แล้ว +13

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

  • @clever_dude
    @clever_dude 5 ปีที่แล้ว +106

    Thumbs up for Example :)

    • @dire_vin
      @dire_vin 4 ปีที่แล้ว +1

      Thumbs up into the big nose !

  • @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.

  • @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.

  • @heshansandeepa9471
    @heshansandeepa9471 ปีที่แล้ว +1

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

  • @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

  • @seccat
    @seccat 5 ปีที่แล้ว +19

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

    • @ToshaKhan
      @ToshaKhan หลายเดือนก่อน

      that's a private function()

  • @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;

  • @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.

  • @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.

  • @alexandreaugustolg
    @alexandreaugustolg ปีที่แล้ว

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

  • @ShubhamDukare-ky8qv
    @ShubhamDukare-ky8qv 3 หลายเดือนก่อน

    great explaination

  • @rika9317
    @rika9317 2 ปีที่แล้ว

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

  • @adamjonsson2176
    @adamjonsson2176 5 ปีที่แล้ว +4

    Hahah, love the sound effects!

  • @erdemsym
    @erdemsym 3 ปีที่แล้ว

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

  • @mastercheetos4422
    @mastercheetos4422 5 ปีที่แล้ว +2

    pls make a video about context

  • @Wissperwind
    @Wissperwind 3 ปีที่แล้ว +1

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

  • @jagdishshetty4782
    @jagdishshetty4782 5 ปีที่แล้ว +1

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

  • @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.

  • @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.

  • @bukunmialuko
    @bukunmialuko 4 ปีที่แล้ว

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

  • @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 → th-cam.com/play/PLjxrf2q8roU23XGwz3Km7sQZFTdB996iG.html

  • @grazinascito9251
    @grazinascito9251 3 หลายเดือนก่อน

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

  • @tinatahmasebi3422
    @tinatahmasebi3422 2 ปีที่แล้ว +1

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

  • @pvarela
    @pvarela 4 ปีที่แล้ว +2

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

  • @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

  • @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;

  • @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

  • @JobinJacobKavalam
    @JobinJacobKavalam 3 ปีที่แล้ว

    Awesome and hilarious ! Great video.

  • @danilyusupov5364
    @danilyusupov5364 4 ปีที่แล้ว

    Nice guy! Thanks for explanation, was really helpful 👍

  • @mulletman1705
    @mulletman1705 2 ปีที่แล้ว

    Finally a tutorial that KNOWS what it's talking about

  • @emmanuelenya
    @emmanuelenya 5 ปีที่แล้ว

    This guy example is just perfect

  • @pleilleur
    @pleilleur 2 ปีที่แล้ว

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

  • @bhanukharbanda7956
    @bhanukharbanda7956 10 หลายเดือนก่อน

    "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?

  • @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),

  • @vanau91
    @vanau91 5 ปีที่แล้ว

    Thank you, it's awesome!

  • @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)?

  • @kennedymatanda4972
    @kennedymatanda4972 5 ปีที่แล้ว +6

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

  • @fidamuntaseer1989
    @fidamuntaseer1989 4 ปีที่แล้ว

    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.

  • @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!

  • @daniillipatkin8650
    @daniillipatkin8650 5 ปีที่แล้ว

    Amazing series XD

  • @ciapigeon5351
    @ciapigeon5351 4 ปีที่แล้ว

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

  • @penvblockchainz4058
    @penvblockchainz4058 5 ปีที่แล้ว

    Thank you!

  • @levonhakobyan5936
    @levonhakobyan5936 2 ปีที่แล้ว

    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?

  • @moazelsawaf2000
    @moazelsawaf2000 4 ปีที่แล้ว

    Thanks a lot ❤

  • @MuhammadAdil7
    @MuhammadAdil7 5 ปีที่แล้ว

    i liked last part of the video :D

  • @pradeep422
    @pradeep422 5 ปีที่แล้ว +3

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

  • @marceli-wac
    @marceli-wac 2 ปีที่แล้ว

    Quality content

  • @davidmoreno5489
    @davidmoreno5489 5 ปีที่แล้ว

    nice and useful widget

  • @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 😔

  • @avirias
    @avirias 4 ปีที่แล้ว

    Finally I found the right way to move the data.

  • @scalybur
    @scalybur 5 ปีที่แล้ว

    ThankU

  • @dhruvintanna
    @dhruvintanna 2 ปีที่แล้ว

    4:30 Keys

  • @SergioArroyoSailing
    @SergioArroyoSailing 3 ปีที่แล้ว

    clear and fun :)

  • @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

  • @makenasandra
    @makenasandra 4 ปีที่แล้ว

    Funny and informative

  • @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

  • @Itanium21
    @Itanium21 3 ปีที่แล้ว

    0 information about inheritFromWidgetOfExactType being depreciated?

  • @mohamedelmancy7626
    @mohamedelmancy7626 4 ปีที่แล้ว

    useful

  • @mohsinazeemrind
    @mohsinazeemrind 5 ปีที่แล้ว

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

  • @alfredotlacuilo6231
    @alfredotlacuilo6231 5 ปีที่แล้ว

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

  • @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 5 ปีที่แล้ว +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.

  • @user-kh6rp6yx1j
    @user-kh6rp6yx1j 2 หลายเดือนก่อน

    Hi.

  • @flutterwithvitul
    @flutterwithvitul 5 ปีที่แล้ว

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

  • @ehsanhasin8092
    @ehsanhasin8092 ปีที่แล้ว

    🙂

  • @Choffly
    @Choffly 4 ปีที่แล้ว

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

  • @TranLuan89
    @TranLuan89 5 ปีที่แล้ว +1

    helo

  • @gauravsharma1455
    @gauravsharma1455 5 ปีที่แล้ว

    So technically a Provider Consumer Scenario

    • @MedardRebero
      @MedardRebero 5 ปีที่แล้ว

      Yes but with added hierarchy!!

  • @hemaethossain4946
    @hemaethossain4946 5 ปีที่แล้ว

    I love Google and everything concerned to it.

  • @elmeroranchero
    @elmeroranchero 3 ปีที่แล้ว

    what oculd NoseService possibly have xD

  • @davidbubutube
    @davidbubutube 5 ปีที่แล้ว

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

  • @ahmedfathyalex
    @ahmedfathyalex 3 ปีที่แล้ว +1

    Out of date content,please update it or remove it

  • @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).

  • @nurelhuda5684
    @nurelhuda5684 5 ปีที่แล้ว

    hilarious XD

  • @bhavneetsingh5864
    @bhavneetsingh5864 5 ปีที่แล้ว

    I dont know this guy cool nature makes me laugh

  • @maksabrosimenko9991
    @maksabrosimenko9991 ปีที่แล้ว

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

  • @arestechnology6665
    @arestechnology6665 5 ปีที่แล้ว

    😂😂😂😂

  • @user-tk8jw5bx4c
    @user-tk8jw5bx4c 4 หลายเดือนก่อน

    mark

  • @KraasRas
    @KraasRas 3 ปีที่แล้ว

    deprecated I guess :D

  • @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

  • @artemmakohon212
    @artemmakohon212 5 ปีที่แล้ว

    Thank you!