Video Notes Contents
Course: absolute beginners
Unnecessary. Do not need 30 minutes of how to setup a google and apple developer account.
Already have the flutter setup steps known from uni.
Dart is the programming language that powers flutter.
DartPad
flutter create <ProjectName>
code .
-> command to bring up visual studio code in terminal
Android Studio for phone emulator.
the lib folder is where the code is written.
final variable in dart
final name = 'foo';
Final is a variable whose value cannot be changed. Final gives more flexible in assigning a variable later in the code, while informing the dart language that the variable once assigned is not going to change.
Function parameters are defined in the declaration or signature, while function arguments are the values or objects passed to the function when it is invoked.
Saving triggers flutters hot reload
feature, so code does not need to be rerun, by executing changes. Very cool imo.
String Formatting
print('$firstName $lastName');
If/Else - don't need.
Operators - don't need.
Lists in Dart
Sets in Dart - List of unique things (No Duplicates)
Maps in Dart
Maps are used to hold key-value pairs of information
Sound Null-Safety in Dart
Controls whether a variable can be null.
Dart has null-safety by default, therefore variables must be set to nullable.
var i = 43; // not nullable
final b = 32; // also not nullable
int? b = 12; // nullable
int? b = null;
Null-Coalescing Operator (??
)
Instead of doing multiple if/else if/else statement to decide whether a value is null or not the ??
in Dart.
const String? first = null;
const String? second = 'bar';
const String? last = 'bat';
final firstNonNull = first ?? second ?? last;
Null-Aware Assignment Operator (??=
)
Conditional Invocation
Named list of related items
enum PersonProperties
{
firstName, lastName, age
}
void test()
{
const String? name = 'foo';
const String? otherName = 'foo';
PersonProperities.firstName.name; // .name obtains the value
}
Already known.
An object is an instance of a class.
Class initialisation of object
Functions of classes
Can return instances of that are not of the same class
class Cat
{
final String name;
Cat(this.name);
factory Cat.fluffBall()
{
return Cat("Fluff Ball");
}
}
void test()
{
final fluffBall = Cat.fluffBall();
print(fluffBall.name)
}
The factory constructor does not necessarily need to return the same instance of its own class, it can return an instance of another class.
Defining custom operations in dart on own classes
void test()
{
final cat1 = Cat("Foo");
final cat2 = Cat("Foo");
if (cat1 == cat2)
{
print("They are equal");
}
else
{
print("they are not equal");
}
}
@override
bool operator ==(covariant Cat other) => other.name == name;
@override
int get hashCode => name.hashCode;
A hash code is a unique numeric value assigned to each class instance, used to identify objects in collections.
Extensions, Futures, Streams, Async Await, Generators, and Generics.
The ability to extend or add functionality to an existing class.
Data to be returned in the future.
A part of Asynchronous Programming
Future<int> futureThatMultipliesByTwo(int a)
{
return Future.delayed(const Duration(seconds: 3), () => a * 2);
}
void test() async
{
final result = await futureThatMultipliesByTwo(10);
print(result);
}
await
waits for the Future to return a value. An asynchronous "pipe" of data.
It either completes successfully, never completes, or errors.
A future that sends data down a pipe that never ends, and continues.
Stream<String> getName()
{
return Stream.periodic(const Duration(seconds: 10), (_) => return 'foo');
}
void test()
{
await for (final value in getName())
{
print(value);
}
}
Do not need.
Avoid writing the same code over and over again.
class PairOfStrings
{
final String value1;
final String value2;
PairOfStrings(this.value1, this.value2);
}
class PairOfIntegers
{
final int value1;
final int value2;
PairOfStrings(this.value1, this.value2);
}
Generic Class:
Do not have time for.
flutter create application_name