ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก
Flutter Tutorial - Flutter Keys & Global Key
ฝัง
- เผยแพร่เมื่อ 12 ส.ค. 2024
- With Flutter Keys & the Flutter Global Key, you can access the state of Stateful Widgets in Flutter. The main Flutter Keys are GlobalKey, ValueKey, UniqueKey, & ObjectKey.
Click here to Subscribe to Johannes Milke: th-cam.com/users/JohannesMilke...
👉 12 Week Flutter Training | heyflutter.com
👉 Flutter Masterclass Courses | heyflutter.com/masterclass
Source Code | github.com/JohannesMilke/key_...
My Courses | heyflutter.com
Follow Newsletter | johannesmilke.com/newsletter
SUBSCRIBE HERE
bit.ly/JohannesMilke
SUPPORT & SPONSOR ME
github.com/sponsors/JohannesM...
RESOURCES
UniqueKey Tutorial: • Flutter Tutorial - Flu...
ValueKey Tutorial: • Flutter Tutorial - Flu...
Null Safety Tutorial: • Flutter Tutorial - Nul...
Migrate App To Null Safety Tutorial: • Flutter Tutorial - Mig...
Native Splash Screen Tutorial: • Flutter Tutorial - Nat...
Create Flutter Project For App Stores Tutorial: • Flutter Tutorial - Cre...
QR Code Scanner App Tutorial: • Flutter Tutorial - QR ...
Barcode Scanner App Tutorial: • Flutter Tutorial - Bar...
Onboarding UI Screen Tutorial: • Flutter Tutorial - Onb...
Date Picker & Time Picker Tutorial: • Flutter Tutorial - Dat...
Face ID - Local Auth Tutorial: • Flutter Tutorial - Fac...
Fingerprint - Local Auth Tutorial: • Flutter Tutorial - Fin...
App Internationalization Tutorial: • Flutter Tutorial - Loc...
TIMELINE
0:00 Introduction Flutter Global Key
0:34 Setup Global Key
2:06 Access State Of Stateful Widget
4:17 Global Key For Forms & Validation
SHARE | SUBSCRIBE | LIKE FOR MORE VIDEOS LIKE THIS
*********
SOCIAL MEDIA: Follow Us :-)
Twitter | / heyflutter_
Linkedin | / heyflutter
LEARN MORE
SOURCE CODE | github.com/JohannesMilke
ARTICLES | / johannesmilke
PLAYLISTS
All Flutter Videos | • Flutter Tutorial - Flu...
Widgets - Flutter | • Flutter Tutorial - Flu...
Plugins - Flutter | • Flutter Tutorial - Flu...
Animations - Flutter | • Flutter Tutorial - Tra...
Designs - Flutter | • Flutter Tutorial - Flu...
Firebase - Flutter | • Flutter Tutorial - Pag...
State Management - Flutter | • Flutter Tutorial - Riv...
CREDITS
Copyright song "Corporate Technology" by scottholmesmusic.com
#Flutter #Tutorial #JohannesMilke
LIKE & SHARE & ACTIVATE THE BELL
Thanks For Watching :-)
bit.ly/JohannesMilke
This might help you :)
👉 12 Week Flutter Training from Newbie to Expert: heyflutter.com
Source Code: github.com/JohannesMilke/key_global_example
UniqueKey Tutorial: th-cam.com/video/WhnB_5yjyWQ/w-d-xo.html
ValueKey Tutorial: th-cam.com/video/-F_5yHm_Zso/w-d-xo.html
Null Safety Tutorial: th-cam.com/video/Q_WloMNKOkU/w-d-xo.html
Migrate App To Null Safety Tutorial: th-cam.com/video/GLnQphHi1BY/w-d-xo.html
Native Splash Screen Tutorial: th-cam.com/video/8ME8Czqc-Oc/w-d-xo.html
Create Flutter Project For App Stores Tutorial: th-cam.com/video/4f1AO-f-jYQ/w-d-xo.html
QR Code Scanner App Tutorial: th-cam.com/video/Z32WsUiOegs/w-d-xo.html
Barcode Scanner App Tutorial: th-cam.com/video/Ezzx0eIB4WM/w-d-xo.html
Onboarding UI Screen Tutorial: th-cam.com/video/CQlA2p--oEg/w-d-xo.html
Date Picker & Time Picker Tutorial: th-cam.com/video/a_fGsywyL90/w-d-xo.html
Face ID - Local Auth Tutorial: th-cam.com/video/WIkdceaOUns/w-d-xo.html
Fingerprint - Local Auth Tutorial: th-cam.com/video/qTuVurGvdbM/w-d-xo.html
App Internationalization Tutorial: th-cam.com/video/Zw4KoorVxgg/w-d-xo.html
This is way better than the official video. Thanks for the explanation!
Thank you for this tutorial. It helped me a lot!
clear and perfect , thank you :)
Great explanation...
Thank you
thank you so much awesom tutorial:)
Best teacher!!
Prosda Perfecto Teacher. You Are Krasavcik
thank you !!! finally useful!!!
Best video about key
You're the best ........ thanks a lot Milke for this tutorial
You’re most welcome, Yasmeen Abu shaar! 🙂
Awesome👏👍
Man you saved my life ! Thank you ! You have a new follower
Glad I could be of help, Thank you gerson chadi! 😊
love your videos man keep it up
Thank you, Daniel Ekpenyong! 🙂
that's great, @Johannes Milke ...
Thanks🙏🙏
Thank you. I found out how a parent widget can call methods in it's child's state.
Thanks you sir
Thanks
Thanks.
Great Explanation...Thank you
@@HeyFlutter Have you create video on other type of keys in flutter like : unique key, Value key etc.?
So clear when you explain :) You should have been my math teacher when i was young :))
I returned today on the Global Key series. These kind of specialized tutos are very usefull compared to so many basic Dart tutos that you can find on the internet. A lot of people are trying to find advanced tutos on Dart but the majority of them are so Basic compared to these kind of tuto
Awesome, thanks a lot, Arnaud! 🙂 Yeah, I try my best so that people don't say the same about Flutter in the future 😉
Can you pls explain how to create multiple enddrawer in a single same page with different content
one question brother my local app notification(not the firebase but native) is not working when app is terminated what to do(i already watched your old videos)? can you please make video on that?
and also make video on native ad which uses the latest package from google ad, old one is deprecated and i lost where the part to write native code inside manifest file there is some errors regarding package and also note that i also used fluuter_native_ads package but due to new firebase firestore package i got error while building i will be very thankful if you help me out, btw love your content
I am receiving GlobalKey current state null ?? I have tried for variable and function both but getting null value.
Great and clear content as always
@@HeyFlutter it worked :D thanks for the explanation and quick answer :) you are the best
Thanks, Njm! 🙂 Sure good question, first of all you need to check if you can access the state of your GlobalKey by checking if keyCounter.currentState != null. Only if the currentState exists then you could access the state & logic of your StatefulWidget with the help of your GlobalKey. Check out the example below where we display the counter within the AppBar Title:
import 'package:flutter/material.dart';
class BasicKeyPage extends StatefulWidget {
@override
_BasicKeyPageState createState() => _BasicKeyPageState();
}
class _BasicKeyPageState extends State {
final keyCounter = GlobalKey();
@override
Widget build(BuildContext context) {
final counter = keyCounter.currentState == null
? '0'
: keyCounter.currentState!.counter;
return Scaffold(
appBar: AppBar(
title: Text('My Counter: $counter'),
centerTitle: true,
),
body: Center(
child: CounterWidget(key: keyCounter),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => setState(() => keyCounter.currentState!.increment()),
),
);
}
}
class CounterWidget extends StatefulWidget {
const CounterWidget({Key? key}) : super(key: key);
@override
_CounterWidgetState createState() => _CounterWidgetState();
}
class _CounterWidgetState extends State {
int counter = 0;
void increment() => setState(() => counter += 5);
@override
Widget build(BuildContext context) => Text(
'Counter: $counter',
style: TextStyle(fontSize: 32),
);
}
thanks for it I prefer to read the subtitles though.
Nice
Thank you, blacky arinova! 🙂
Why not use provider?
Which key we have to use with Stateless Widget
Thank You @piyushbhatnagar4735! Follow this link: stackoverflow.com/questions/50080860/what-are-keys-in-the-stateless-widgets-class
I hope you will get your answer 🙂
And what happen with the explanation of the plain keys (not the global)? :s
How do I dispose a TextFormField correctly with this global Form and can I (or should I ) dispose the Global Form Key too if so then how
Thank You Cong Toan Nguyen! Follow this link: stackoverflow.com/questions/68095494/why-did-if-statement-dispose-textformfield-in-flutter
I hope you will get your answer 🙂
How to make the height of the cursor same with the height of text in UITextField?
@@HeyFlutter i know but i have many doubts, so i comment on ur latest video so that u give me attantion.
Thanks, Mart! 🙂 This seems to be unrelated to the concept of Global Keys. Learn more about TextFields here: th-cam.com/video/C5hJIKCTrvk/w-d-xo.html
Hi, How to access GlobalKey to another flutter page / file? another people asked this 6 months ago and you give a very outdated way. please tell me properly I really need this thank you.
@@HeyFlutter this does not work sir, this is a different topic
I dont understand why we use keys. In this example we used the key to access the methods and variables. But this is also possible with Classname.variable isnt it ?
@@HeyFlutter Thank you. Now i understand. Great Video!
Thanks, The Ghost! 🙂 The first example was only a very simple demonstration to showcase how Global Keys work, however, you are right this should not be used in your apps because you could also pass the counter variable directly down from the parent to the child widget without using GlobalKeys. The second example at 4:17 is a real example that makes more sense to use since the widget is from the Flutter SDK and we have no direct control over it however with the help of Global Keys we can access this external widget - its state and also its logic.
Global Keys should be mainly used to access logic & state of EXTERNAL Source Codes such as packages & the Flutter SDK, as demonstrated at 4:17. If you write your own widgets prefer to use StatelessWidgets & write your logic with a State Management, then you don't need to care about Global Keys anymore. Check also my tutorials out about State Management here:
1. Riverpod Basics Providers Tutorial: th-cam.com/video/8H3bwxxla4Y/w-d-xo.html
2. Riverpod Basics Notifiers Tutorial: th-cam.com/video/vD-I1ARIMnk/w-d-xo.html
3. Riverpod Basics Modifiers Tutorial: th-cam.com/video/7h2BrtK8Bpg/w-d-xo.html
4. Riverpod & Calculator UI Tutorial: th-cam.com/video/6isW26d9TiE/w-d-xo.html
5. Provider Tutorial: th-cam.com/video/cltCpXY60Sk/w-d-xo.html
6. Provider & Firebase Tutorial: th-cam.com/video/EV2DyrKOqrY/w-d-xo.html
in my projet i have this error:
Looking up a deactivated widget's ancestor is unsafe.
I try to folloz your course but i have a error like:
"'dynamic' doesn't conform to the bound 'State' of the type parameter 'T'.
Try using a type that is or is a subclass of 'State'."
and
"The name '_SalerListViewAnnounceWidgetState' isn't a type so it can't be used as a type argument.
Try correcting the name to an existing type, or defining a type named '_SalerListViewAnnounceWidgetState'."
Thank you, e.NONO! 🙂 Make sure wherever you are using navigator.pop() must have atleast one screen availabe on stack
Hi Milke,
How do I access the global key defined in a different dart file?
@@HeyFlutter Excellent tutorial, Johannes! If you know any (recent) solution using GlobalKey, pls share... I don't know why, but some old codes don't work anymore, using GlobalKey's inside different files.
Thank you, Robert Mrobo! You could learn more about this problem here : stackoverflow.com/a/29182641
Why r u using keys?
Thanks, Tech1st! 🙂 In this video, we were focused on Global Keys. With a Global Key, you can access the state of Stateful Widgets. Therefore a Global Key can be useful to access the state & logic of other widgets as demonstrated at 7:32 Especially the Flutter SDK uses this technique to implement some logic within their Stateful Widgets which you can then access over a GlobalKey. All in all, it is mainly used to access the logic of StatefulWidgets that were created for you within the Flutter SDK or within other Flutter packages.
if you make the class in different you won't be able to access the key!!