Urgent.News

What's breaking now, across thousands of outlets.

Tech

Scrolling to an Index in a Flutter Lazy List, Without Building Everything Above It

You have a list of a million rows and you want to jump to row 842,013. ScrollController.jumpTo takes a pixel offset, not an index. To convert one to the other you need the total height of the 842,012 rows above your target — and a lazy list has never built them, so it does not know how tall they are. That is not an oversight. It is the entire point of a lazy list. Flutter ships no answer. The two…

The article discusses the problem of jumping to a specific index in a Flutter lazy list without building all the preceding elements, which is a common challenge when dealing with large lists. The author highlights the limitations of various methods that people often attempt to solve this issue, such as using a fixed item extent, estimating average row height, using GlobalKey to ensure visibility, or rebuilding the entire list with the desired anchor index.

The article explains that these approaches either fail to provide a smooth jumping experience or are not practical for real-world scenarios.

The core solution proposed in the article is to use an AnchoredListController in combination with an AnchoredList widget. This approach involves splitting the list into two parts at the anchor index, with the content before the anchor laid out in reverse order and the anchor itself serving as the center of the viewport. By setting the scroll offset to zero, the anchor index becomes the reference point for scrolling, allowing the user to jump to any index with O(1) complexity and without the need to rebuild or measure anything above the anchor.

This method also addresses the issue of content shifting when new items are added above the current position, as items above the anchor are naturally positioned at negative offsets, ensuring the user's content remains stable.

The key takeaway from the article is that Flutter's center property of Viewport, which supports negative offsets, can be leveraged to create a solution for jumping to arbitrary indices in a lazy list. By understanding that the offset origin can be placed anywhere, developers can implement a simple and efficient solution that avoids the pitfalls of previous workarounds.

The article also mentions the added benefit of handling dynamic content, such as chat feeds or logs, where new items can arrive above the current position without disrupting the user's experience.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

10 Developer Tools That Can Save You Time Every Day

As developers, a surprising amount of time is spent on small tasks. Formatting JSON, encoding Base64, generating hashes, decoding JWTs, testing regular expressions, converting timestamps — none of…

  • MazdaDev streamlines developer tasks by combining utilities into one workspace.
  • Offers JSON Formatter, Base64 Encoder/Decoder, JWT Decoder, and more.
  • 7-day Pro trial available to test tools and features.

Talking to Native: FFI, Pigeon, and Knowing Which One You Need

A MethodChannel typo cost us three days and a hotfix release, and the compiler never said a word. That's the whole story of Flutter native interop in one sentence: the easy path is a stringly-typed…

  • Dart:ffi offers fastest interop, calls C, Rust directly with zero serialization
  • Pigeon generates type-safe method channels, provides compiler checks on both sides
  • Raw MethodChannel/EventChannel is asynchronous, dynamically typed fallback for specific cases

urning emailed spreadsheets into Magento orders without asking customers to change

Every B2B Magento store I've worked on has the same quiet leak. A chunk of the orders never touch the storefront. They arrive as an .xlsx exported from the buyer's purchasing system, a PDF purchase…

  • Salespeople create orders manually, bypassing storefront
  • Author proposes letting spreadsheets arrive in original format
  • Magento converts orders via draft review before finalization

Introducing TaxUI: A Modern Declarative HTML & CSS Framework with Zero JavaScript

Hey fellow developers! 👋 Like many of you, I've spent countless hours configuring build tools, writing endless strings of utility classes, or importing heavy JavaScript bundles just to achieve basic…

  • TaxUI is a JavaScript-free framework for modern web development.
  • Uses declarative HTML attributes for component building.
  • Lightweight at 14.8 KB gzipped, with sub-bundles as small as 1.4 KB.

More from Saturday 5 September →