Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding index builder #85

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
Expand Down Expand Up @@ -72,3 +72,5 @@ build/
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3

.fvm/
11 changes: 11 additions & 0 deletions lib/src/az_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class AzListView extends StatefulWidget {
this.indexBarAlignment = Alignment.centerRight,
this.indexBarMargin,
this.indexBarOptions = const IndexBarOptions(),
this.indexBuilder,
this.shrinkWrap = false,
}) : super(key: key);

/// with ISuspensionBean Data
Expand Down Expand Up @@ -93,6 +95,13 @@ class AzListView extends StatefulWidget {
/// IndexBar options.
final IndexBarOptions indexBarOptions;

/// The builder of index.
final IndexWidgetBuilder? indexBuilder;
/// The shrinkWrap of list.
///
/// The default value is [false].
final bool shrinkWrap;

@override
_AzListViewState createState() => _AzListViewState();
}
Expand Down Expand Up @@ -193,6 +202,7 @@ class _AzListViewState extends State<AzListView> {
susPosition: widget.susPosition,
padding: widget.padding,
physics: widget.physics,
shrinkWrap: widget.shrinkWrap,
),
Align(
alignment: widget.indexBarAlignment,
Expand All @@ -206,6 +216,7 @@ class _AzListViewState extends State<AzListView> {
indexBarDragListener: dragListener,
options: widget.indexBarOptions,
controller: indexBarController,
builder: widget.indexBuilder,
),
),
],
Expand Down
21 changes: 14 additions & 7 deletions lib/src/index_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/services.dart';

/// IndexHintBuilder.
typedef IndexHintBuilder = Widget Function(BuildContext context, String tag);
typedef IndexWidgetBuilder = Widget Function(BuildContext context, int index);

/// IndexBarDragListener.
abstract class IndexBarDragListener {
Expand Down Expand Up @@ -234,6 +235,7 @@ class IndexBar extends StatefulWidget {
IndexBarDragListener? indexBarDragListener,
this.options = const IndexBarOptions(),
this.controller,
this.builder,
}) : indexBarDragNotifier = indexBarDragListener as IndexBarDragNotifier?,
super(key: key);

Expand Down Expand Up @@ -264,6 +266,9 @@ class IndexBar extends StatefulWidget {
/// IndexBarController. If non-null, this can be used to control the state of the IndexBar.
final IndexBarController? controller;

/// The builder of index.
final IndexWidgetBuilder? builder;

@override
_IndexBarState createState() => _IndexBarState();
}
Expand All @@ -280,7 +285,7 @@ class _IndexBarState extends State<IndexBar> {
@override
void initState() {
super.initState();
widget.indexBarDragNotifier?.dragDetails?.addListener(_valueChanged);
widget.indexBarDragNotifier?.dragDetails.addListener(_valueChanged);
widget.controller?._attach(this);
}

Expand Down Expand Up @@ -319,7 +324,7 @@ class _IndexBarState extends State<IndexBar> {
void dispose() {
widget.controller?._detach();
_removeOverlay();
widget.indexBarDragNotifier?.dragDetails?.removeListener(_valueChanged);
widget.indexBarDragNotifier?.dragDetails.removeListener(_valueChanged);
super.dispose();
}

Expand Down Expand Up @@ -466,7 +471,7 @@ class _IndexBarState extends State<IndexBar> {
width: widget.width,
itemHeight: widget.itemHeight,
hapticFeedback: widget.options.hapticFeedback,
itemBuilder: (BuildContext context, int index) {
itemBuilder: widget.builder ?? (BuildContext context, int index) {
return _buildItem(context, index);
},
indexBarDragNotifier: widget.indexBarDragNotifier,
Expand Down Expand Up @@ -527,7 +532,7 @@ class _BaseIndexBarState extends State<BaseIndexBar> {
action == IndexBarDragDetails.actionUpdate)) {
HapticFeedback.vibrate();
}
widget.indexBarDragNotifier?.dragDetails?.value = IndexBarDragDetails(
widget.indexBarDragNotifier?.dragDetails.value = IndexBarDragDetails(
action: action,
index: lastIndex,
tag: widget.data[lastIndex],
Expand Down Expand Up @@ -590,9 +595,11 @@ class _BaseIndexBarState extends State<BaseIndexBar> {
//_triggerDragEvent(IndexBarDragDetails.actionUp);
},
behavior: HitTestBehavior.translucent,
child: Column(
mainAxisSize: MainAxisSize.min,
children: children,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: children,
),
),
);
}
Expand Down
8 changes: 7 additions & 1 deletion lib/src/suspension_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SuspensionView extends StatefulWidget {
this.susPosition,
this.physics,
this.padding,
this.shrinkWrap = false,
}) : super(key: key);

/// Suspension data.
Expand Down Expand Up @@ -56,6 +57,10 @@ class SuspensionView extends StatefulWidget {

/// The amount of space by which to inset the children.
final EdgeInsets? padding;
/// The shrinkWrap of list.
///
/// Default value is [false].
final bool shrinkWrap;

@override
_SuspensionViewState createState() => _SuspensionViewState();
Expand Down Expand Up @@ -112,7 +117,7 @@ class _SuspensionViewState extends State<SuspensionView> {
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;
Expand Down Expand Up @@ -157,6 +162,7 @@ class _SuspensionViewState extends State<SuspensionView> {
itemPositionsListener: itemPositionsListener,
physics: widget.physics,
padding: widget.padding,
shrinkWrap: widget.shrinkWrap,
),
_buildSusWidget(context),
],
Expand Down
61 changes: 27 additions & 34 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,51 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
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"
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.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
Expand All @@ -64,35 +64,35 @@ 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.4"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.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.1"
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"
sky_engine:
Expand All @@ -104,58 +104,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.8.2"
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"
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"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
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"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.13.8"
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: azlistview
description: A Flutter sticky headers & index ListView. IndexBar. such as citylist, contactlist. index and hover effect.
version: 2.0.0
version: 2.0.1
homepage: https://github.com/flutterchina/azlistview

environment:
Expand All @@ -10,7 +10,7 @@ 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:
Expand Down