Using Global Keys to get State and Validate Input in Dart's Flutter Framework
What Will I Learn?
- You will learn how to create Global Keys and use them as unique identifies in Flutter
- You will learn how to access the state of a block of Widgets from outside of the Widgets
- You will learn how to validate and save the state of widgets inside of a Form Widget
Requirements
- IDEA intellij or Visual Studio Code with the Dart/Flutter Plugins
- The Dart SDK and the Flutter SDK
- A fair understanding of Mobile development and Imperative or Object Oriented Programming
Difficulty
- Intermediate
Description
In this tutorial, we build out a simple Form Application using Flutter. In this form application, we have three different input boxes, one for an username, one for an email and one for a password. We preform rudimentary validation checks on each of these input boxes and when those validation conditions are met, the user interface changes to show that the user has logged in. Rather then using a database, we make use of global variables to pass around the state of the forms.
We use the GlobalKey Class to access and manipulate the state of our Form and the outer Scaffold Widget. These GlobalKeys allow us to access the unique identifiers that are assigned to our widgets in the Flutter Widget Tree. By gaining access to these Identifiers, we can then change the state and the User interface of these widgets from the outside which allows us to further react to the changes in state that happen in our applications. The GlobalKeys also give us access to the child widgets of these specific widgets in an indirect manner. This way we can proliferate the changes from the top downwards as the state changes.
The source code for this project can be found here
Video Tutorial
Curriculum
- Dart Flutter Cross Platform Chat Application Tutorial
- Building a Multi-Page Application with Dart's Flutter Mobile Framework
- Making Http requests and Using Json in Dart's Flutter Framework
- Building Dynamic Lists with Streams in Dart's Flutter Framework
- Using GridView, Tabs, and Steppers in Dart's Flutter Framework
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Thank you for moderating my content so quickly.
Do you want to hide thumbnail image on your steemit post page? Here is trick that you must know
Hey @tensor I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x