Mobile Tech
1.11K subscribers
91 photos
8 videos
6 files
136 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
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.
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
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
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
formsf.png
648 KB
Implemented extremely simple forms for #Flutter that support asynchronous validators 👀
Screen Recording 2024-05-18 at 20.43.37.mov
3.3 MB
🔥 A new article about popups is coming next week!

In the meantime, I have created a custom popup that positions follower widget relatively to a target and prevents it from overflowing the screen.

#flutter
Please open Telegram to view this post
VIEW IN TELEGRAM
Tomorrow, I'm launching a new article series on creating UI Kits.

I’ll guide you through developing various components like buttons, text fields, and more.

You’ll also learn about animations, transitions, iconography, responsive design tools, and best practices for layouts and custom components.

#article #uikit #flutter
Learn how to build efficient sticky headers in Flutter using slivers for seamless scrolling. Includes code examples and best practices!

https://lazebny.io/sticky-headers

#flutter #article
I created a simple but much more powerful alternative to Widgetbook, Storybook, and similar tools.

It automatically generates routes for GoRouter (supports deep links).

It also makes it very easy to create configurations, fields, etc., for customizing widgets.

This is just an example—it will be improved over time and might eventually be added to sizzle starter or a separate package.

Github Link

#flutter
This media is not supported in your browser
VIEW IN TELEGRAM
Created a minimal example of custom AppBars using SliverPersistentHeaderDelegate.Take a look here https://github.com/hawkkiller/pageheader/blob/main/lib/page_header.dart

#flutter #flutterdev
If you want to make your VS Code indentation a bit more beautiful for #Flutter widgets, set "dart.previewFlutterUiGuides" to true

If I'm not mistaken, the same thing exists in IDEA :)