Skip to content

Commit

Permalink
adds android keyboard animation
Browse files Browse the repository at this point in the history
  • Loading branch information
drogel committed Apr 18, 2020
1 parent 28ebf47 commit 7a27ec6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
21 changes: 19 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
),
),
),
),
),
Expand Down
35 changes: 35 additions & 0 deletions lib/src/android_attachable_controller.dart
Original file line number Diff line number Diff line change
@@ -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<double> 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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions lib/src/keyboard_attachable.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -23,7 +24,7 @@ class _KeyboardAttachableState extends State<KeyboardAttachable>
@override
void initState() {
_bottomSize = 0;
_controller = CupertinoAttachableController(vsync: this);
_controller = AndroidAttachableController(vsync: this);
KeyboardVisibilityNotification().addNewListener(
onShow: () => WidgetsBinding.instance.addPostFrameCallback(
(_) => _controller.forward(),
Expand Down

0 comments on commit 7a27ec6

Please sign in to comment.