flutter doctor flutter clean ios -> flutter pub get flutter clean android -> flutter pub get flutter pub add <package_name> flutter pub outdated # To see which dependencies have newer versions availableflutter pub add <firebase_packages> dart pub global activate flutterfire_cli # Remember to add to OS env-path: C:\Users\$USERNAME\AppData\Local\Pub\Cache\binscrcpy ↗ # Remember to add to OS env-path
assets: - assets/graphics/ fonts: - family: Poppins fonts: - asset: assets/fonts/Poppins-Medium.ttf weight: 400import 'package:flutter/material.dart';import 'package:flutter_testing/world_time/pages/home.dart';import 'package:flutter_testing/world_time/pages/choose_location.dart';import 'package:flutter_testing/world_time/pages/loading.dart'; void main() => runApp(MaterialApp( initialRoute: '/', // Remove later on, for testing purposes routes: { '/': (context) => const Loading(), '/home': (context) => const Home(), '/location': (context) => const ChooseLocation() }, ));Navigator.pushReplacementNamed(context, '/home');Navigator.pushNamed(context, '/home');class _LoadingState extends State<Loading> { void setupWorldTime() async { WorldTime berlin = WorldTime( locationName: "Berlin", flagIconPath: "germany.png", timezoneEndpoint: "Europe/Berlin"); await berlin.getTime(); Navigator.pushReplacementNamed(context, '/home', arguments: { 'location': berlin.locationName, 'flag': berlin.flagIconPath, 'time': berlin.time }); } void initState() { super.initState(); setupWorldTime(); }.... class _HomeState extends State<Home> { Map data = {}; Widget build(BuildContext context) { data = ModalRoute.of(context)!.settings.arguments as Map; ........_selectedIndex = 0;print('${_selectedIndex}'); // Automatically calls the toString() method on _selectedIndexprint(_selectedIndex.toString()); // The same as aboveOnly Stateful Widgets can usesetState((){})
Use setState to trigger the build function of a statefull widget:
setState(() { age += 1;});Stateful widgets have lifecycle methods we can tap into:
initState()void initState() { //TODO: Implement initstate super.initState();}Build()setStateDispose()variableWhichMMayBeNull ?? variableWhichMayAlsoBeNull ?? variableWhichMayAgainBeNull
prop = objectPropDrillingWherePropertyMayBeNull?.stringPropertyThatMayBeNull
String name;name ??= "Adam"; // name is null and "Adam" is assigned to nameprint(name); //-> Adamname ??= "Adrian"; // name is not null and "Adrian" is hence not assigned to nameprint(name); //-> Adamclass Cat { final String name; Cat(this.name); factory Cat.fluffball() { return Cat('Fluff Ball'); }} void test() { final fluffBall = Cat.fluffBall(); print(fluffBall.name);}class Cat extends Object { final String name; Cat(this.name); bool operator ==(covariant Cat other) => other.name == name; int get hashCode => name.hashCode;}extension Run on Cat { void run() { print('Cat $name is running'); }} void test() { final meow = Cat('Fluffers'); meow.run();}class Person { final String firstName; final String lastName; Person(this.firstName, this.lastName);} extension FullName on Person { String get fullName => '$firstName $lastName';} void test() { final foo = Person('Foo', 'Bar'); print(foo.fullName);}Future<int> aFutureFunction(int a) { return Future.delayed(const Duration(seconds: 3), () => a * 2);} void test() async { final result = await aFutureFunction(8); print(result); // prints 16 after 3 seconds.}void getData() async { late String username; await Future.delayed(Duration(seconds: 3), () { username = "Dirk"; }); Future.delayed(Duration(seconds: 3), () { print("$username is a developer and musician!"); }); print("End of function") //> End of function //> Dirk is a developer and musician!}Stream<String> getName() { return Stream.value('Foo');} void test() async { await for (final value in getName()) { print(value); } print('Stream finished working);}Stream<String> getName() { return Stream.periodic(const Duration(seconds: 1), (value) { return 'Foo'; });} void test() async { await for (final value in getName()) { print(value); }}Stream<Iterable<int>> getOneTwoThree() async* { ...}Iterable<int> getOneTwoThree() sync* { yield 1; yield 2; yield 3;} void test() { for (final value in getOneTwoThree()) { print(value); } // Or: print(getOneTwoThree());}class PairOfIntegers { final int value1; final int value2; PairOfIntegers(this.value1, this.value2);} class Pair<A, B> { final A value1; final B value2; Pair(this.value1, this.value2);} void test() { final names = Pair('Foo', 'Bar'); final ages = Pair(22, 34);}