ListView Error while using the "cacheExtent: double.infinity" in IOS

Issue

To improve the performance I used cacheExtent: double.infinity in Listview. but in ios an error popup up. how to fix this error and why this error is poping?

code :

ListView.separated(
        cacheExtent: double.infinity,
        padding: EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 8),
        itemCount: 200,
        itemBuilder: (_, index) {
          return _buildItem();
        },
        separatorBuilder: (context, index) {
          return Divider(
            color: AppColors.app_list_divider,
          );
        },
      )

Error :

flutter: [2022-02-16 16:39:40.239153 | Catcher | FINE] Error: ”package:flutter/src/semantics/semantics.dart’: Failed assertion: line 1592 pos 12: ‘value.isFinite’: SemanticsNode#60(Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), tags: [RenderViewport.twoPane], invisible) (with null) tried to set a non-finite rect.’ has been skipped to due to duplication occurence within 3000 ms.

Solution

I had the same problem today. Instead of using double.infinity, try to use double.maxFinite, like this:

ListView.separated(
  cacheExtent: double.maxFinite,
  ...
);

According to the docs, this are the values behind them:

static const double nan = 0.0 / 0.0;
static const double infinity = 1.0 / 0.0;
static const double negativeInfinity = -infinity;
static const double minPositive = 5e-324;
static const double maxFinite = 1.7976931348623157e+308;

It worked for me, hope it will work for you 🙂

Answered By – Marc Sanny

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.