Mobile Tech
1.14K subscribers
91 photos
8 videos
6 files
138 links
Michael Lazebny's blog about @dart and @flutter
lazebny.io
Download Telegram
When to use InheritedModel in Flutter?

Inherited widgets are a powerful, natural way to propagate information down the tree in Flutter.

The crucial thing is that they are O(1). It means, that the time needed to obtain an inherited widget from the tree is equivalent to constant.

When InheritedWidget changes (i.e., some data is updated), dependent elements are notified via didChangeDependencies and eventually rebuilt.

However, when clients (modules that depend on a widget) are interested only in a certain part of its data things become a bit complicated as the inherited widget doesn’t support it.

In such a case, the Inherited Model comes to our help. Basically, they extend the functionality of InheritedWidget by adding an aspect field.

Clients declare the aspect they’re interested in and are notified only if the data they’re interested in changes!

I’ve enclosed an example of an inherited model used for settings. Basically, when the client is interested in the locale -> it will be notified if the locale changes.

There is also a widget called MediaQuery that’s probably used by every #Flutter application. It also implements InheritedModel with its brightnessOf, sizeOf, and others.

LinkedIn
👍11
How does #Flutter draw a frame?

The process can be initiated by several sources - setState, render object, system, or engine.

When you call setState, it marks the element as dirty and asks the engine (C++) for a frame via FFI. Later, when the engine is ready, it calls the WidgetsBinding.drawFrame callback.

The drawFrame iterates through the element tree and rebuilds dirty elements. If dirty elements change their size, color, or orientation (generally something that render objects are interested in) - render objects are marked as dirty.

Then the framework performs layout and painting.

Finally, the scene (or frame) is built and sent to the painting engine.
🔥3👍2
Five Questions for Middle Flutter Developer

How will you adapt UI to large/small screens?

Ephemeral vs app state.

How do you implement state management?

Tell about “Constraints go down, sizes go up”.

How will you communicate with Native platforms?

#flutter #tip
👍13
Enhancing Image Rendering Efficiency

Handling large images often leads to excessive consumption of device memory. To tackle this issue, DevTools offers valuable insights into identifying images that are too large.

To optimize, consider setting 'cacheWidth' or 'cacheHeight' properties on your images. This approach decodes and stores images in memory at a designated size.

There is also a ResizeImage class in the SDK that can be used to resize the image.

See how the GSkinner team utilized AppImage in the Wonderous project, offering a real-world example of these techniques in action - https://buff.ly/46sE71y

#FlutterDev #Flutter #Performance
👍9
Media is too big
VIEW IN TELEGRAM
Use extent to optimize scrolling

If all elements have the same length along their main axis, it is recommended to set the extent or utilize prototypeItem. This will prevent the scrolling engine from laying out these widgets.

#Flutter #Performance
👍8🔥4
formsf.png
648 KB
Implemented extremely simple forms for #Flutter that support asynchronous validators 👀
👍7🔥4