From 3459ec9fd8dede41fb581ca35177d53bc4393881 Mon Sep 17 00:00:00 2001 From: "Yusuke.Inoue" Date: Tue, 29 Dec 2020 10:26:37 +0900 Subject: [PATCH] Cannot use the same id --- CHANGELOG.md | 3 +++ README.md | 12 +++++++++--- example/pubspec.lock | 2 +- lib/src/interactive_scroll_viewer.dart | 7 +++++++ pubspec.yaml | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fc6bd4..d7ec391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.3.1 +- Cannot use the same id + # 1.3.0 - Get id by scroll position - To set ScrollController diff --git a/README.md b/README.md index 8d578b3..08001a3 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ You should add the following to your `pubspec.yaml` file: ```yaml dependencies: - scroll_to_id: ^1.3.0 + scroll_to_id: ^1.3.1 ``` ## Getting Started @@ -22,9 +22,14 @@ To start, import the dependency in your code: import 'package:scroll_to_id/scroll_to_id.dart'; ``` -Next, to create instance: +Next, to define ScrollController: ```dart -final ScrollToId scrollToId = ScrollToId(); +final scrollController = ScrollController(); +``` + +Next, to create instance with ScrollController: +```dart +ScrollToId scrollToId = ScrollToId(scrollController: scrollController); ``` Next, to set InteractiveScrollViewer and ScrollContent: @@ -54,6 +59,7 @@ InteractiveScrollViewer( ``` id property is destination of scroll. +Do not use the same id. Next, to scroll to id: diff --git a/example/pubspec.lock b/example/pubspec.lock index cfffbde..fedf58d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -94,7 +94,7 @@ packages: path: ".." relative: true source: path - version: "1.2.1" + version: "1.3.0" sky_engine: dependency: transitive description: flutter diff --git a/lib/src/interactive_scroll_viewer.dart b/lib/src/interactive_scroll_viewer.dart index 5882a21..88a4a7b 100644 --- a/lib/src/interactive_scroll_viewer.dart +++ b/lib/src/interactive_scroll_viewer.dart @@ -24,6 +24,8 @@ class InteractiveScrollViewer extends StatefulWidget { } class _InteractiveScrollViewerState extends State { + List _idList = []; + @override void initState() { super.initState(); @@ -33,6 +35,11 @@ class _InteractiveScrollViewerState extends State { /// Convert ScrollContent to ScrollContentWithKey for (ScrollContent scrollContents in widget.children) { + if (_idList.contains(scrollContents.id)) { + throw Exception('Do not use the same id'); + } else { + _idList.add(scrollContents.id); + } widget.scrollToId.scrollContentsList .add(ScrollContentWithKey.fromWithout(scrollContents)); } diff --git a/pubspec.yaml b/pubspec.yaml index c9988a5..0c1ce8b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: scroll_to_id description: scroll_to_id is a Flutter library that enables screen to auto-scroll by selecting id defined for each widget in scrollview. -version: 1.3.0 +version: 1.3.1 homepage: https://github.com/yusukeinouehatchout/scroll_to_id environment: