flutter-tips-and-tricks

A Collection of Flutter and Dart Tips and Tricks

Stars
6.7K
Committers
1

Bot releases are hidden (Show)

flutter-tips-and-tricks - 375 - Canonicalized Maps in Dart Latest Release

Published by vandadnp almost 2 years 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

flutter-tips-and-tricks - 374 - Extending Functions in Flutter

Published by vandadnp almost 2 years 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

flutter-tips-and-tricks - 373 - Stream Timeout Between Events in Flutter

Published by vandadnp almost 2 years 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

flutter-tips-and-tricks - 371 - Unwrapping Multiple Optionals in Flutter and Dart

Published by vandadnp almost 2 years 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

flutter-tips-and-tricks - 370 - SafeList in Flutter and Dart

Published by vandadnp almost 2 years 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

flutter-tips-and-tricks - 369 - Optional Iterable First Element in Dart

Published by vandadnp almost 2 years 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

flutter-tips-and-tricks - 368 - Finding and Converting JSON Values in Dart

Published by vandadnp almost 2 years 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

flutter-tips-and-tricks - 367 - Colorful Logs in Flutter

Published by vandadnp almost 2 years 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

flutter-tips-and-tricks - 366 - Prefer Iterable in Flutter

Published by vandadnp almost 2 years 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

flutter-tips-and-tricks - 365 - Recoveringg Stream Errors in Flutter

Published by vandadnp almost 2 years ago

Use a Stream transformer to send a value down your stream in case of an exception/error. Here is an example of us recovering a stream with the value of "Baz" upon error https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/recovering-stream-errors-in-flutter/recovering-stream-errors-in-flutter.md

flutter-tips-and-tricks - 364 - Riverpod StreamProvider Disposal

Published by vandadnp almost 2 years ago

Using the .onDispose callback of a StreamProvider's ref in Riverpod you can take care of disposal of your StreamController => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/riverpod-streamprovider-disposal/riverpod-streamprovider-disposal.md

flutter-tips-and-tricks - 363 - Figma Text Strokes in Flutter

Published by vandadnp almost 2 years ago

Using a Stack together with 2 Text widgets you can render a stroke around your texts. Check this handy tip out => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/figma-text-strokes-in-flutter/figma-text-strokes-in-flutter.md

flutter-tips-and-tricks - 362 - Universal App Links in Flutter

Published by vandadnp about 2 years ago

If you want to link to an application that is in the App Store or Google Play Store, you need to have one native and one non-native link. The native link for iOS is used when the device running your app is an iOS device and non native iOS link gets opened if your Flutter app is running on an Android device but is trying to open a link to App Store for an iOS app. The same thing is true for Android devices. With this approach, you can have one UniversalApp that solves this for you in one easy to use class => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/universal-app-links-in-flutter/universal-app-links-in-flutter.md

flutter-tips-and-tricks - 361 - Reusable Lottie Animations in Flutter

Published by vandadnp about 2 years ago

flutter-tips-and-tricks - 360 - Identical Objects in Dart

Published by vandadnp about 2 years ago

Learn how to use the identical() function in Dart to compare if two instances of an object point to the same object in memory. Read the tip here => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/identical-objects-in-dart/identical-objects-in-dart.md

flutter-tips-and-tricks - 359 - Breaking Strings in Dart

Published by vandadnp about 2 years ago

flutter-tips-and-tricks - 358 - Presenting Streams in Flutter

Published by vandadnp about 2 years ago

Just like how we presented futures in the previous tip, by implementing a present() function on AsyncSnapshot, you can easily make your Stream instances presentable in a reusable-way. The same AsyncSnapshot extension is used for presenting futures and streams. Let me show you how => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/presenting-streams-in-flutter/presenting-streams-in-flutter.md

flutter-tips-and-tricks - 357 - Presenting Futures in Flutter

Published by vandadnp about 2 years ago

By implementing a present() function on AsyncSnapshot, you can easily make your Future instances presentable in a reusable-way. Let me show you how => https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/presenting-futures-in-flutter/presenting-futures-in-flutter.md

flutter-tips-and-tricks - 356 - Absorb Stream Errors in Flutter

Published by vandadnp about 2 years ago

You can use this trick to absorb errors that are thrown down a stream. Your stream will then simply close when an exception is detected. https://github.com/vandadnp/flutter-tips-and-tricks/blob/main/tipsandtricks/absorb-stream-errors-in-flutter/absorb-stream-errors-in-flutter.md