Last active
November 30, 2019 14:34
-
-
Save bacalj/7c90560060b6899f22e462106f6ff949 to your computer and use it in GitHub Desktop.
This flutter app from the Google tutorial works but I need to grok it, man
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:english_words/english_words.dart'; | |
| /* entry point to all flutterland is main, I think */ | |
| void main() => runApp(MyApp()); | |
| /* | |
| -- CREATE THE APP INSTANCE AS A UBER-WIDGET -- | |
| subclass StatelessWidget to create an object to hold the app | |
| */ | |
| class MyApp extends StatelessWidget { | |
| /* | |
| this is some dartness where we have to mention we are | |
| overriding members of the object we are inheriting from I guess? | |
| */ | |
| @override | |
| /* | |
| and I guess here we go, | |
| overriding the built-in build method, | |
| returning a widget that is itself an instance | |
| of a MaterialApp object that we configure with an object we pass to it on instantiation | |
| also because unknown Dart and Flutter we bring in the context which I do not know what is, yet | |
| */ | |
| Widget build(BuildContext context){ | |
| return MaterialApp( | |
| title: 'Welcome to Flutter', | |
| home: Scaffold( | |
| appBar: AppBar( | |
| title:Text('Bienvenue to Flutter'), | |
| ), | |
| body: Center( | |
| child: RandomWords(), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| /* | |
| - CREATING CLASS FOR THE STATE - | |
| ok here be dragons | |
| we set up a class for the state itself | |
| that will belong to another object, called RandomWords | |
| which is the so-called stateful widget - but remember, it seems | |
| stateful widget doesn't truly have its own state, it still needs | |
| an object to hold the state, SO we declare the state object and | |
| let it know that it is headed for a life of servitude to the Widget | |
| we will be making (a subclass of StatefulWidget known as | |
| RandomWords -- and functionally | |
| -this object RandomWordsState - | |
| it just returns the state itself | |
| */ | |
| class RandomWordsState extends State<RandomWords> { | |
| @override | |
| Widget build(BuildContext context){ | |
| final wordPair = WordPair.random(); | |
| return Text(wordPair.asPascalCase); | |
| } | |
| } | |
| /* | |
| - CREATING CLASS FOR THE STATEFUL WIDGET THAT HOLDS THE STATE - | |
| and, finally, the widget we mentioned above | |
| we let it know that it is an extension of Stateful Widget | |
| and that is has a member variable or like child object thing | |
| that is the State known as RandomWordsState and that we'll call it's | |
| expression of itself into a method called createState - which is an alias of sorts like I just said | |
| to the "object that is a method kinda sorta?" | |
| It's kind of like we access the State itslef that belongs to the statefulwidget | |
| through a method on the StatefulWidget object | |
| oooh, I think createState() must be a built-in method on original | |
| StatefulWidget class, and we override it saying guess what | |
| lets have that method return whatever our state class gives us, and we | |
| can just call it by name with a () after it to methodify it magically? | |
| */ | |
| class RandomWords extends StatefulWidget { | |
| @override | |
| RandomWordsState createState() => RandomWordsState(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment