class _PagTabItemState extends State {
final GlobalKey _pagKey = GlobalKey();
@OverRide
void initState() {
super.initState();
}
@OverRide
void didUpdateWidget(PagTabItem oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isSelected != oldWidget.isSelected) {
_handleAnimation();
}
}
void _handleAnimation() {
if (widget.isLoop) return;
final state = _pagKey.currentState;
if (state == null) return;
if (widget.isSelected) {
state.setProgress(0);
state.start();
} else {
state.stop();
state.setProgress(0);
}
}
void _onPagInit() {
if (widget.isSelected && !widget.isLoop) {
final state = _pagKey.currentState;
state?.setProgress(1);
}
}
@OverRide
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onTap,
behavior: HitTestBehavior.opaque,
child: SizedBox(
width: widget.width,
height: widget.height,
child: IgnorePointer(
child: PAGView.asset(
widget.assetPath,
key: _pagKey,
width: widget.width,
height: widget.height,
repeatCount:
widget.isLoop
? PAGView.REPEAT_COUNT_LOOP
: PAGView.REPEAT_COUNT_DEFAULT,
initProgress: 0,
autoPlay: widget.isLoop,
onInit: _onPagInit,
),
),
),
);
}
}
class _PagTabItemState extends State {
final GlobalKey _pagKey = GlobalKey();
@OverRide
void initState() {
super.initState();
}
@OverRide
void didUpdateWidget(PagTabItem oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.isSelected != oldWidget.isSelected) {
_handleAnimation();
}
}
void _handleAnimation() {
if (widget.isLoop) return;
final state = _pagKey.currentState;
if (state == null) return;
}
void _onPagInit() {
if (widget.isSelected && !widget.isLoop) {
final state = _pagKey.currentState;
state?.setProgress(1);
}
}
@OverRide
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onTap,
behavior: HitTestBehavior.opaque,
child: SizedBox(
width: widget.width,
height: widget.height,
child: IgnorePointer(
child: PAGView.asset(
widget.assetPath,
key: _pagKey,
width: widget.width,
height: widget.height,
repeatCount:
widget.isLoop
? PAGView.REPEAT_COUNT_LOOP
: PAGView.REPEAT_COUNT_DEFAULT,
initProgress: 0,
autoPlay: widget.isLoop,
onInit: _onPagInit,
),
),
),
);
}
}