-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Closed
Copy link
Description
Use case
Whenever itemExtent is used in a ListView, it would be nice to control the scrolling using the item index instead of an offset.
Use case:
An app has a list of items and the list should be scrolled to the 5th item.
Proposal
Allow FixedExtentScrollController (or a controller with similar functionality specialized for lists, e.g. FixedExtentListScrollController) to be used with a ListView having itemExtent specified.
Currently FixedExtentScrollController can only be used with ListWheelScrollViews is thrown.
import 'package:flutter/material.dart';
final scrollController = FixedExtentScrollController();
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
home: Scaffold(
body: ListView.builder(
controller: scrollController, // this line does not work
itemExtent: 20,
itemBuilder: (context, index) =>
Center(child: Text(index.toString()))),
),
);
}
}In case #113431 gets implemented, itemExtentPerIndex should also allow using a FixedExtentScrollController.
Apparently I'm not the only one needing this: #25074 (comment)
Metadata
Metadata
Assignees
Labels
No labels