How do I unload an event loop in Dart? It is quite a common situation for us to have APIs like Future<List<T>>.
Imagine a method that returns a list of users. What you do there is parse the json into a dart list and then somehow convert it into a typed list of models. This conversion to models can be done lazily. Just change the API to Stream<T> and you will get the idea. You can put all the elements in the event loop to process them asynchronously.
Here is the link to the working flutter app, which gives you an example of how to do this:
https://gist.github.com/hawkkiller/932140079adfdcab2cfdd4b0292bb50a
#dart #flutter #async #eventloop #tip
Imagine a method that returns a list of users. What you do there is parse the json into a dart list and then somehow convert it into a typed list of models. This conversion to models can be done lazily. Just change the API to Stream<T> and you will get the idea. You can put all the elements in the event loop to process them asynchronously.
Here is the link to the working flutter app, which gives you an example of how to do this:
https://gist.github.com/hawkkiller/932140079adfdcab2cfdd4b0292bb50a
#dart #flutter #async #eventloop #tip
Gist
Event Loop unloading
Event Loop unloading. GitHub Gist: instantly share code, notes, and snippets.
Today published a post about Dart GC. I wrote about the garbage collection process and the tricks it employs.
Linkedin
Sign Up | LinkedIn
500 million+ members | Manage your professional identity. Build and engage with your professional network. Access knowledge, insights and opportunities.
Today I learned an interesting algorithm for finding the majority element.
The Boyer-Moore majority algorithm is a popular algorithm for finding the majority element in a list of integers. The majority element in an array (or list) is an element that appears more than n/2 times where n is the size of the array.
Here's a simple way to describe the Boyer-Moore Voting Algorithm:
1. Start with an initial candidate and a counter set to 0.
2. Iterate over the list of numbers.
3. For the current number: If the counter is zero, set the current number as the candidate.
4. If the current number is the candidate, increment the counter. Otherwise, decrement the counter.
5. The candidate will be the majority number.
#dart #leetcode #tipoftheday #algorithm
The Boyer-Moore majority algorithm is a popular algorithm for finding the majority element in a list of integers. The majority element in an array (or list) is an element that appears more than n/2 times where n is the size of the array.
Here's a simple way to describe the Boyer-Moore Voting Algorithm:
1. Start with an initial candidate and a counter set to 0.
2. Iterate over the list of numbers.
3. For the current number: If the counter is zero, set the current number as the candidate.
4. If the current number is the candidate, increment the counter. Otherwise, decrement the counter.
5. The candidate will be the majority number.
#dart #leetcode #tipoftheday #algorithm
An iterator-like interface for stream values.
Allows more elegant and flexible solutions than default "for"
https://api.flutter.dev/flutter/dart-async/StreamIterator-class.html
#tip #dart #stream
Allows more elegant and flexible solutions than default "for"
https://api.flutter.dev/flutter/dart-async/StreamIterator-class.html
#tip #dart #stream
Declarative Status Bar Overlay Color in Flutter
Ever struggled with imperative SystemChrome API? See this short guide to make this process neat.
Ever struggled with imperative SystemChrome API? See this short guide to make this process neat.
Linkedin
Michael Lazebny on LinkedIn: #dart #flutter #declarative #appbar
Declarative Status Bar Overlay Color in Flutter
Have you ever struggled with switching between colors of the status/navigation bar on Android? There is an imperative solution to use SystemChrome.setSystemOverlayUiStyle, but there is an even better declarative…
Have you ever struggled with switching between colors of the status/navigation bar on Android? There is an imperative solution to use SystemChrome.setSystemOverlayUiStyle, but there is an even better declarative…
How to efficiently transform data using Codecs in Dart. Read in today's post :)
https://www.linkedin.com/feed/update/urn:li:activity:7130419429242224642/
https://www.linkedin.com/feed/update/urn:li:activity:7130419429242224642/
Linkedin
Michael Lazebny on LinkedIn: #dart #flutter #converter #json #utf8 #serialization
How to effectively serialize data in Dart & Flutter?
There is a very sophisticated way:
Dart has a built-in package called "dart:convert" that includes…
There is a very sophisticated way:
Dart has a built-in package called "dart:convert" that includes…
Avoid these dart libraries. Briefly about their drawbacks and better alternatives.
https://lazebny.io/avoid-these-dart-libraries/
#flutter #flutterdev #dart
https://lazebny.io/avoid-these-dart-libraries/
#flutter #flutterdev #dart
Michael Lazebny
Avoid These Dart Libraries
This article lists popular Dart and Flutter libraries that are not recommended, including Riverpod, Get, Get_it, Hive, and Stacked.
Modern Monorepo management in Dart and Flutter
https://lazebny.io/modern-monorepo-management
#dart #flutter #flutterdev
https://lazebny.io/modern-monorepo-management
#dart #flutter #flutterdev
Michael Lazebny
Modern Monorepo Management with Pub Workspaces and Melos in Dart
Efficiently manage Flutter/Dart monorepos using Pub Workspaces and Melos, with examples for dependency management and workflow automation.
Rust is an amazing language for FFI in Dart
All you need to do is define the extern C function, run cbindgen to generate a C header file, and then run ffigen, which generates safe Dart bindings.
Here is how I implemented upscale using Rust's "image" crate, which is 50x faster than dart's "image" package.
I think this is not the best solution and if you know how to improve it, it would be greatly appreciated! :)
#dart #rust #ffi
All you need to do is define the extern C function, run cbindgen to generate a C header file, and then run ffigen, which generates safe Dart bindings.
Here is how I implemented upscale using Rust's "image" crate, which is 50x faster than dart's "image" package.
I think this is not the best solution and if you know how to improve it, it would be greatly appreciated! :)
#dart #rust #ffi