Flutter - Code Development Notes
Flutter - Code Development Notes
Root Widget
App Bar Widget
Text Widget
Container Widget
Text Widget
- Widget Tree (describes the structure of widgets inside your app)
- Properties can be defined
- All widgets are classes e.g. _HomeState (has its own programmatic class
which defines its behavior and how it looks)
- Uses a programming language called Dart
- We use different widgets to create our widget tree. Everything in blue in the
code are essentially widgets nested inside each other
Lesson 3: Flutter Tutorial - Dart Primer by Net
Ninja
At the start of your code write
void main()
- The top level required function that dart will automatically find and
execute when we run a dart file.
Sample Code
The code can be tested out in the DartPad. On the left you can write the code and
on the right you can run and see what code does on the console.
DART
CONSOLE
- You cannot assign a value that is not of the same variable type
- In Dart, the void main function plays a crucial role. It is the entry point of a
Dart program from where the execution starts. The void keyword indicates
that the main function does not return a value.
- The return value is a crucial aspect of functions in Dart. A function can
return a value using the return keyword. The type of value a function returns
is specified by the return type in the function declaration. If a function does
not return a value, its return type is void.
- You may also use ‘ => ’ instead of the return function without the curly
braces which does exactly the same thing.
- You can create List data type. Return and Add functions can also be used to
input data into the list. You may be able to add values with different data
types such as an integer inside the list. But it is not common and advisable
practice to mix data types.
- It is common practice to set the data type inside the list. This can be done
using angle brackets e.g. <String>
- This is the correct example of coding and assigning data types of your
variables in a list.
-
CLASSES IN DART
- Like a blueprint for an object (like a user object e.g. username, biography or
like a shopping cart object with information about the shopping cart e.g. the
info on the shopping cart like the items, the total number of items, the prices,
etc.)
- This code is an example of how to define a class. This code describes a user
object.
- To actually create a user object based on this class follow the code below.
You can create by writing, for example User() and invoke it like we would a
function. This is called instantiating a class or making an instance of a class.
We can store this inside a variable.
- Code Execution (The main function creates a User object with the given
username and age, then prints these properties to the console.)
- This approach ensures that the fields username and age are always initialized,
thus adhering to Dart's non-nullable type requirements.
Class Properties
Constructor
Method or
Function
- Let’s create a new class called SuperUser. We don’t want normal users to
have the publish update function, so we define it in SuperUser. The
SuperUSer inherits the behavior of the class User with the added option to
create additional functions.
- The void has the extra publish function that you can set.
- The constructor defines what we take in, the username and age. When we
create a SuperUser we pass in the values username and age. We don’t set
those values right in the SuperUser, we inherit it from the User which has
those values.
SuperUser inherits properties of User class
Constructor
Extra Function
Delete everything first and start with the void line. Use MaterialApp widget as our
root widget. This allows us to use a blank-up and use google materials design
features. It’s like a wrapper for the rest of our widgets in the app. Inside our widget
we can specify different properties e.g. home properties having inside it a text
widget. Always place a comma after defining a property and its value.
Lesson 5: Flutter Tutorial: Scaffold and AppBar
widgets in Android Studio by Net Ninja
Scaffold Widget allows us to implement a basic layout for our app. AppBar,
floating buttons, etc.
Scaffold is very useful to flesh out the general layout of your app.
More information on Scaffold Class in this Link. (Properties you can add to the
Scaffold widget)
Lesson 6: Flutter Tutorial: Colors and Fonts in
Android Studio by Net Ninja
You can modify the properties e.g. background color on the app bar. You can find
the values of these properties for color in the Material Design Color Palettes.
When adding a color property, you can click Cltr+Q while selecting color, a list of
the shades of the color chosen will be shown. e.g. backgroundColor:
Colors.red[400]
If you want text to accept different properties do this. You can use TextStyle and
define the properties such fontSize, fontWeight, etc.
You can also add different font families. You can get the custom font in google
fonts.