Skip to content
0:00 / 0:00

#flutter#widget#keys

When to Use Keys - Flutter Widgets 101 Ep. 4

Google for Developers

2.6M subscribers • 20 videos on Hallway

YouTube
  • Recommended by 3 people: 2 in engineering communities and 1 on Stack Overflow and its sister sites.
  • A classic. People kept recommending it from 2018 to 2023.
  • Made by the vendor. The company whose product it covers made or sponsored it.
  • May be out of date. Uploaded 7 years ago, in an area where tools change fast.

Intermediate. Assumes working knowledge.

536K views7 years ago3 recommendations

Mobile developmentFlutter and React NativeMobile app architecture

An explanation of when and how to use keys in Flutter to preserve state and control widget rebuilding.

In this episode, you will learn about key parameters on widgets: when you need keys, where to put keys in your widget tree, and which key is right for you. More specifically, you'll learn about he nuances of how keys work, discern when to use keys in your widget hierarchy, and identify the appropriate types of keys to optimize your widget-based structures. Chapters: - Intro - When to use keys - How keys work - Where to put keys - Types of Keys Watch other episodes in the series → bit.ly/FlutterWidgets101 Subscribe to Google for Developers → goo.gle/developers

Why it's here

3 people recommend this

What people say. Recommended as a clear explanation of how Flutter keys work and when to use them to maintain widget state.

Moments people linked to

u/Dazza5000in r/FlutterDev • Recommends

When to Use Keys - Flutter Widgets 101 Ep. 4 (this has stumped me twice now!)

u/Purple_Pizzazzin r/FlutterDev • Recommends

When to Use Keys - Flutter Widgets 101 Ep. 4

mavini.son Stack Overflow • Recommends

On “Flutter - setState not updating inner Stateful Widget”

…a bit late to the discussion, but I think this is important. I was facing a similar problem a while back and I even came to this thread to get some ideas. In my case, I was simply getting widget.value directly inside the build method of the childWidget, and it was not updating when i called setState in the mainWidget. Then i found this video: link to this video (When to Use Keys - Flutter Widgets 101 Ep. 4) - Here the Google dev talks about how keys in Flutter. The short answer is In a StatefulWidget the actual value you pass is stored in the state, not in the widget itself, like a StatelessWidget does. When you call setState in the mainWidget , Flutter walks down the widget tree and checks…

WSBTon Stack Overflow • Mentions

…t if you wanted to show the same widget on two different screens, but holding all the same state, you’d want to use a GlobalKey. Her article includes a gif demo of an app called "Using GlobalKey to ReuseWidget" but does not provide source code (probably because it's too trivial). You can also see a quick video demo here, starting at 8:30 mark: link to this video How do I implement her demo? Where do I define the GlobalKey variable and how/where do I use it? Basically for example, I want to display a counter that counts up every second, and have it on many different screens. Is that s……
52View the answer