diff --git a/lib/src/cupertino_attachable_controller.dart b/lib/src/cupertino_attachable_controller.dart index c7bcc97..e7faae0 100644 --- a/lib/src/cupertino_attachable_controller.dart +++ b/lib/src/cupertino_attachable_controller.dart @@ -28,4 +28,10 @@ class CupertinoAttachableController implements KeyboardAttachableController { final reverseSimulation = SpringSimulation(_spring, 1, 0, -_springVelocity); return _controller.animateWith(reverseSimulation); } + + @override + void dispose() { + _controller.dispose(); + _controller = null; + } } diff --git a/lib/src/keyboard_attachable.dart b/lib/src/keyboard_attachable.dart index 67aece4..d3d0bbe 100644 --- a/lib/src/keyboard_attachable.dart +++ b/lib/src/keyboard_attachable.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:flutter/physics.dart'; +import 'package:keyboard_attachable/src/cupertino_attachable_controller.dart'; +import 'package:keyboard_attachable/src/keyboard_attachable_controller.dart'; import 'package:keyboard_visibility/keyboard_visibility.dart'; class KeyboardAttachable extends StatefulWidget { @@ -11,31 +12,23 @@ class KeyboardAttachable extends StatefulWidget { final Widget child; @override - _KeyboardAttachableState createState() => - _KeyboardAttachableState(); + _KeyboardAttachableState createState() => _KeyboardAttachableState(); } class _KeyboardAttachableState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; + KeyboardAttachableController _controller; double _bottomSize; @override void initState() { _bottomSize = 0; - _controller = AnimationController(vsync: this); - final spring = SpringDescription(mass: 8, stiffness: 1, damping: 4.5); - final fwSimulation = SpringSimulation(spring, 0, 1, 10); - final revSimulation = SpringSimulation(spring, 1, 0, -10); + _controller = CupertinoAttachableController(vsync: this); KeyboardVisibilityNotification().addNewListener( - onShow: () { - WidgetsBinding.instance.addPostFrameCallback((_) { - _controller.animateWith(fwSimulation); - }); - }, - onHide: () { - _controller.animateWith(revSimulation); - } + onShow: () => WidgetsBinding.instance.addPostFrameCallback( + (_) => _controller.forward(), + ), + onHide: () => _controller.reverse(), ); super.initState(); } @@ -48,13 +41,19 @@ class _KeyboardAttachableState extends State children: [ widget.child, SizeTransition( - sizeFactor: _controller, + sizeFactor: _controller.animation, child: SizedBox(height: _bottomSize), ), ], ); } + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + void _shouldUpdateBottomSize(BuildContext context) { final bottomInsets = MediaQuery.of(context).viewInsets.bottom; if (bottomInsets != 0) { diff --git a/lib/src/keyboard_attachable_controller.dart b/lib/src/keyboard_attachable_controller.dart index 1b5d5ed..8c5611a 100644 --- a/lib/src/keyboard_attachable_controller.dart +++ b/lib/src/keyboard_attachable_controller.dart @@ -6,4 +6,6 @@ abstract class KeyboardAttachableController { TickerFuture forward(); TickerFuture reverse(); + + void dispose(); } \ No newline at end of file