profile pic

Precise Asteroid

Welcome to Amir's Blog 👋

Dart Advanced

2022-01-22

Use functional programming side by side with imperative one for clearer clode

Functional Programming

Map

Use higher level functions - functions that get functions as params. for example map:

var ArrayAdded = Array.map((item) => item+1);

for excpetion handlig

The signature shows that an exception is a possible return value of a function, and the consumer does not ned to guess it.

Part of Dartz package

final Either<realValue, someException> result = await repository.getFromDB(...);
result.fold(
 (someRealValue) => DoWhatYouWantWithVar
 (someException) => DoWhatYouWantWithException, 
);

Streaming

Allows for async programming. There are libs in dart that ease the use of streams and allows us easy binding of our widget to these events

Dependency Injection

Easily replace between services (service locator or SL or DI) in order to easily switch between production, test and dev environments.

Main Libs

  1. get_it
  2. get
  3. kiwi_generator

Made by Amir 💚