diff --git a/example/lib/common/models.dart b/example/lib/common/models.dart index 59c3e16..2116d40 100644 --- a/example/lib/common/models.dart +++ b/example/lib/common/models.dart @@ -88,6 +88,7 @@ class Languages extends GithubLanguage with ISuspensionBean { @override Map toJson() { final Map map = super.toJson(); + // ignore: unused_element void addIfNonNull(String fieldName, dynamic value) { if (value != null) { map[fieldName] = value; diff --git a/example/lib/main.dart b/example/lib/main.dart index 9b6df88..c828b40 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -20,6 +20,7 @@ class MyApp extends StatelessWidget { title: 'AzListView Demo', theme: ThemeData( primaryColor: Colors.white, + // ignore: deprecated_member_use accentColor: Colors.grey, //primarySwatch: Colors.white, visualDensity: VisualDensity.adaptivePlatformDensity, diff --git a/example/lib/ui/car_models_page.dart b/example/lib/ui/car_models_page.dart index 2f902b2..d3b27bd 100644 --- a/example/lib/ui/car_models_page.dart +++ b/example/lib/ui/car_models_page.dart @@ -1,5 +1,3 @@ -import 'dart:developer'; - import 'package:azlistview/azlistview.dart'; import 'package:azlistview_example/common/index.dart'; import 'package:flutter/material.dart'; diff --git a/example/lib/ui/citylist_page.dart b/example/lib/ui/citylist_page.dart index 60de164..dced7d2 100644 --- a/example/lib/ui/citylist_page.dart +++ b/example/lib/ui/citylist_page.dart @@ -118,10 +118,11 @@ class _CityListPageState extends State { child: Card( clipBehavior: Clip.hardEdge, margin: const EdgeInsets.only(left: 8, top: 8, right: 8), - shape: const RoundedRectangleBorder( + shape: RoundedRectangleBorder( borderRadius: const BorderRadius.only( - topLeft: Radius.circular(4.0), - topRight: Radius.circular(4.0)), + topLeft: Radius.circular(4.0), + topRight: Radius.circular(4.0), + ), ), child: Column( children: [ diff --git a/example/pubspec.lock b/example/pubspec.lock index e45ad9a..c4d8dfd 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,9 +5,9 @@ packages: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" azlistview: dependency: "direct main" description: @@ -19,79 +19,72 @@ packages: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" characters: dependency: transitive description: name: characters - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" common_utils: dependency: "direct main" description: name: common_utils - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.1.0" convert: dependency: transitive description: name: convert - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.2" crypto: dependency: transitive description: name: crypto - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.2" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "1.0.5" decimal: dependency: transitive description: name: decimal - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "2.2.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" flutter: dependency: "direct main" description: flutter @@ -108,58 +101,58 @@ packages: path: "." ref: HEAD resolved-ref: b4f88207ebc0c5dcc8baa1676a0fd7796974173a - url: "git://github.com/Sky24n/github_language_colors.git" + url: "https://github.com/Sky24n/github_language_colors.git" source: git version: "2.0.0" lpinyin: dependency: "direct main" description: name: lpinyin - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.3" matcher: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.12.11" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.5" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.2" rational: dependency: transitive description: name: rational - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "2.2.0" scrollable_positioned_list: dependency: transitive description: name: scrollable_positioned_list - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.2.3" + version: "0.3.2" sky_engine: dependency: transitive description: flutter @@ -169,58 +162,58 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.9.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.9" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" sdks: - dart: ">=2.14.0 <3.0.0" - flutter: ">=1.17.0" + dart: ">=2.17.0-0 <3.0.0" + flutter: ">=2.12.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 37aa579..182487f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -28,10 +28,10 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.3 - common_utils: ^2.0.0 + cupertino_icons: ^1.0.5 + common_utils: ^2.1.0 # 汉字转拼音 - lpinyin: ^2.0.0 + lpinyin: ^2.0.3 azlistview: path: ../ @@ -41,7 +41,7 @@ dependencies: # url: git://github.com/Sky24n/github_language_colors.git github_language_colors: git: - url: git://github.com/Sky24n/github_language_colors.git + url: https://github.com/Sky24n/github_language_colors.git dev_dependencies: flutter_test: diff --git a/lib/src/az_listview.dart b/lib/src/az_listview.dart index 9175002..9170517 100644 --- a/lib/src/az_listview.dart +++ b/lib/src/az_listview.dart @@ -28,6 +28,7 @@ class AzListView extends StatefulWidget { this.indexBarAlignment = Alignment.centerRight, this.indexBarMargin, this.indexBarOptions = const IndexBarOptions(), + this.minCacheExtent, }) : super(key: key); /// with ISuspensionBean Data @@ -93,6 +94,10 @@ class AzListView extends StatefulWidget { /// IndexBar options. final IndexBarOptions indexBarOptions; + /// The minimum cache extent used by the underlying scroll lists. + /// See [ScrollView.cacheExtent]. + final double? minCacheExtent; + @override _AzListViewState createState() => _AzListViewState(); } @@ -193,6 +198,7 @@ class _AzListViewState extends State { susPosition: widget.susPosition, padding: widget.padding, physics: widget.physics, + minCacheExtent: widget.minCacheExtent, ), Align( alignment: widget.indexBarAlignment, diff --git a/lib/src/index_bar.dart b/lib/src/index_bar.dart index f93251e..d87094a 100644 --- a/lib/src/index_bar.dart +++ b/lib/src/index_bar.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'dart:math' as math; @@ -280,7 +278,7 @@ class _IndexBarState extends State { @override void initState() { super.initState(); - widget.indexBarDragNotifier?.dragDetails?.addListener(_valueChanged); + widget.indexBarDragNotifier?.dragDetails.addListener(_valueChanged); widget.controller?._attach(this); } @@ -319,7 +317,7 @@ class _IndexBarState extends State { void dispose() { widget.controller?._detach(); _removeOverlay(); - widget.indexBarDragNotifier?.dragDetails?.removeListener(_valueChanged); + widget.indexBarDragNotifier?.dragDetails.removeListener(_valueChanged); super.dispose(); } @@ -527,7 +525,7 @@ class _BaseIndexBarState extends State { action == IndexBarDragDetails.actionUpdate)) { HapticFeedback.vibrate(); } - widget.indexBarDragNotifier?.dragDetails?.value = IndexBarDragDetails( + widget.indexBarDragNotifier?.dragDetails.value = IndexBarDragDetails( action: action, index: lastIndex, tag: widget.data[lastIndex], diff --git a/lib/src/suspension_view.dart b/lib/src/suspension_view.dart index b1d0515..f2196a2 100644 --- a/lib/src/suspension_view.dart +++ b/lib/src/suspension_view.dart @@ -19,6 +19,7 @@ class SuspensionView extends StatefulWidget { this.susPosition, this.physics, this.padding, + this.minCacheExtent, }) : super(key: key); /// Suspension data. @@ -57,6 +58,10 @@ class SuspensionView extends StatefulWidget { /// The amount of space by which to inset the children. final EdgeInsets? padding; + /// The minimum cache extent used by the underlying scroll lists. + /// See [ScrollView.cacheExtent]. + final double? minCacheExtent; + @override _SuspensionViewState createState() => _SuspensionViewState(); } @@ -85,13 +90,13 @@ class _SuspensionViewState extends State { /// build sus widget. Widget _buildSusWidget(BuildContext context) { if (widget.susItemBuilder == null) { - return Container(); + return const Offstage(); } return ValueListenableBuilder>( valueListenable: itemPositionsListener.itemPositions, builder: (ctx, positions, child) { if (positions.isEmpty || widget.itemCount == 0) { - return Container(); + return const Offstage(); } ItemPosition itemPosition = positions .where((ItemPosition position) => position.itemTrailingEdge > 0) @@ -99,7 +104,8 @@ class _SuspensionViewState extends State { position.itemTrailingEdge < min.itemTrailingEdge ? position : min); - if (itemPosition.itemLeadingEdge > 0) return Container(); + if (itemPosition.itemLeadingEdge > 0) return const Offstage(); + int index = itemPosition.index; double left = 0; double top = 0; @@ -112,7 +118,7 @@ class _SuspensionViewState extends State { ISuspensionBean bean = widget.data[next]; if (bean.isShowSuspension) { double height = - context.findRenderObject()?.paintBounds?.height ?? 0; + context.findRenderObject()?.paintBounds.height ?? 0; double topTemp = itemPosition.itemTrailingEdge * height; top = math.min(widget.susItemHeight, topTemp) - widget.susItemHeight; @@ -149,7 +155,7 @@ class _SuspensionViewState extends State { return Stack( children: [ widget.itemCount == 0 - ? Container() + ? const Offstage() : ScrollablePositionedList.builder( itemCount: widget.itemCount, itemBuilder: (context, index) => _buildItem(context, index), @@ -157,6 +163,7 @@ class _SuspensionViewState extends State { itemPositionsListener: itemPositionsListener, physics: widget.physics, padding: widget.padding, + minCacheExtent: widget.minCacheExtent, ), _buildSusWidget(context), ], diff --git a/pubspec.lock b/pubspec.lock index 1cb79b0..b1bfd88 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,51 +5,44 @@ packages: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.8.2" + version: "2.9.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" characters: dependency: transitive description: name: characters - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.3.1" + version: "1.2.1" clock: dependency: transitive description: name: clock - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0" flutter: dependency: "direct main" description: flutter @@ -64,37 +57,37 @@ packages: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "0.12.11" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.5" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.2" scrollable_positioned_list: dependency: "direct main" description: name: scrollable_positioned_list - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.2.3" + version: "0.3.2" sky_engine: dependency: transitive description: flutter @@ -104,58 +97,51 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.9.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.4.8" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "0.4.9" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" sdks: - dart: ">=2.14.0 <3.0.0" - flutter: ">=1.13.8" + dart: ">=2.17.0-0 <3.0.0" + flutter: ">=2.12.0" diff --git a/pubspec.yaml b/pubspec.yaml index d725b1b..662ba94 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,13 +4,14 @@ version: 2.0.0 homepage: https://github.com/flutterchina/azlistview environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=2.18.0-44.1.beta <3.0.0" + flutter: ">=1.24.0-6.0.pre <2.0.0" dependencies: flutter: sdk: flutter # https://pub.flutter-io.cn/packages/scrollable_positioned_list - scrollable_positioned_list: ^0.2.3 + scrollable_positioned_list: ^0.3.2 dev_dependencies: flutter_test: