Skip to content

Instantly share code, notes, and snippets.

@MarcinusX MarcinusX/price_tab.dart Secret
Created Sep 3, 2018

Embed
What would you like to do?
class _PriceTabState extends State<PriceTab> with TickerProviderStateMixin {
AnimationController _planeSizeAnimationController;
Animation _planeSizeAnimation;
double get _planeTopPadding => widget.height - _initialPlanePaddingBottom - _planeSize;
double get _planeSize => _planeSizeAnimation.value;
@override
void initState() {
super.initState();
_initSizeAnimations();
_planeSizeAnimationController.forward();
}
@override
void dispose() {
_planeSizeAnimationController.dispose();
super.dispose();
}
Widget _buildPlane() {
return Positioned(
top: _planeTopPadding,
child: Column(
children: <Widget>[
AnimatedPlaneIcon(animation: _planeSizeAnimation),
],
),
);
}
_initSizeAnimations() {
_planeSizeAnimationController = AnimationController(
duration: const Duration(milliseconds: 340),
vsync: this,
);
_planeSizeAnimation = Tween<double>(begin: 60.0, end: 36.0).animate(CurvedAnimation(
parent: _planeSizeAnimationController,
curve: Curves.easeOut,
));
}
}
@RizkiDPrast

This comment has been minimized.

Copy link

RizkiDPrast commented Mar 22, 2019

hi @MarcinusX,
i am following your tutorial but get exception after applying code after Not so much for now, let’s add plane size animation. First by adding AnimationController and Animation objects related to the size of the plane.

here is the full code in price_tab.dart currently
`class _PriceTabState extends State with TickerProviderStateMixin {
final double _initialPlanePaddingBottom = 16.0;
AnimationController _planeSizeAnimationController;
Animation _planeSizeAnimation;

double get _planeTopPadding => widget.height - _initialPlanePaddingBottom - _planeSize;

double get _planeSize => _planeSizeAnimation.value; // <=== this line throws 1st exception

@override
void initState() {
super.initState();
_initSizeAnimations();
_planeSizeAnimationController.forward();
}

@override
void dispose() {
_planeSizeAnimationController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
child: Stack(
alignment: Alignment.center,
children: [_buildPlane()],
),
);
}

Widget _buildPlane() {
return Positioned(
top: _planeTopPadding,
child: Column(
children: [
AnimatedPlaneIcon(animation: _planeSizeAnimation),
],
),
);
}

_initSizeAnimations() {
_planeSizeAnimationController = AnimationController(
duration: const Duration(milliseconds: 340),
vsync: this,
);
_planeSizeAnimation = Tween(begin: 60.0, end: 36.0).animate(CurvedAnimation(
parent: _planeSizeAnimationController,
curve: Curves.easeOut,
));
}
}`

and here is the exception
I/flutter (10835): The getter 'value' was called on null. I/flutter (10835): Receiver: null I/flutter (10835): Tried calling: value I/flutter (10835): I/flutter (10835): When the exception was thrown, this was the stack: I/flutter (10835): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5) I/flutter (10835): #1 _PriceTabState._planeSize [...]

im guessing _planeSize was initialized before _planeSizeAnimation initialization

is there any clue what i did wrong?

regards

@RizkiDPrast

This comment has been minimized.

Copy link

RizkiDPrast commented Mar 22, 2019

Sorry to disturb you @MarcinusX. The problem was SOLVED after restarting the app (not just Hot reload it)
I was thinking of deleting my previous post but i will keep it for reference

thank you, your tutorial is amazing !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.