Render an image only when it'll visible - flutter

Can i render an imagens only it'll visuble in scrollview?
My app has an list view with many products, when I scrolling down many times the performance of my app is down (i'm using a lazy list), i guess it's becase there many imagens (from web) render up my screen.
I'm thinking to do something like it:

You'll need to use Listview.builder with itemBuilder instead of a child
It will allow you to only render what is on the screen or what is likely to be on scrolled in the very near future - your performance will be considerably improved
I recommend watching this video from the Flutter Team on this topic (lazy load a big list view) at flutter.io - if you'd like to go deeper into the topic

use .builder when ever you can find.
Creates a scrollable, linear array of widgets that are created on demand.
This constructor is appropriate for list views with a large (or infinite) number of children because the builder is called only for those children that are actually visible.
for more follow ListView.builder

Related

Flutter Responsive Layout

I am working on building a mobile application using flutter and am stuck on building a resposive login screen layout. To be precise, I am using the MediaQuery to find the screen size and to find the safe area and based on that I am spacing and building containers based on percentage of screen height. I would like to know if this is the best way or if I am unnecessarily complicating the entire process. I did come across a few youtube videos where most of them give random numbers but when I try doing that, my layout most often than not ends of overflowing!
So far, I have mostly done this with just mathematical calculations. i.e. I have stuck to calculating the available height (total height - safe area) and then built all my containers based on this height (including their spacing). But, I am struggling with getting the right font size and this constant struggle to balance the UI in both android and iOS setup is eating up most of my time.
I built hundreds of screens in Flutter. It is very rare that you need to use exact screen height for a layout. Most screens fall into one of the three categories:
There are too many elements to fit into a screen of any size.
In this case you wrap your layout in SingleChildScrollView widget that has a Column child, and then put all other widgets in that Column. Users scroll down to see all visible elements they need to see.
There are too many elements to fit into smaller screen sizes, but they fit into larger screens.
In this case you still wrap your layout in SingleChildScrollView widget. Then you make your layout look nice on larger screens, but users on smaller screens still have to scroll down. This is not ideal, but sometimes it's the right solution. Making design elements smaller on a small screen often makes it hard to use or even totally unusable. Plus, having various calculations related to a screen size in your layout logic makes it a nightmare to test your app: you have to test it on all sorts of screen sizes.
All design elements can fit into a small screen.
In this case you should use Flex widgets (like Column, Row, Spacer, Center, etc.) to create your layout. These widgets already have a logic for spacing their children in the available space (for example, using mainAxisAlignment and crossAxisAlignment properties in Column and Row).
There are also widgets that can take a specified percentage of a screen (or their parent widget), but I never use them. I can imagine situations where these widgets can be useful, but for the vast majority of designs using Flex layout is a better option that results in better looking screens.
If you post your design and the layout you came up with, we can point if there are ways to optimize it.

3D wheel effect with list or scroll view

I need to create a list view that has a few key requirements
Infinite scroll of a fixed number of items (ie looping)
Multiple child item types (images, text, inputs)
Multiple child item heights
"3d" wheel look/feel. 2d perspective changes and shadowing/coloring should suffice
It needs to be iOS and Android compatible in Flutter.
I've tried the List Wheel Scroll View widget (https://api.flutter.dev/flutter/widgets/ListWheelScrollView-class.html) and am currently using Carousel Slider (https://pub.dev/packages/carousel_slider), but neither quite get the job done. List Wheel can't do interactive inputs or mixed child heights and the carousel can't do mixed heights or '3d'.
Has anybody created or come across something that might at least get me going in the right direction?
UPDATE
Currently playing with CustomScrollView with some success. It allows me to have multiple child heights and I ~think~ I'll be able to add some perspective to the children in the scroll listener.
What I can't figure out with CustomScrollView is how to get the looping/infinite scroll.
I liked using the flutter_swiper package a while ago. Not sure if it supports mixed heights, but it has 3D effects. But it doesn't seem maintained, so I would try this null-saefty unofficial fork : flutter_swiper_null_safety

Trying to understand RangeMaintainingScrollPhysics in flutter

I'm not sure I understand the use of RangeMaintainingScrollPhysics in Flutter.
What I have is a listview of variable items (think something like a twitter feed), and those items have images in them which dynamically load. If an image above your current position loads, then the listview item changes size and the whole list gets pushed down. The user loses his current position, which is annoying.
Reading the docs on RangeMaintainingScrollPhysics I thought that it would solve the problem I'm describing. But its not working for me at all, so either I am misunderstanding what it does or I misused it
Am I understanding what its purpose is?

GridView which keeps all elements instead of building them once on-screen

I have a grid view which is showing the heal status of many different services, and coloring them and/or auto-opening a webpage when the service goes down. The problem is that the elements which are off the screen are not being checked, which is more efficient, but not what is desired in this case.
I guess it's behaving similarly to the RecyclerView in android?
I want to be building the widgets which are checking service health even when they are not visible on the screen.
Currently the services don't start being checked until the moment I scroll them into the screen.
Assuming you are currently using the GridView.builder constructor, I recommend using the "normal" GridView constructor (with a children property). Since GridView.builder only builds the elements currently visible for efficiency reasons, the elements that are not rendered on the screen won't run your back end logic.
For more information, see the official docs:
[GridView.builder] constructor is appropriate for grid views with a large (or infinite) number of children because the builder is called only for those children that are actually visible.
Here you'll find alternatives:
The most commonly used grid layouts are GridView.count, which creates a layout with a fixed number of tiles in the cross axis, and GridView.extent, which creates a layout with tiles that have a maximum cross-axis extent.

Building calendar. Overlapping scrollable content.

I am building calendar based app and trying Flutter.
Can you give advice/example of hierarchy how build complex and efficient layout like Google Calendar daily view?
Main question: how should I layout constant hours background and overlapping dynamic events layer?
I used RecyclerView and custom RecyclerView.LayoutManager before, but have no idea about Flutter way.
You can construct your layout efficiently using GridView.custom.
A custom SliverGridDelegate can produce an aribtrary 2D arrangement of children, including arrangements that are unaligned or overlapping.
An easier option might be to use a CustomMultiChildLayout but that will require laying out all the children instead of just the ones that are visible. It could be slower, but maybe that isn't the bottleneck for a calendar app.