From c5cfc5c4dcfd210f843aa11ac85fd799e5e217f0 Mon Sep 17 00:00:00 2001 From: Ha Duy Hung Date: Sat, 11 Aug 2018 08:37:39 +0700 Subject: [PATCH] re-config to support Dart2 --- CHANGELOG.md | 6 +- example/pubspec.lock | 96 ++++++++-------- flip_panel.iml | 1 + lib/flip_panel.dart | 262 +++++++++++++++++++++---------------------- pubspec.yaml | 4 +- 5 files changed, 186 insertions(+), 183 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30fa66b..b236b2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,4 +12,8 @@ ## [0.0.4] -* Fix bugs (temporarily get around the matter of perspective transform) \ No newline at end of file +* Fix bugs (temporarily get around the matter of perspective transform) + +## [0.0.5] + +* re-config to support Dart2 \ No newline at end of file diff --git a/example/pubspec.lock b/example/pubspec.lock index 35bd1d8..8df6363 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,35 +7,35 @@ packages: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.31.2-alpha.2" + version: "0.32.4" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.4.3" + version: "1.5.0" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.0.7" + version: "2.0.8" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.1" + version: "1.1.2" collection: dependency: transitive description: @@ -49,21 +49,21 @@ packages: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.0.1" + version: "2.0.2" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.0.5" + version: "2.0.6" csslib: dependency: transitive description: name: csslib url: "https://pub.dartlang.org" source: hosted - version: "0.14.4" + version: "0.14.4+1" cupertino_icons: dependency: "direct main" description: @@ -77,7 +77,7 @@ packages: path: ".." relative: true source: path - version: "0.0.3" + version: "0.0.5" flutter: dependency: "direct main" description: flutter @@ -94,28 +94,28 @@ packages: name: front_end url: "https://pub.dartlang.org" source: hosted - version: "0.1.0-alpha.12" + version: "0.1.4" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "1.1.7" html: dependency: transitive description: name: html url: "https://pub.dartlang.org" source: hosted - version: "0.13.3+1" + version: "0.13.3+2" http: dependency: transitive description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.11.3+16" + version: "0.11.3+17" http_multi_server: dependency: transitive description: @@ -129,49 +129,49 @@ packages: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.2" + version: "3.1.3" io: dependency: transitive description: name: io url: "https://pub.dartlang.org" source: hosted - version: "0.3.2+1" + version: "0.3.3" js: dependency: transitive description: name: js url: "https://pub.dartlang.org" source: hosted - version: "0.6.1" + version: "0.6.1+1" json_rpc_2: dependency: transitive description: name: json_rpc_2 url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.0.9" kernel: dependency: transitive description: name: kernel url: "https://pub.dartlang.org" source: hosted - version: "0.3.0-alpha.12" + version: "0.3.4" logging: dependency: transitive description: name: logging url: "https://pub.dartlang.org" source: hosted - version: "0.11.3+1" + version: "0.11.3+2" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.2" + version: "0.12.2+1" meta: dependency: transitive description: @@ -185,98 +185,98 @@ packages: name: mime url: "https://pub.dartlang.org" source: hosted - version: "0.9.6+1" + version: "0.9.6+2" multi_server_socket: dependency: transitive description: name: multi_server_socket url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.2" node_preamble: dependency: transitive description: name: node_preamble url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "1.4.4" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.5" package_resolver: dependency: transitive description: name: package_resolver url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.1" + version: "1.6.2" plugin: dependency: transitive description: name: plugin url: "https://pub.dartlang.org" source: hosted - version: "0.2.0+2" + version: "0.2.0+3" pool: dependency: transitive description: name: pool url: "https://pub.dartlang.org" source: hosted - version: "1.3.5" + version: "1.3.6" pub_semver: dependency: transitive description: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.4.2" quiver: dependency: transitive description: name: quiver url: "https://pub.dartlang.org" source: hosted - version: "0.29.0+1" + version: "2.0.0+1" shelf: dependency: transitive description: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "0.7.3+1" + version: "0.7.3+3" shelf_packages_handler: dependency: transitive description: name: shelf_packages_handler url: "https://pub.dartlang.org" source: hosted - version: "1.0.3" + version: "1.0.4" shelf_static: dependency: transitive description: name: shelf_static url: "https://pub.dartlang.org" source: hosted - version: "0.2.7+1" + version: "0.2.8" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "0.2.2+2" + version: "0.2.2+4" sky_engine: dependency: transitive description: flutter @@ -288,49 +288,49 @@ packages: name: source_map_stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.1.4" + version: "1.1.5" source_maps: dependency: transitive description: name: source_maps url: "https://pub.dartlang.org" source: hosted - version: "0.10.5" + version: "0.10.7" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.4.0" + version: "1.4.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.2" + version: "1.9.3" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "1.6.7+1" + version: "1.6.8" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.3" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.0.1" test: dependency: transitive description: @@ -351,41 +351,41 @@ packages: name: utf url: "https://pub.dartlang.org" source: hosted - version: "0.9.0+4" + version: "0.9.0+5" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.6" + version: "2.0.8" vm_service_client: dependency: transitive description: name: vm_service_client url: "https://pub.dartlang.org" source: hosted - version: "0.2.4+3" + version: "0.2.6" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+8" + version: "0.9.7+10" web_socket_channel: dependency: transitive description: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted - version: "1.0.8" + version: "1.0.9" yaml: dependency: transitive description: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.1.14" + version: "2.1.15" sdks: - dart: ">=2.0.0-dev.62.0 <=2.0.0-dev.63.0.flutter-4c9689c1d2" + dart: ">=2.0.0-dev.62.0 <=2.0.0-dev.69.5.flutter-eab492385c" diff --git a/flip_panel.iml b/flip_panel.iml index 27c9b7c..be90f19 100644 --- a/flip_panel.iml +++ b/flip_panel.iml @@ -9,6 +9,7 @@ + diff --git a/lib/flip_panel.dart b/lib/flip_panel.dart index 4c77528..08acb73 100644 --- a/lib/flip_panel.dart +++ b/lib/flip_panel.dart @@ -32,11 +32,13 @@ class FlipClock extends StatelessWidget { this.spacing = const EdgeInsets.symmetric(horizontal: 2.0), }) { _digitBuilder = (context, digit) => Container( + alignment: Alignment.center, + width: 44.0, + height: 60.0, decoration: BoxDecoration( color: backgroundColor, borderRadius: borderRadius, ), - padding: const EdgeInsets.symmetric(horizontal: 6.0), child: Text( '$digit', style: TextStyle( @@ -50,7 +52,9 @@ class FlipClock extends StatelessWidget { color: backgroundColor, borderRadius: borderRadius, ), - padding: const EdgeInsets.symmetric(horizontal: 6.0), + width: 24.0, + height: 60.0, + alignment: Alignment.center, child: Text( ':', style: TextStyle( @@ -68,7 +72,8 @@ class FlipClock extends StatelessWidget { int hours = startTime.hour; var time = startTime; - final timeStream = Stream.periodic(Duration(milliseconds: 1000), (_) { + final timeStream = + Stream.periodic(Duration(milliseconds: 1000), (_) { time = time.add(const Duration(seconds: 1)); return time; }).asBroadcastStream(); @@ -251,7 +256,8 @@ class _FlipPanelState extends State bool _isStreamMode; bool _running; final _perspective = 0.003; - final _zeroAngle = 0.0001; // There's something wrong in the perspective transform, I use a very small value instead of zero to temporarily get it around. + final _zeroAngle = + 0.0001; // There's something wrong in the perspective transform, I use a very small value instead of zero to temporarily get it around. int _loop; T _currentValue, _nextValue; Timer _timer; @@ -271,22 +277,22 @@ class _FlipPanelState extends State _loop = 0; _controller = - new AnimationController(duration: widget.duration, vsync: this) - ..addStatusListener((status) { - if (status == AnimationStatus.completed) { - _isReversePhase = true; - _controller.reverse(); - } - if (status == AnimationStatus.dismissed) { - _currentValue = _nextValue; - _running = false; - } - }) - ..addListener(() { - setState(() { - _running = true; - }); - }); + new AnimationController(duration: widget.duration, vsync: this) + ..addStatusListener((status) { + if (status == AnimationStatus.completed) { + _isReversePhase = true; + _controller.reverse(); + } + if (status == AnimationStatus.dismissed) { + _currentValue = _nextValue; + _running = false; + } + }) + ..addListener(() { + setState(() { + _running = true; + }); + }); _animation = Tween(begin: _zeroAngle, end: math.pi / 2).animate(_controller); @@ -368,20 +374,20 @@ class _FlipPanelState extends State _child1 = _child2 != null ? _child2 : _isStreamMode - ? widget.streamItemBuilder(context, _currentValue) - : widget.indexedItemBuilder( - context, _currentIndex % widget.itemsCount); + ? widget.streamItemBuilder(context, _currentValue) + : widget.indexedItemBuilder( + context, _currentIndex % widget.itemsCount); _child2 = null; _upperChild1 = - _upperChild2 != null ? _upperChild2 : makeUpperClip(_child1); + _upperChild2 != null ? _upperChild2 : makeUpperClip(_child1); _lowerChild1 = - _lowerChild2 != null ? _lowerChild2 : makeLowerClip(_child1); + _lowerChild2 != null ? _lowerChild2 : makeLowerClip(_child1); } if (_child2 == null) { _child2 = _isStreamMode ? widget.streamItemBuilder(context, _nextValue) : widget.indexedItemBuilder( - context, (_currentIndex + 1) % widget.itemsCount); + context, (_currentIndex + 1) % widget.itemsCount); _upperChild2 = makeUpperClip(_child2); _lowerChild2 = makeLowerClip(_child2); } @@ -389,133 +395,125 @@ class _FlipPanelState extends State _child1 = _child2 != null ? _child2 : _isStreamMode - ? widget.streamItemBuilder(context, _currentValue) - : widget.indexedItemBuilder( - context, _currentIndex % widget.itemsCount); + ? widget.streamItemBuilder(context, _currentValue) + : widget.indexedItemBuilder( + context, _currentIndex % widget.itemsCount); _upperChild1 = - _upperChild2 != null ? _upperChild2 : makeUpperClip(_child1); + _upperChild2 != null ? _upperChild2 : makeUpperClip(_child1); _lowerChild1 = - _lowerChild2 != null ? _lowerChild2 : makeLowerClip(_child1); + _lowerChild2 != null ? _lowerChild2 : makeLowerClip(_child1); } } - Widget _buildUpperFlipPanel() => - widget.direction == FlipDirection.up - ? Stack( - children: [ - Transform( + Widget _buildUpperFlipPanel() => widget.direction == FlipDirection.up + ? Stack( + children: [ + Transform( + alignment: Alignment.bottomCenter, + transform: Matrix4.identity() + ..setEntry(3, 2, _perspective) + ..rotateX(_zeroAngle), + child: _upperChild1), + Transform( alignment: Alignment.bottomCenter, transform: Matrix4.identity() ..setEntry(3, 2, _perspective) - ..rotateX(_zeroAngle), - child: _upperChild1 - ), - Transform( - alignment: Alignment.bottomCenter, - transform: Matrix4.identity() - ..setEntry(3, 2, _perspective) - ..rotateX(_isReversePhase ? _animation.value : math.pi / 2), - child: _upperChild2, - ), - ], - ) - : Stack( - children: [ - Transform( + ..rotateX(_isReversePhase ? _animation.value : math.pi / 2), + child: _upperChild2, + ), + ], + ) + : Stack( + children: [ + Transform( + alignment: Alignment.bottomCenter, + transform: Matrix4.identity() + ..setEntry(3, 2, _perspective) + ..rotateX(_zeroAngle), + child: _upperChild2), + Transform( alignment: Alignment.bottomCenter, transform: Matrix4.identity() ..setEntry(3, 2, _perspective) - ..rotateX(_zeroAngle), - child: _upperChild2 - ), - Transform( - alignment: Alignment.bottomCenter, - transform: Matrix4.identity() - ..setEntry(3, 2, _perspective) - ..rotateX(_isReversePhase ? math.pi / 2 : _animation.value), - child: _upperChild1, - ), - ], - ); + ..rotateX(_isReversePhase ? math.pi / 2 : _animation.value), + child: _upperChild1, + ), + ], + ); - Widget _buildLowerFlipPanel() => - widget.direction == FlipDirection.up - ? Stack( - children: [ - Transform( + Widget _buildLowerFlipPanel() => widget.direction == FlipDirection.up + ? Stack( + children: [ + Transform( + alignment: Alignment.topCenter, + transform: Matrix4.identity() + ..setEntry(3, 2, _perspective) + ..rotateX(_zeroAngle), + child: _lowerChild2), + Transform( alignment: Alignment.topCenter, transform: Matrix4.identity() ..setEntry(3, 2, _perspective) - ..rotateX(_zeroAngle), - child: _lowerChild2 - ), - Transform( - alignment: Alignment.topCenter, - transform: Matrix4.identity() - ..setEntry(3, 2, _perspective) - ..rotateX(_isReversePhase ? math.pi / 2 : -_animation.value), - child: _lowerChild1, - ) - ], - ) - : Stack( - children: [ - Transform( + ..rotateX(_isReversePhase ? math.pi / 2 : -_animation.value), + child: _lowerChild1, + ) + ], + ) + : Stack( + children: [ + Transform( + alignment: Alignment.topCenter, + transform: Matrix4.identity() + ..setEntry(3, 2, _perspective) + ..rotateX(_zeroAngle), + child: _lowerChild1), + Transform( alignment: Alignment.topCenter, transform: Matrix4.identity() ..setEntry(3, 2, _perspective) - ..rotateX(_zeroAngle), - child: _lowerChild1 - ), - Transform( - alignment: Alignment.topCenter, - transform: Matrix4.identity() - ..setEntry(3, 2, _perspective) - ..rotateX(_isReversePhase ? -_animation.value : math.pi / 2), - child: _lowerChild2, - ) - ], - ); + ..rotateX(_isReversePhase ? -_animation.value : math.pi / 2), + child: _lowerChild2, + ) + ], + ); Widget _buildPanel() { return _running ? Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - _buildUpperFlipPanel(), - Padding( - padding: EdgeInsets.only(top: widget.spacing), - ), - _buildLowerFlipPanel(), - ], - ) + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + _buildUpperFlipPanel(), + Padding( + padding: EdgeInsets.only(top: widget.spacing), + ), + _buildLowerFlipPanel(), + ], + ) : _isStreamMode && _currentValue == null - ? Container() - : Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Transform( - alignment: Alignment.bottomCenter, - transform: Matrix4.identity() - ..setEntry(3, 2, _perspective) - ..rotateX(_zeroAngle), - child: _upperChild1 - ), - Padding( - padding: EdgeInsets.only(top: widget.spacing), - ), - Transform( - alignment: Alignment.topCenter, - transform: Matrix4.identity() - ..setEntry(3, 2, _perspective) - ..rotateX(_zeroAngle), - child: _lowerChild1 - ) - ], - ); + ? Container() + : Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Transform( + alignment: Alignment.bottomCenter, + transform: Matrix4.identity() + ..setEntry(3, 2, _perspective) + ..rotateX(_zeroAngle), + child: _upperChild1), + Padding( + padding: EdgeInsets.only(top: widget.spacing), + ), + Transform( + alignment: Alignment.topCenter, + transform: Matrix4.identity() + ..setEntry(3, 2, _perspective) + ..rotateX(_zeroAngle), + child: _lowerChild1) + ], + ); } -} \ No newline at end of file +} diff --git a/pubspec.yaml b/pubspec.yaml index b44dccd..4018204 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: flip_panel description: A package for flip panel with built-in animation -version: 0.0.4 +version: 0.0.5 author: hunghd homepage: https://github.com/hnvn/flutter_flip_panel environment: - sdk: '>=1.19.0 <2.0.0' + sdk: '>=1.20.1 <3.0.0' dependencies: flutter: