From 036ccd2f46e28a186e0e72ba72f320b4cc758e2f Mon Sep 17 00:00:00 2001 From: Unger Andrey Date: Tue, 1 Dec 2020 17:22:30 +0300 Subject: [PATCH] null-safety --- .gitignore | 1 + .../ios/Flutter/flutter_export_environment.sh | 15 + example/pubspec.lock | 103 +++--- lib/index_controller.dart | 30 +- lib/parallax.dart | 14 +- lib/transformer_page_view.dart | 321 +++++++++--------- pubspec.lock | 175 +++++----- pubspec.yaml | 2 +- transformer_page_view.iml | 13 +- 9 files changed, 368 insertions(+), 306 deletions(-) create mode 100755 example/ios/Flutter/flutter_export_environment.sh diff --git a/.gitignore b/.gitignore index 44cadee..76920b3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ ios/Flutter/Generated.xcconfig ios/Runner/GeneratedPluginRegistrant.* *.log +*.iml diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh new file mode 100755 index 0000000..13b1406 --- /dev/null +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Volumes/DATA/flutter/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/cobalt/dev/git/flutter/transformer_page_view/example" +export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build/ios" +export "OTHER_LDFLAGS=$(inherited) -framework Flutter" +export "FLUTTER_FRAMEWORK_DIR=/Volumes/DATA/flutter/flutter/bin/cache/artifacts/engine/ios" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=false" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.packages" diff --git a/example/pubspec.lock b/example/pubspec.lock index c6f118f..0632861 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,41 +1,62 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: async: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.5.0-nullsafety.3" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.1.0-nullsafety.3" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0-nullsafety.5" charcode: dependency: transitive description: name: charcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0-nullsafety.3" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.0-nullsafety.3" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0-nullsafety.5" 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.2" + version: "0.1.3" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0-nullsafety.3" flutter: dependency: "direct main" description: flutter @@ -50,37 +71,23 @@ packages: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.10-nullsafety.3" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.6" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.6.2" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "1.8.0-nullsafety.3" sky_engine: dependency: transitive description: flutter @@ -90,44 +97,44 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.5.4" + version: "1.8.0-nullsafety.4" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0-nullsafety.6" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.6.8" + version: "2.1.0-nullsafety.3" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0-nullsafety.3" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety.3" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.2.2" + version: "0.2.19-nullsafety.6" transformer_page_view: dependency: "direct dev" description: @@ -139,15 +146,15 @@ packages: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.5" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety.5" sdks: - dart: ">=2.1.0 <3.0.0" + dart: ">=2.12.0-0.0 <3.0.0" diff --git a/lib/index_controller.dart b/lib/index_controller.dart index 461278f..a9333c9 100644 --- a/lib/index_controller.dart +++ b/lib/index_controller.dart @@ -8,40 +8,40 @@ class IndexController extends ChangeNotifier { static const int PREVIOUS = -1; static const int MOVE = 0; - Completer _completer; + Completer? _completer; - int index; - bool animation; - int event; + int? index; + bool? animation; + int? event; - Future move(int index, {bool animation: true}) { - this.animation = animation ?? true; + Future? move(int index, {bool animation: true}) { + this.animation = animation; this.index = index; this.event = MOVE; _completer = new Completer(); notifyListeners(); - return _completer.future; + return _completer?.future; } - Future next({bool animation: true}) { + Future? next({bool animation: true}) { this.event = NEXT; - this.animation = animation ?? true; + this.animation = animation; _completer = new Completer(); notifyListeners(); - return _completer.future; + return _completer?.future; } - Future previous({bool animation: true}) { + Future? previous({bool animation: true}) { this.event = PREVIOUS; - this.animation = animation ?? true; + this.animation = animation; _completer = new Completer(); notifyListeners(); - return _completer.future; + return _completer?.future; } void complete() { - if (!_completer.isCompleted) { - _completer.complete(); + if (_completer != null && !_completer!.isCompleted) { + _completer!.complete(); } } } diff --git a/lib/parallax.dart b/lib/parallax.dart index 6594945..56945db 100644 --- a/lib/parallax.dart +++ b/lib/parallax.dart @@ -88,9 +88,9 @@ class ParallaxColor extends StatefulWidget { final TransformInfo info; ParallaxColor({ - @required this.colors, - @required this.info, - @required this.child, + required this.colors, + required this.info, + required this.child, }); @override @@ -106,8 +106,8 @@ class ParallaxContainer extends StatelessWidget { final double opacityFactor; ParallaxContainer( - {@required this.child, - @required this.position, + {required this.child, + required this.position, this.translationFactor: 100.0, this.opacityFactor: 1.0}) : assert(position != null), @@ -129,12 +129,12 @@ class ParallaxImage extends StatelessWidget { final Image image; final double imageFactor; - ParallaxImage.asset(String name, {double position, this.imageFactor: 0.3}) + ParallaxImage.asset(String name, {double? position, this.imageFactor: 0.3}) : assert(imageFactor != null), image = Image.asset(name, fit: BoxFit.cover, alignment: FractionalOffset( - 0.5 + position * imageFactor, + 0.5 + (position ?? 0) * imageFactor, 0.5, )); diff --git a/lib/transformer_page_view.dart b/lib/transformer_page_view.dart index f4bc33f..1b0f57b 100644 --- a/lib/transformer_page_view.dart +++ b/lib/transformer_page_view.dart @@ -2,6 +2,7 @@ library transformer_page_view; import 'package:flutter/widgets.dart'; import 'package:transformer_page_view/index_controller.dart'; + export 'package:transformer_page_view/index_controller.dart'; export 'package:transformer_page_view/parallax.dart'; @@ -59,16 +60,16 @@ class TransformInfo { final Axis scrollDirection; TransformInfo( - {this.index, - this.position, - this.width, - this.height, - this.activeIndex, - this.fromIndex, - this.forward, - this.done, - this.viewportFraction, - this.scrollDirection}); + {this.index = 0, + this.position = 0, + this.width = 0, + this.height = 0, + this.activeIndex = 0, + this.fromIndex = 0, + this.forward = false, + this.done = false, + this.viewportFraction = 0, + this.scrollDirection = Axis.horizontal}); } abstract class PageTransformer { @@ -86,7 +87,7 @@ typedef Widget PageTransformerBuilderCallback(Widget child, TransformInfo info); class PageTransformerBuilder extends PageTransformer { final PageTransformerBuilderCallback builder; - PageTransformerBuilder({bool reverse: false, @required this.builder}) + PageTransformerBuilder({bool reverse: false, required this.builder}) : assert(builder != null), super(reverse: reverse); @@ -106,11 +107,11 @@ class TransformerPageController extends PageController { bool keepPage = true, double viewportFraction = 1.0, this.loop: false, - this.itemCount, + this.itemCount = 0, this.reverse: false, }) : super( initialPage: TransformerPageController._getRealIndexFromRenderIndex( - initialPage ?? 0, loop, itemCount, reverse), + initialPage, loop, itemCount, reverse), keepPage: keepPage, viewportFraction: viewportFraction); @@ -128,13 +129,13 @@ class TransformerPageController extends PageController { if (itemCount == 0) return 0; int renderIndex; if (loop) { - renderIndex = index - kMiddleValue; + renderIndex = index.toInt() - kMiddleValue; renderIndex = renderIndex % itemCount; if (renderIndex < 0) { renderIndex += itemCount; } } else { - renderIndex = index; + renderIndex = index.toInt(); } if (reverse) { renderIndex = itemCount - renderIndex - 1; @@ -148,7 +149,7 @@ class TransformerPageController extends PageController { if (position.maxScrollExtent == null || position.minScrollExtent == null) { page = 0.0; } else { - page = super.page; + page = super.page ?? 0.0; } return page; @@ -185,7 +186,7 @@ class TransformerPageController extends PageController { static int _getRealIndexFromRenderIndex( num index, bool loop, int itemCount, bool reverse) { - int result = reverse ? (itemCount - index - 1) : index; + int result = reverse ? (itemCount - index.toInt() - 1) : index.toInt(); if (loop) { result += kMiddleValue; } @@ -197,7 +198,7 @@ class TransformerPageView extends StatefulWidget { /// Create a `transformed` widget base on the widget that has been passed to the [PageTransformer.transform]. /// See [TransformInfo] /// - final PageTransformer transformer; + final PageTransformer? transformer; /// Same as [PageView.scrollDirection] /// @@ -205,7 +206,7 @@ class TransformerPageView extends StatefulWidget { final Axis scrollDirection; /// Same as [PageView.physics] - final ScrollPhysics physics; + final ScrollPhysics? physics; /// Set to false to disable page snapping, useful for custom scroll behavior. /// Same as [PageView.pageSnapping] @@ -213,12 +214,12 @@ class TransformerPageView extends StatefulWidget { /// Called whenever the page in the center of the viewport changes. /// Same as [PageView.onPageChanged] - final ValueChanged onPageChanged; + final ValueChanged? onPageChanged; - final IndexedWidgetBuilder itemBuilder; + final IndexedWidgetBuilder? itemBuilder; // See [IndexController.mode],[IndexController.next],[IndexController.previous] - final IndexController controller; + final IndexController? controller; /// Animation duration final Duration duration; @@ -226,7 +227,7 @@ class TransformerPageView extends StatefulWidget { /// Animation curve final Curve curve; - final TransformerPageController pageController; + final TransformerPageController? pageController; /// Set true to open infinity loop mode. final bool loop; @@ -253,9 +254,9 @@ class TransformerPageView extends StatefulWidget { /// [itemBuilder] will be called only with indices greater than or equal to /// zero and less than [itemCount]. TransformerPageView({ - Key key, - this.index, - Duration duration, + Key? key, + this.index = 0, + Duration? duration, this.curve: Curves.ease, this.viewportFraction: 1.0, this.loop: false, @@ -267,28 +268,28 @@ class TransformerPageView extends StatefulWidget { this.transformer, this.itemBuilder, this.pageController, - @required this.itemCount, - }) : assert(itemCount != null), + required this.itemCount, + }) : assert(itemCount != null), assert(itemCount == 0 || itemBuilder != null || transformer != null), this.duration = duration ?? new Duration(milliseconds: kDefaultTransactionDuration), super(key: key); factory TransformerPageView.children( - {Key key, - int index, - Duration duration, + {Key? key, + int index = 0, + Duration? duration, Curve curve: Curves.ease, double viewportFraction: 1.0, bool loop: false, Axis scrollDirection = Axis.horizontal, - ScrollPhysics physics, + ScrollPhysics? physics, bool pageSnapping = true, - ValueChanged onPageChanged, - IndexController controller, - PageTransformer transformer, - @required List children, - TransformerPageController pageController}) { + ValueChanged? onPageChanged, + IndexController? controller, + PageTransformer? transformer, + required List children, + TransformerPageController? pageController}) { assert(children != null); return new TransformerPageView( itemCount: children.length, @@ -316,7 +317,10 @@ class TransformerPageView extends StatefulWidget { } static int getRealIndexFromRenderIndex( - {bool reverse, int index, int itemCount, bool loop}) { + {bool reverse = false, + int index = 0, + int itemCount = 0, + bool loop = false}) { int initPage = reverse ? (itemCount - index - 1) : index; if (loop) { initPage += kMiddleValue; @@ -325,11 +329,11 @@ class TransformerPageView extends StatefulWidget { } static PageController createPageController( - {bool reverse, - int index, - int itemCount, - bool loop, - double viewportFraction}) { + {bool reverse = false, + int index = 0, + int itemCount = 0, + bool loop = false, + double viewportFraction = 0.0}) { return new PageController( initialPage: getRealIndexFromRenderIndex( reverse: reverse, index: index, itemCount: itemCount, loop: loop), @@ -338,71 +342,81 @@ class TransformerPageView extends StatefulWidget { } class _TransformerPageViewState extends State { - Size _size; - int _activeIndex; - double _currentPixels; + Size? _size; + int? _activeIndex; + double? _currentPixels; bool _done = false; ///This value will not change until user end drag. - int _fromIndex; + int? _fromIndex; - PageTransformer _transformer; + PageTransformer? _transformer; - TransformerPageController _pageController; + TransformerPageController? _pageController; Widget _buildItemNormal(BuildContext context, int index) { - int renderIndex = _pageController.getRenderIndexFromRealIndex(index); - Widget child = widget.itemBuilder(context, renderIndex); + int? renderIndex = _pageController?.getRenderIndexFromRealIndex(index); + Widget child = widget.itemBuilder != null + ? widget.itemBuilder!(context, renderIndex ?? 0) + : Container(); return child; } Widget _buildItem(BuildContext context, int index) { - return new AnimatedBuilder( - animation: _pageController, - builder: (BuildContext c, Widget w) { - int renderIndex = _pageController.getRenderIndexFromRealIndex(index); - Widget child; - if (widget.itemBuilder != null) { - child = widget.itemBuilder(context, renderIndex); - } - if (child == null) { - child = new Container(); - } - if (_size == null) { - return child ?? new Container(); - } - - double position; - - double page = _pageController.realPage; - - if (_transformer.reverse) { - position = page - index; - } else { - position = index - page; - } - position *= widget.viewportFraction; - - TransformInfo info = new TransformInfo( - index: renderIndex, - width: _size.width, - height: _size.height, - position: position.clamp(-1.0, 1.0), - activeIndex: - _pageController.getRenderIndexFromRealIndex(_activeIndex), - fromIndex: _fromIndex, - forward: _pageController.position.pixels - _currentPixels >= 0, - done: _done, - scrollDirection: widget.scrollDirection, - viewportFraction: widget.viewportFraction); - return _transformer.transform(child, info); - }); + if (_pageController != null) { + return new AnimatedBuilder( + animation: _pageController!, + builder: (BuildContext c, Widget? w) { + int renderIndex = + _pageController!.getRenderIndexFromRealIndex(index); + Widget? child; + if (widget.itemBuilder != null) { + child = widget.itemBuilder!(context, renderIndex); + } + if (child == null) { + child = new Container(); + } + if (_size == null) { + return child; + } + + double? position; + + double? page = _pageController?.realPage; + + if (_transformer != null && _transformer!.reverse) { + position = (page ?? 0) - index; + } else { + position = (index - (page ?? 0)).toDouble(); + } + position = position * widget.viewportFraction; + + TransformInfo info = new TransformInfo( + index: renderIndex, + width: _size?.width ?? 0, + height: _size?.height ?? 0, + position: position.clamp(-1.0, 1.0), + activeIndex: _pageController! + .getRenderIndexFromRealIndex(_activeIndex ?? 0), + fromIndex: _fromIndex ?? 0, + forward: + _pageController!.position.pixels - (_currentPixels ?? 0) >= + 0, + done: _done, + scrollDirection: widget.scrollDirection, + viewportFraction: widget.viewportFraction); + + return _transformer?.transform(child, info) ?? Container(); + }); + } + return Container(); } - double _calcCurrentPixels() { - _currentPixels = _pageController.getRenderIndexFromRealIndex(_activeIndex) * - _pageController.position.viewportDimension * - widget.viewportFraction; + double? _calcCurrentPixels() { + _currentPixels = + (_pageController?.getRenderIndexFromRealIndex(_activeIndex ?? 0) ?? 0) * + (_pageController?.position.viewportDimension ?? 0) * + widget.viewportFraction; // print("activeIndex:$_activeIndex , pix:$_currentPixels"); @@ -415,13 +429,13 @@ class _TransformerPageViewState extends State { _transformer == null ? _buildItemNormal : _buildItem; Widget child = new PageView.builder( itemBuilder: builder, - itemCount: _pageController.getRealItemCount(), + itemCount: _pageController?.getRealItemCount(), onPageChanged: _onIndexChanged, controller: _pageController, scrollDirection: widget.scrollDirection, physics: widget.physics, pageSnapping: widget.pageSnapping, - reverse: _pageController.reverse, + reverse: _pageController?.reverse ?? false, ); if (_transformer == null) { return child; @@ -445,18 +459,19 @@ class _TransformerPageViewState extends State { void _onIndexChanged(int index) { _activeIndex = index; - if (widget.onPageChanged != null) { - widget.onPageChanged(_pageController.getRenderIndexFromRealIndex(index)); + if (widget.onPageChanged != null && _pageController != null) { + widget + .onPageChanged!(_pageController!.getRenderIndexFromRealIndex(index)); } } void _onGetSize(_) { - Size size; + Size? size; if (context == null) { onGetSize(size); return; } - RenderObject renderObject = context.findRenderObject(); + RenderObject? renderObject = context.findRenderObject(); if (renderObject != null) { Rect bounds = renderObject.paintBounds; if (bounds != null) { @@ -467,13 +482,12 @@ class _TransformerPageViewState extends State { onGetSize(size); } - void onGetSize(Size size) { - if(mounted){ + void onGetSize(Size? size) { + if (mounted) { setState(() { _size = size; }); } - } @override @@ -487,15 +501,15 @@ class _TransformerPageViewState extends State { itemCount: widget.itemCount, loop: widget.loop, reverse: - widget.transformer == null ? false : widget.transformer.reverse); + widget.transformer == null ? false : widget.transformer!.reverse); } // int initPage = _getRealIndexFromRenderIndex(index); // _pageController = new PageController(initialPage: initPage,viewportFraction: widget.viewportFraction); - _fromIndex = _activeIndex = _pageController.initialPage; + _fromIndex = _activeIndex = _pageController?.initialPage; _controller = getNotifier(); if (_controller != null) { - _controller.addListener(onChangeNotifier); + _controller!.addListener(onChangeNotifier); } super.initState(); } @@ -503,7 +517,7 @@ class _TransformerPageViewState extends State { @override void didUpdateWidget(TransformerPageView oldWidget) { _transformer = widget.transformer; - int index = widget.index ?? 0; + int index = widget.index; bool created = false; if (_pageController != widget.pageController) { if (widget.pageController != null) { @@ -516,28 +530,29 @@ class _TransformerPageViewState extends State { loop: widget.loop, reverse: widget.transformer == null ? false - : widget.transformer.reverse); + : widget.transformer!.reverse); } } - if (_pageController.getRenderIndexFromRealIndex(_activeIndex) != index) { - _fromIndex = _activeIndex = _pageController.initialPage; + if (_pageController!.getRenderIndexFromRealIndex(_activeIndex ?? 0) != + index) { + _fromIndex = _activeIndex = _pageController!.initialPage; if (!created) { - int initPage = _pageController.getRealIndexFromRenderIndex(index); - _pageController.animateToPage(initPage, + int initPage = _pageController!.getRealIndexFromRenderIndex(index); + _pageController!.animateToPage(initPage, duration: widget.duration, curve: widget.curve); } } if (_transformer != null) - WidgetsBinding.instance.addPostFrameCallback(_onGetSize); + WidgetsBinding.instance!.addPostFrameCallback(_onGetSize); if (_controller != getNotifier()) { if (_controller != null) { - _controller.removeListener(onChangeNotifier); + _controller!.removeListener(onChangeNotifier); } _controller = getNotifier(); if (_controller != null) { - _controller.addListener(onChangeNotifier); + _controller!.addListener(onChangeNotifier); } } super.didUpdateWidget(oldWidget); @@ -546,17 +561,17 @@ class _TransformerPageViewState extends State { @override void didChangeDependencies() { if (_transformer != null) - WidgetsBinding.instance.addPostFrameCallback(_onGetSize); + WidgetsBinding.instance!.addPostFrameCallback(_onGetSize); super.didChangeDependencies(); } - ChangeNotifier getNotifier() { + ChangeNotifier? getNotifier() { return widget.controller; } int _calcNextIndex(bool next) { - int currentIndex = _activeIndex; - if (_pageController.reverse) { + int currentIndex = _activeIndex ?? 0; + if (_pageController != null && _pageController!.reverse) { if (next) { currentIndex--; } else { @@ -570,11 +585,11 @@ class _TransformerPageViewState extends State { } } - if (!_pageController.loop) { - if (currentIndex >= _pageController.itemCount) { + if (_pageController != null && !_pageController!.loop) { + if (currentIndex >= _pageController!.itemCount) { currentIndex = 0; } else if (currentIndex < 0) { - currentIndex = _pageController.itemCount - 1; + currentIndex = _pageController!.itemCount - 1; } } @@ -582,42 +597,44 @@ class _TransformerPageViewState extends State { } void onChangeNotifier() { - int event = widget.controller.event; - int index; - switch (event) { - case IndexController.MOVE: - { - index = _pageController - .getRealIndexFromRenderIndex(widget.controller.index); - } - break; - case IndexController.PREVIOUS: - case IndexController.NEXT: - { - index = _calcNextIndex(event == IndexController.NEXT); - } - break; - default: - //ignore this event - return; - } - if (widget.controller.animation) { - _pageController - .animateToPage(index, - duration: widget.duration, curve: widget.curve ?? Curves.ease) - .whenComplete(widget.controller.complete); - } else { - _pageController.jumpToPage(index); - widget.controller.complete(); + if (widget.controller != null) { + int? event = widget.controller!.event; + int? index; + switch (event) { + case IndexController.MOVE: + { + index = _pageController + ?.getRealIndexFromRenderIndex(widget.controller!.index ?? 0); + } + break; + case IndexController.PREVIOUS: + case IndexController.NEXT: + { + index = _calcNextIndex(event == IndexController.NEXT); + } + break; + default: + //ignore this event + return; + } + if (widget.controller!.animation ?? false) { + _pageController + ?.animateToPage(index ?? 0, + duration: widget.duration, curve: widget.curve) + .whenComplete(widget.controller!.complete); + } else { + _pageController!.jumpToPage(index ?? 0); + widget.controller!.complete(); + } } } - ChangeNotifier _controller; + ChangeNotifier? _controller; void dispose() { super.dispose(); if (_controller != null) { - _controller.removeListener(onChangeNotifier); + _controller!.removeListener(onChangeNotifier); } } } diff --git a/pubspec.lock b/pubspec.lock index 331b288..0e4f1cb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,55 +1,90 @@ # Generated by pub -# See https://www.dartlang.org/tools/pub/glossary#lockfile +# See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.13" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.0" async: dependency: transitive description: name: async - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.5.0-nullsafety.3" 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-nullsafety.3" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0-nullsafety.5" charcode: dependency: transitive description: name: charcode - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.2.0-nullsafety.3" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0-nullsafety.3" collection: dependency: transitive description: name: collection - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0-nullsafety.5" convert: dependency: transitive description: name: convert - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted version: "2.1.1" crypto: dependency: transitive description: name: crypto - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" + version: "2.1.5" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0-nullsafety.3" file: dependency: transitive description: name: file - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "5.0.7" + version: "6.0.0-nullsafety.4" flutter: dependency: "direct main" description: flutter @@ -70,76 +105,48 @@ packages: description: flutter source: sdk version: "0.0.0" - intl: - dependency: transitive - description: - name: intl - url: "https://pub.flutter-io.cn" - source: hosted - version: "0.15.7" json_rpc_2: dependency: transitive description: name: json_rpc_2 - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.2.2" matcher: dependency: transitive description: name: matcher - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.10-nullsafety.3" meta: dependency: transitive description: name: meta - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.6" path: dependency: transitive description: name: path - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.4.0" + version: "1.8.0-nullsafety.3" platform: dependency: transitive description: name: platform - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "3.0.0-nullsafety.4" process: dependency: transitive description: name: process - url: "https://pub.flutter-io.cn" - source: hosted - version: "3.0.9" - pub_semver: - dependency: transitive - description: - name: pub_semver - url: "https://pub.flutter-io.cn" - source: hosted - version: "1.4.2" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "4.0.0-nullsafety.4" sky_engine: dependency: transitive description: flutter @@ -149,71 +156,85 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.5.4" + version: "1.8.0-nullsafety.4" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0-nullsafety.6" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.6.8" + version: "2.1.0-nullsafety.3" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.1.0-nullsafety.3" + sync_http: + dependency: transitive + description: + name: sync_http + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety.3" test_api: dependency: transitive description: name: test_api - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "0.2.2" + version: "0.2.19-nullsafety.6" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0-nullsafety.5" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - vm_service_client: + version: "2.1.0-nullsafety.5" + vm_service: dependency: transitive description: - name: vm_service_client - url: "https://pub.flutter-io.cn" + name: vm_service + url: "https://pub.dartlang.org" source: hosted - version: "0.2.6" + version: "5.2.0" web_socket_channel: dependency: transitive description: name: web_socket_channel - url: "https://pub.flutter-io.cn" + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + webdriver: + dependency: transitive + description: + name: webdriver + url: "https://pub.dartlang.org" source: hosted - version: "1.0.9" + version: "2.1.2" sdks: - dart: ">=2.1.0 <3.0.0" + dart: ">=2.12.0-0.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 02e5bea..447d39d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ author: JZoom homepage: https://github.com/jzoom/transformer_page_view environment: - sdk: ">=2.0.0-dev.50.0 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" dependencies: flutter: diff --git a/transformer_page_view.iml b/transformer_page_view.iml index 77dcfac..378ce17 100644 --- a/transformer_page_view.iml +++ b/transformer_page_view.iml @@ -1,23 +1,24 @@ + + + + + - - + - - - + - \ No newline at end of file