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

Поделиться
HTML-код
  • Опубликовано: 27 ноя 2024
  • НаукаНаука

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

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

    I want this level of calmness in my life.

    • @ToshaKhan
      @ToshaKhan 4 месяца назад

      Yeah he seems to get the concepts 🙌

  • @MarkDechamps
    @MarkDechamps 6 лет назад +119

    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 ;)

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

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

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

      thanks a lot!!!

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

      thanks

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

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

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

      @@impzeropvp yeah.

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

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

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

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

    Thumbs up for Example :)

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

      Thumbs up into the big nose !

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

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

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

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

  • @f13775
    @f13775 4 года назад +9

    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 6 лет назад +123

    😂😂😂 this guy is awesome

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

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

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

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

    • @ToshaKhan
      @ToshaKhan 4 месяца назад

      that's a private function()

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

    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 Год назад +1

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

  • @patrickngnet
    @patrickngnet 6 лет назад +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.

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

    Finally a tutorial that KNOWS what it's talking about

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    This guy example is just perfect

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

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

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

    Hahah, love the sound effects!

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

    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 Год назад

      `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 7 месяцев назад

    great explaination

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

    pls make a video about context

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

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

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

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

      Never mind, I asked ChatGPT.

    • @juanvitor6833
      @juanvitor6833 2 месяца назад

      Declare a final list, now mutate it (add/remove items from it), done.
      You created a list that cannot be reassigned and changed it's content without changing it's reference.

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

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

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

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

    Finally I found the right way to move the data.

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

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

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

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

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

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

    Awesome and hilarious ! Great video.

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

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

    Out of date content,please update it or remove it

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

    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!

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

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

  • @maheshj01
    @maheshj01 5 лет назад +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 5 лет назад +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.

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

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

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

    i liked last part of the video :D

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

    Nice guy! Thanks for explanation, was really helpful 👍

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

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

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

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

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

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

    • @redbrogdon
      @redbrogdon 6 лет назад +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 3 года назад

      @@redbrogdon Broken link 😔

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

    Thanks a lot ❤

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

    Quality content

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

    Amazing series XD

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

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

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

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

    Thank you!

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

    Thank you, it's awesome!

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

    ThankU

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

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

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

    So technically a Provider Consumer Scenario

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

      Yes but with added hierarchy!!

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

    nice and useful widget

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

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

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

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

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

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

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

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

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

    0 information about inheritFromWidgetOfExactType being depreciated?

  • @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 7 месяцев назад

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

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

    clear and fun :)

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

    4:30 Keys

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

    useful

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

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

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

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

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

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

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

    🙂

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

  • @HousseinDroubi-o9i
    @HousseinDroubi-o9i 5 месяцев назад

    Hi.

  • @Trancongluan89
    @Trancongluan89 6 лет назад +1

    helo

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

    what oculd NoseService possibly have xD

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

    I love Google and everything concerned to it.

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

    I dont know this guy cool nature makes me laugh

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

    hilarious XD

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

    😂😂😂😂

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

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

    deprecated I guess :D

  • @高海滨-i9p
    @高海滨-i9p 7 месяцев назад

    mark

  • @Randomdude-i8x
    @Randomdude-i8x 2 года назад

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

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

    Thank you!