From 121edc42ed442ffb0e9ed41da6f8474beddcf362 Mon Sep 17 00:00:00 2001 From: Rezaul Islam Date: Thu, 4 Jan 2024 15:52:34 +0600 Subject: [PATCH] Fix runtime issue Update changelog --- CHANGELOG.md | 4 ++ README.md | 2 +- lib/MotionTabBar.dart | 112 +++++++++++++++++++++--------------------- 3 files changed, 62 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b099c4..11a4f4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.0.4] + +* Fix flutter run time issue + ## [2.0.3] * Support RTL diff --git a/README.md b/README.md index 205ad5c..7b75385 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Add the plugin: ```yaml dependencies: - motion_tab_bar: ^2.0.3 + motion_tab_bar: ^2.0.4 ``` ## Basic Usage diff --git a/lib/MotionTabBar.dart b/lib/MotionTabBar.dart index 3ae289f..59858b1 100644 --- a/lib/MotionTabBar.dart +++ b/lib/MotionTabBar.dart @@ -67,6 +67,7 @@ class _MotionTabBarState extends State with TickerProviderStateMix IconData? activeIcon; String? selectedTab; + bool isRtl = false; List? badges; Widget? activeBadge; @@ -87,72 +88,73 @@ class _MotionTabBarState extends State with TickerProviderStateMix super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) async { - bool isRtl = Directionality.of(context).index == 0; - if(widget.controller != null) { - widget.controller!.onTabChange= (index) { - setState(() { - activeIcon = widget.icons![index]; - selectedTab = widget.labels[index]; - }); - _initAnimationAndStart(_positionAnimation.value, getPosition(isRtl)); - }; - } - labels = widget.labels; - icons = Map.fromIterable( - labels, - key: (label) => label, - value: (label) => widget.icons![labels.indexOf(label)], - ); + isRtl = Directionality.of(context).index == 0; + }); - selectedTab = widget.initialSelectedTab; - activeIcon = icons[selectedTab]; + if(widget.controller != null) { + widget.controller!.onTabChange= (index) { + setState(() { + activeIcon = widget.icons![index]; + selectedTab = widget.labels[index]; + }); + _initAnimationAndStart(_positionAnimation.value, getPosition(isRtl)); + }; + } + labels = widget.labels; + icons = Map.fromIterable( + labels, + key: (label) => label, + value: (label) => widget.icons![labels.indexOf(label)], + ); - // init badge text - int selectedIndex = labels.indexWhere((element) => element == widget.initialSelectedTab); - activeBadge = (widget.badges != null && widget.badges!.length > 0) ? widget.badges![selectedIndex] : null; + selectedTab = widget.initialSelectedTab; + activeIcon = icons[selectedTab]; - _animationController = AnimationController( - duration: Duration(milliseconds: ANIM_DURATION), - vsync: this, - ); + // init badge text + int selectedIndex = labels.indexWhere((element) => element == widget.initialSelectedTab); + activeBadge = (widget.badges != null && widget.badges!.length > 0) ? widget.badges![selectedIndex] : null; - _fadeOutController = AnimationController( - duration: Duration(milliseconds: (ANIM_DURATION ~/ 5)), - vsync: this, - ); + _animationController = AnimationController( + duration: Duration(milliseconds: ANIM_DURATION), + vsync: this, + ); - _positionTween = Tween(begin: getPosition(isRtl), end: 1); + _fadeOutController = AnimationController( + duration: Duration(milliseconds: (ANIM_DURATION ~/ 5)), + vsync: this, + ); - _positionAnimation = _positionTween.animate(CurvedAnimation(parent: _animationController, curve: Curves.easeOut)) - ..addListener(() { - setState(() {}); - }); + _positionTween = Tween(begin: getPosition(isRtl), end: 1); - _fadeFabOutAnimation = Tween(begin: 1, end: 0) - .animate(CurvedAnimation(parent: _fadeOutController, curve: Curves.easeOut)) - ..addListener(() { - setState(() { - fabIconAlpha = _fadeFabOutAnimation.value; - }); - }) - ..addStatusListener((AnimationStatus status) { - if (status == AnimationStatus.completed) { - setState(() { - activeIcon = icons[selectedTab]; - int selectedIndex = labels.indexWhere((element) => element == selectedTab); - activeBadge = (widget.badges != null && widget.badges!.length > 0) ? widget.badges![selectedIndex] : null; - }); - } - }); + _positionAnimation = _positionTween.animate(CurvedAnimation(parent: _animationController, curve: Curves.easeOut)) + ..addListener(() { + setState(() {}); + }); - _fadeFabInAnimation = Tween(begin: 0, end: 1) - .animate(CurvedAnimation(parent: _animationController, curve: Interval(0.8, 1, curve: Curves.easeOut))) - ..addListener(() { + _fadeFabOutAnimation = Tween(begin: 1, end: 0) + .animate(CurvedAnimation(parent: _fadeOutController, curve: Curves.easeOut)) + ..addListener(() { + setState(() { + fabIconAlpha = _fadeFabOutAnimation.value; + }); + }) + ..addStatusListener((AnimationStatus status) { + if (status == AnimationStatus.completed) { setState(() { - fabIconAlpha = _fadeFabInAnimation.value; + activeIcon = icons[selectedTab]; + int selectedIndex = labels.indexWhere((element) => element == selectedTab); + activeBadge = (widget.badges != null && widget.badges!.length > 0) ? widget.badges![selectedIndex] : null; }); + } + }); + + _fadeFabInAnimation = Tween(begin: 0, end: 1) + .animate(CurvedAnimation(parent: _animationController, curve: Interval(0.8, 1, curve: Curves.easeOut))) + ..addListener(() { + setState(() { + fabIconAlpha = _fadeFabInAnimation.value; }); - }); + }); } @override