Skip to content

Commit

Permalink
Fix runtime issue
Browse files Browse the repository at this point in the history
Update changelog
  • Loading branch information
therezacuet committed Jan 4, 2024
1 parent 7213785 commit 121edc4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 56 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.0.4]

* Fix flutter run time issue

## [2.0.3]

* Support RTL
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add the plugin:

```yaml
dependencies:
motion_tab_bar: ^2.0.3
motion_tab_bar: ^2.0.4
```
## Basic Usage
Expand Down
112 changes: 57 additions & 55 deletions lib/MotionTabBar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class _MotionTabBarState extends State<MotionTabBar> with TickerProviderStateMix
IconData? activeIcon;
String? selectedTab;

bool isRtl = false;
List<Widget>? badges;
Widget? activeBadge;

Expand All @@ -87,72 +88,73 @@ class _MotionTabBarState extends State<MotionTabBar> 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<double>(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<double>(begin: getPosition(isRtl), end: 1);

_fadeFabOutAnimation = Tween<double>(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<double>(begin: 0, end: 1)
.animate(CurvedAnimation(parent: _animationController, curve: Interval(0.8, 1, curve: Curves.easeOut)))
..addListener(() {
_fadeFabOutAnimation = Tween<double>(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<double>(begin: 0, end: 1)
.animate(CurvedAnimation(parent: _animationController, curve: Interval(0.8, 1, curve: Curves.easeOut)))
..addListener(() {
setState(() {
fabIconAlpha = _fadeFabInAnimation.value;
});
});
});
}

@override
Expand Down

0 comments on commit 121edc4

Please sign in to comment.