v0.4.4anchor_scroll_controller
此套件實作了一個支援錨點的 ScrollController。亦即,AnchorScrollController 支援滾動至索引並在使用者滾動時監聽索引變更。
48喜歡 5350近 30 天下載160Pub 分數
AndroidiOSWebmacOSWindowsLinux
一個支援錨點的 ScrollController
以下為英文專案原文快照,最新內容請造訪 GitHub。
This package implement a ScrollController which supports anchor. That is, AnchorScrollController supports to scroll to index and listen to index changed while scrolling by user.
Scroll to index
Listen to index changed
In the pubspec.yaml of your flutter project, add the following dependency:
dependencies:
...
anchor_scroll_controller: <latest_version>
In your library add the following import:
import 'package:anchor_scroll_controller/anchor_scroll_controller.dart';
Initialize an AnchorScrollController object and use it as the ScrollController of ListView, and wrap the items in the ListView with AnchorItemWrapper
late final AnchorScrollController _scrollController;
@override
void initState() {
super.initState();
_scrollController = AnchorScrollController(
onIndexChanged: (index) {
_tabController?.animateTo(index);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("GeneralScrollViewWidget"),
),
body: Column(
children: [
Expanded(
child: ListView.builder(
controller: _scrollController,
itemCount: length,
itemBuilder: (context, index) => AnchorItemWrapper(
index: index,
controller: _scrollController,
child: Container(
height: 50.0 + Random().nextInt(50),
color: Colors.primaries[index % Colors.primaries.length],
alignment: Alignment.center,
child: Text(index.toString(),
style: const TextStyle(fontSize: 24, color: Colors.black)),
),
)
),
),
... // omit more code
],
)
);
...
// call AnchorScrollController.scrollToIndex() to scroll to the target index item
_scrollController.scrollToIndex(index);
...
fixedItemSize param of AnchorScrollController to the size of items. For example, if the height of all items are 50, then set fixedItemSize param to 50.scrollViewWrapper param instead of controller param to AnchorItemWrapper. See cascaded_scroll_controller.dart for more detail.依賴清單 2 項
{"sdk":"flutter"}{"sdk":"flutter"}先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗