Flutter Tips And Tricks Versions Save

A Collection of Flutter and Dart Tips and Tricks

375

1 year ago

Canonicalized maps in Dart are maps where for each key, you can calculate a unique value and should two keys get the same unique value, the last one always wins. Here is an example of how this can be useful => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/canonicalized-maps-in-dart/canonicalized-maps-in-dart.md

374

1 year ago

If you can turn a function into a data type, then you can extend it. This example shows how helpful this can be =>

https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/extending-functions-in-flutter/extending-functions-in-flutter.md

373

1 year ago

In order to make sure your stream produces an element every N-seconds, you can take advantage of this useful Stream transformer in Flutter / Dart => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/stream-timeout-between-events-in-flutter/stream-timeout-between-events-in-flutter.md

371

1 year ago

If you have multipel optional values which are needed for a single operation, you will need to check all of them for null and then perform your operation on them if all are non-null. Using this function you can simplify that task => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/unwrapping-multiple-optionals-in-flutter-and-dart/unwrapping-multiple-optionals-in-flutter-and-dart.md

370

1 year ago

Dart's List leaves a lot to be desired from the default implementation. For instance if you read the first element of an empty list you get an exception. Rust and Swift have optionality baked into their lists so you receive optional values instead of exceptions. You can create your own lists in Dart though to circumvent some of these shortcomings. Here is an example => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/safelist-in-flutter-and-dart/safelist-in-flutter-and-dart.md

369

1 year ago

Iterable.first in Dart crashes your application if your iterable is empty. Let's remedy that with this extension => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/optional-iterable-first-element-in-dart/optional-iterable-first-element-in-dart.md

368

1 year ago

Use this extension to find a key in a JSON Map object, and should it exist AND its value be of a given type, then you can convert it to another data-type all within the same operation => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/finding-and-converting-json-values-in-dart/finding-and-converting-json-values-in-dart.md

367

1 year ago

Use this extension on Object? in order to log any sort of value to the console and distinguish true null values from others => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/colorful-logs-in-flutter/colorful-logs-in-flutter.md

366

1 year ago

Iterables allow lazy evaluation of collection items in Flutter and are the preferred way of iterating over otherwise-heavy collections. Here is an example why they are important to use => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/prefer-iterable-in-flutter/prefer-iterable-in-flutter.md