From c56460ee9f1e278d360f25feac6e3b016c400aad Mon Sep 17 00:00:00 2001 From: Antonino Date: Tue, 26 Feb 2019 18:59:18 +0100 Subject: [PATCH] fix some artifacts with linear animation --- .idea/libraries/Dart_Packages.xml | 20 ++-- .idea/workspace.xml | 148 +++++++++++++++++------------- CHANGELOG.md | 6 +- README.md | 22 ++++- lib/inner_drawer.dart | 55 ++++++----- pubspec.lock | 15 ++- pubspec.yaml | 2 +- 7 files changed, 165 insertions(+), 103 deletions(-) diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml index 9a7d54a..8c80693 100644 --- a/.idea/libraries/Dart_Packages.xml +++ b/.idea/libraries/Dart_Packages.xml @@ -79,6 +79,13 @@ + + + + + + @@ -96,7 +103,7 @@ - @@ -124,14 +131,14 @@ - - @@ -161,13 +168,14 @@ + - + - - + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e6eed01..7d9e816 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,8 +7,12 @@ + + + + @@ -72,52 +76,61 @@ - + + - + - - - + + + - - - + + + - - + + - - + + - + - - + + + + + + + + + + @@ -125,8 +138,8 @@ - - + + @@ -137,17 +150,8 @@ - - - - - - - - - - - + + @@ -155,8 +159,8 @@ - - + + @@ -172,8 +176,6 @@ - animation - Widget build alignment widget.alignment TextDirection.rtl @@ -202,6 +204,8 @@ static materiam materia + asser + print D:\Android-Project\flutter\package\inner_drawer\flutter_inner_drawer\example @@ -222,18 +226,18 @@ - @@ -322,7 +326,6 @@ - @@ -373,11 +376,11 @@ - + - + @@ -407,11 +410,11 @@ file://$PROJECT_DIR$/lib/inner_drawer.dart - 155 + 152 file://$PROJECT_DIR$/lib/inner_drawer.dart - 275 + 281 @@ -426,34 +429,39 @@ file://$PROJECT_DIR$/lib/inner_drawer.dart - 180 + 177 file://$PROJECT_DIR$/lib/inner_drawer.dart - 438 + 449 file://$PROJECT_DIR$/lib/inner_drawer.dart - 298 + 304 file://$PROJECT_DIR$/lib/inner_drawer.dart - 403 + 414 file://$PROJECT_DIR$/lib/inner_drawer.dart - 336 + 342 file://$PROJECT_DIR$/lib/inner_drawer.dart - 393 + 404 + + file://$PROJECT_DIR$/lib/inner_drawer.dart + 192 + @@ -600,41 +608,49 @@ - + - - + + - + - - - - - + + - + - - + + - + - - + + + + + - + - - + + + + + + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index 487f9d2..e40d421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ +## [0.2.2] - 2019-02-26. + +* fix some artifacts with linear animation. + ## [0.2.1] - 2019-02-25. -* With CupertinoThemeData an assert was launched, fixed bug. +* solved the problem of CupertinoThemeData that launched an assert. ## [0.2.0] - 2019-02-16. diff --git a/README.md b/README.md index ff6d38d..1b1dd9c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # flutter_inner_drawer -[![pub package](https://img.shields.io/badge/pub-0.2.1-orange.svg)](https://pub.dartlang.org/packages/flutter_inner_drawer) +[![pub package](https://img.shields.io/badge/pub-0.2.2-orange.svg)](https://pub.dartlang.org/packages/flutter_inner_drawer) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/dnag88) @@ -10,7 +10,7 @@ Inner Drawer is an easy way to create an internal side section (left/right) wher Add this to your package's pubspec.yaml file: ```dart dependencies: - flutter_inner_drawer: "^0.2.1" + flutter_inner_drawer: "^0.2.2" ``` ### New Version 0.1.5 -> 0.2.0 @@ -56,7 +56,23 @@ import 'package:flutter_inner_drawer/inner_drawer.dart'; child: Container(...) ) ), - scaffold: Scaffold(...) or CupertinoPageScaffold(...), // A Scaffold is generally used but you are free to use other widgets + // A Scaffold is generally used but you are free to use other widgets + // Note: use "automaticallyImplyLeading: false" if you do not personalize "leading" of Bar + scaffold: Scaffold( + appBar: AppBar( + automaticallyImplyLeading: false + ) + . + . + ) + or + CupertinoPageScaffold( + navigationBar: CupertinoNavigationBar( + automaticallyImplyLeading: false + ), + . + . + ), ) } diff --git a/lib/inner_drawer.dart b/lib/inner_drawer.dart index 8880011..d8f9633 100644 --- a/lib/inner_drawer.dart +++ b/lib/inner_drawer.dart @@ -30,17 +30,8 @@ enum InnerDrawerAnimation } -// Mobile: -// Width = Screen width − 56 dp -// Maximum width: 320dp -// Maximum width applies only when using a left nav. When using a right nav, -// the panel can cover the full width of the screen. - -// Desktop/Tablet: -// Maximum width for a left nav is 400dp. -// The right nav can vary depending on content. - -const double _kWidth = 304.0; +//width before initState +const double _kWidth = 400; const double _kMinFlingVelocity = 365.0; const double _kEdgeDragWidth = 20.0; const Duration _kBaseSettleDuration = Duration(milliseconds: 246); @@ -105,12 +96,17 @@ class InnerDrawerState extends State with SingleTickerProviderState { ColorTween _color = ColorTween(begin: Colors.transparent, end: Colors.black54); + + double _initWidth = _kWidth; + Orientation _orientation = Orientation.portrait; @override void initState() { super.initState(); - + + _updateWidth(); + _controller = AnimationController(duration: _kBaseSettleDuration, vsync: this) ..addListener(_animationChanged) ..addStatusListener(_animationStatusChanged); @@ -133,6 +129,7 @@ class InnerDrawerState extends State with SingleTickerProviderState setState(() { // The animation controller's state is our build state, and it changed already. }); + if(widget.colorTransition!=null) _color = ColorTween (begin: Colors.transparent, end: widget.colorTransition); else @@ -188,7 +185,7 @@ class InnerDrawerState extends State with SingleTickerProviderState void _handleDragDown(DragDownDetails details) { _controller.stop(); - _ensureHistoryEntry(); + //_ensureHistoryEntry(); } @@ -209,10 +206,19 @@ class InnerDrawerState extends State with SingleTickerProviderState double get _width { - final RenderBox box = _drawerKey.currentContext?.findRenderObject(); - if (box != null && box.size!= null) - return box.size.width; - return _kWidth; // drawer not being shown currently + return _initWidth; + } + + /// get width of screen after initState + void _updateWidth() + { + WidgetsBinding.instance.addPostFrameCallback((_){ + final RenderBox box = _drawerKey.currentContext?.findRenderObject(); + if (box != null && box.size!= null) + setState(() { + _initWidth = box.size.width; + }); + }); } @@ -238,7 +244,7 @@ class InnerDrawerState extends State with SingleTickerProviderState _controller.value += delta; break; } - //print(_cont?.currentContext?.size); + final bool opened = _controller.value > 0.5 ? true : false; if (opened != _previouslyOpened && widget.innerDrawerCallback != null) widget.innerDrawerCallback(opened); @@ -384,6 +390,11 @@ class InnerDrawerState extends State with SingleTickerProviderState Widget build(BuildContext context) { //assert(debugCheckHasMaterialLocalizations(context)); + + // initialize the correct width + if(_initWidth == 400 || MediaQuery.of(context).orientation != _orientation) + _updateWidth(); + _orientation = MediaQuery.of(context).orientation; double offset = widget.offset ?? 0.4; double wFactor = _controller.value; @@ -434,7 +445,7 @@ class InnerDrawerState extends State with SingleTickerProviderState ), ///Gradient Container( - width: _controller.value==0 ? 0: null, + width: _controller.value==0 || widget.animationType == InnerDrawerAnimation.linear ? 0: null, color: _color.evaluate(_controller), ), Align( @@ -462,8 +473,6 @@ class InnerDrawerState extends State with SingleTickerProviderState child: Stack( overflow: Overflow.visible, children: [ - ///Scaffold - widget.scaffold, /// Is displayed only when the Linear Animation is in progress, i have not found other ways /// I adopted this technique because it seemed the only possible one @@ -475,7 +484,9 @@ class InnerDrawerState extends State with SingleTickerProviderState child: (_controller.value==0)? null: widget.child, ) ) : null, - /// + + ///Scaffold + widget.scaffold, ].where((a) => a != null ).toList(), ) diff --git a/pubspec.lock b/pubspec.lock index 224c7bb..6b83eb8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -60,6 +60,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.2" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.0" quiver: dependency: transitive description: @@ -78,7 +85,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.5.4" stack_trace: dependency: transitive description: @@ -106,14 +113,14 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.1" + version: "0.2.2" typed_data: dependency: transitive description: @@ -129,4 +136,4 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.0.0 <3.0.0" + dart: ">=2.1.1-dev.0.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index bad661f..8e1ccf3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inner_drawer description: Inner Drawer is an easy way to create an internal side section (left/right) where you can insert a list menu or other. -version: 0.2.1 +version: 0.2.2 author: Antonino Di Natale homepage: https://github.com/Dn-a/flutter_inner_drawer