35 lines
951 B
Dart
35 lines
951 B
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// 只让输入区响应键盘高度,避免整棵页面随 MediaQuery 反复重建。
|
|
class KeyboardLift extends StatelessWidget {
|
|
final Widget child;
|
|
|
|
const KeyboardLift({super.key, required this.child});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final bottom = MediaQuery.viewInsetsOf(context).bottom;
|
|
return Padding(
|
|
padding: EdgeInsets.only(bottom: bottom),
|
|
child: child,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 只移动已有前景图层,不在键盘动画期间重新布局子组件。
|
|
class KeyboardTranslate extends StatelessWidget {
|
|
final Widget child;
|
|
|
|
const KeyboardTranslate({super.key, required this.child});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final bottom = MediaQuery.viewInsetsOf(context).bottom;
|
|
return Transform.translate(
|
|
offset: Offset(0, -bottom),
|
|
transformHitTests: true,
|
|
child: RepaintBoundary(child: child),
|
|
);
|
|
}
|
|
}
|