Mobile UI Flashcards
How does flutter app start?
The call begins with a main() function, that calls the runApp() function that will run the code within the function on emulator or mobile device.
What is Scaffold?
A Class in Flutter framework that lets us define the App Bar easily. Or a basic visual layout structure. To use: runApp( Scaffold( appBar: AppBar() ))
What is difference between Class and Properties?
Within a Class there are several properties to use. e.g. calling Scaffold Scaffold( appBar: AppBar( title: Text() ) ) Here, appBar is property, while AppBar is a class.
What is a Child?
Within a Class() we can another Class() as a child, thus resulting in a nested widget setup. The parent class can govern some properties.
What is pubspec.yaml?
Define the assets under “assets:” section. Use Pub Get to add new files/assets to be used in the project.
How to use Images?
- Define the images in pubspec.yaml
- Execute PubGet
- Within the executable code, call the assets:
Center(
child: Image.asset(“images/test.png”)
)
OR
Networkimage or Assetimage(“images/test.png”)
What is a StatelessWidget?
It describes part of the user interface by building a constellation of other widgets.
This part of user interface doesn’t depend on anything outside of the configuration provided within the object.
How to change the icons on the App?
Android:
/android/app/src/main/res/mipmap*
iOS:
/iOS/Runner/Assets.xcassets/*
Download the archive from appicon.co and replace the corresponding directlories.
Hot Reload vs Hot Restart
Flutter lets us use Stateless Widget to be able to use Hot Reload and Hot Restart.
In Hot Reload the state of the application is maintained and when I change something, the change alone is reflected on the app. While in Hot Restart the state of the app will be deleted, and app will start from the initial point.
All the elements within the build function will be re-drawn with Hot Reload and Restart. Anything that is outside of the build function will not update.
Flutter Widget Catalog.
Has all the widgets categorized in terms of function. Good location for browsing through different widgets.
What is a Container?
Is an element used to maintain layout. Can be used to manipulate how the information is displayed on screen.
Can have 1 child.
What is a SafeArea?
When printing elements on the UI, we have to ensure the borders and the notches are not blocking any important information.
To ensure this, we can use SafeArea() to ensure the enclosed elements are not blocked.
e.g. SafeArea( child: Container( child: Text("Hello World") ) )
What are EdgeInsets?
Used to add boundaries around elements.
Container(
margin: EdgeInsets.Only(left: 30.0)
)
Note: Margin is outside of the widget, and Padding is for the inside of the widget.
Where are Column() and Row() used?
Container() can only have 1 child. Same as Container Column and Row are Layout functionality that let’s us use multiple child elements, which are denoted by ‘children: []’
How is SizedBox() used?
For layout arrangement, we can add SizedBox in between other Containers to achieve desired arrangement.
Quick way to add a circular profile photo?
Use the CircularAvatar() Widget, and use the option backgroundImage:
Note: Image.asset or Image.file will not work as the data type is different.
Networkimage or Assetimage(“images/test.png”) - works
Update Font displayed.
Update pubspec.yaml with: fonts: - family: xyz fonts: - assets: fonts/xyz.ttf
On the Text class modify below as: TextStyle(fontFamily: "XYZ")
What is Margin and Padding?
Margin - empty space that surronds the element.
Padding - the space between the contents of a container and the boundaries of the container.
mainAxisAlignment
For Rows, how the data is arranged in terms if vertical middle line.
For Columns, how the data is arranged in terms of horizontal middle line.
mainAxisSize
For Rows the size of the container consumes complete row. Defining MainAxixSize.min will reduce the container size to the elements.
Similary for Columns, the size of the Container havng the Column will be the whole column. It can be set to min to just fit the elements or set max to consume whole column.
Note: the size of container increases to consume everything available.
What is a Card?
Instead of creating rows and columns to show some info, we can use Card that will create beautiful looking boxes with shadow to show info.
Note: Card doesnt have padding. So we can have a child called Padding, that has a property padding.
What is a ListTile?
Instead of creating rows and columns to arrange an icon and text, we can create a ListTile, which has a leading elemet and a title.
So for leading we can provide an icon, and for the title we can provide the text.