Skip to content

12th December 2021

Computer Science

Programming

Basics

  • New: Add Flutter basics about maps.
  • New: Writing Flutter documentation.
  • New: Combine/merge/concat maps.

    You can use spread operator ...:

    final firstMap = {"1":"2"};
    final secondMap = {"2":"3"};
    
    final thirdMap = {
       ...firstMap,
       ...secondMap,
    };
    
  • New: Find element from list.

    Use .firstWhere():

    List<Currency> currencies = ...;
    Currency dollar = currencies.firstWhere((currency) => currency.code == "USD");
    
  • New: .? operator.

    Use ?. when you want to call a method/getter on an object if that object is not null (otherwise, return null).

    Example:

    currentState?.open();
    

Other

  • New: Catch only some kind of errors.

    Use @retry(retry=retry_if_exception_type(IOError)).

    Several types of exceptions can be combined as follows:

    @retry(retry=(retry_if_exception_type(IOError) | retry_if_exception_type(TimeoutError)))
    
  • New: Parse hexadecimal color string.

    /// Construct a color from a hex code string, of the format #RRGGBB.
    Color hexToColor(String code) {
      return new Color(int.parse(code.substring(1, 7), radix: 16) + 0xFF000000);
    }