diff --git a/example/lib/main.dart b/example/lib/main.dart index b978bca..f6fbb90 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -10,9 +10,26 @@ class Example extends StatelessWidget { resizeToAvoidBottomInset: false, appBar: AppBar(), body: FooterLayout( - body: TextField(), + body: ListView.builder( + itemCount: Colors.primaries.length, + itemBuilder: (_, i) => Container( + height: 88, + color: Colors.primaries[i].withOpacity(0.33), + ), + ), footer: KeyboardAttachable( - child: Text("Testing a label"), + child: Container( + padding: const EdgeInsets.all(16), + color: Colors.blue, + child: TextField( + decoration: InputDecoration( + hintText: "Tap me!", + fillColor: Colors.white, + filled: true, + border: OutlineInputBorder(), + ), + ), + ), ), ), ), diff --git a/lib/src/android_attachable_controller.dart b/lib/src/android_attachable_controller.dart new file mode 100644 index 0000000..07ebf22 --- /dev/null +++ b/lib/src/android_attachable_controller.dart @@ -0,0 +1,35 @@ +import 'package:flutter/animation.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; +import 'package:keyboard_attachable/src/keyboard_attachable_controller.dart'; + +class AndroidAttachableController implements KeyboardAttachableController { + AndroidAttachableController({@required TickerProvider vsync}) { + _controller = AnimationController( + vsync: vsync, + duration: const Duration(milliseconds: 150), + reverseDuration: const Duration(milliseconds: 150), + ); + } + + AnimationController _controller; + + @override + Animation get animation => CurvedAnimation( + parent: _controller, + curve: Cubic(0, 0, 0.2, 1), + reverseCurve: Cubic(0, 0, 1, 0.2), + ); + + @override + void dispose() { + _controller.dispose(); + _controller = null; + } + + @override + TickerFuture forward() => _controller.forward(); + + @override + TickerFuture reverse() => _controller.reverse(); +} diff --git a/lib/src/cupertino_attachable_controller.dart b/lib/src/ios_attachable_controller.dart similarity index 87% rename from lib/src/cupertino_attachable_controller.dart rename to lib/src/ios_attachable_controller.dart index e7faae0..aeb1313 100644 --- a/lib/src/cupertino_attachable_controller.dart +++ b/lib/src/ios_attachable_controller.dart @@ -3,8 +3,8 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/physics.dart'; import 'package:keyboard_attachable/src/keyboard_attachable_controller.dart'; -class CupertinoAttachableController implements KeyboardAttachableController { - CupertinoAttachableController({@required TickerProvider vsync}) +class IOSAttachableController implements KeyboardAttachableController { + IOSAttachableController({@required TickerProvider vsync}) : _spring = SpringDescription(mass: 8, stiffness: 1, damping: 4.5), _springVelocity = 10 { _controller = AnimationController(vsync: vsync); diff --git a/lib/src/keyboard_attachable.dart b/lib/src/keyboard_attachable.dart index d3d0bbe..463889f 100644 --- a/lib/src/keyboard_attachable.dart +++ b/lib/src/keyboard_attachable.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:keyboard_attachable/src/cupertino_attachable_controller.dart'; +import 'package:keyboard_attachable/src/android_attachable_controller.dart'; +import 'package:keyboard_attachable/src/ios_attachable_controller.dart'; import 'package:keyboard_attachable/src/keyboard_attachable_controller.dart'; import 'package:keyboard_visibility/keyboard_visibility.dart'; @@ -23,7 +24,7 @@ class _KeyboardAttachableState extends State @override void initState() { _bottomSize = 0; - _controller = CupertinoAttachableController(vsync: this); + _controller = AndroidAttachableController(vsync: this); KeyboardVisibilityNotification().addNewListener( onShow: () => WidgetsBinding.instance.addPostFrameCallback( (_) => _controller.forward(),