flutter - Flutter 自定义画家和键盘问题
问题描述
我创建了一个 Painter 类,它应该在屏幕上绘制一个弧线,但是当键盘聚焦在 TextField 上时它会被提升。删除SingleChildScrollView
解决了这个问题,但它显示了 n 个像素的溢出问题。也尝试过resizeToAvoidBottomInset
,但它不会让我滚动查看所有字段。
这是一个快速预览: Custom Painter 随键盘浮动
页面类
return Scaffold(
body: SafeArea(
child: CustomPaint(
painter: SmallSunRiseCurvePainter(),
child: _isLoading
? Center(
child: MCircularProgressIndicator(),
)
: SingleChildScrollView(
child: Container(
width: size.width,
height: size.height,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 100),
_buildCreateNewAccountText(),
Padding(
padding: EdgeInsets.all(40),
child: Form(
key: registerFormKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildNameField(),
SizedBox(height: 40),
_buildEmailField(),
SizedBox(height: 40),
_buildSpecialKeyField(),
SizedBox(height: 40),
_buildPasswordField(),
SizedBox(height: 40),
_buildReEnterPasswordField(),
SizedBox(height: 60),
_buildRegisterButton(auth, context),
],
),
),
),
],
),
),
),
),
),
);
}
画家班
class SmallSunRiseCurvePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint();
paint.color = Color(AppConstants.yellowHex);
paint.style = PaintingStyle.fill;
final path = Path()
..moveTo(0, size.height * 0.95)
..quadraticBezierTo(
size.width * 0.5, size.height * 0.9, size.width, size.height * 0.95)
..lineTo(size.width, size.height)
..lineTo(0, size.height);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
解决方案
我想你已经解决了这个问题,但以防万一其他人发现这篇文章,这里是解决方案。
return Scaffold(
**resizeToAvoidBottomInset: false,**
body: SafeArea(
该属性将避免移动。
推荐阅读
- python - 在重定向页面上显示上次上传的文件详细信息 - Django
- speech-recognition - 如何从 microsoft-cognitive 中的单个音频文件中识别多个扬声器
- firebase - Flutter Profile Matching App - Cloud Firestore 数据建模 | 如何查询以避免对已经刷过的 UID 进行不必要的读取
- python - QWidget 在布局分配时变得不可见
- javascript - 根据js确认执行按钮onclick动作
- javascript - 如何使用url将base64中的PDF保存在数据库中?
- javascript - Javascript:对产品选项组合的平面数组进行分组和嵌套
- typescript - Typescript VueJs Webpack 在 Firefox 调试器中与我的组件混淆
- html - 如何使用 flexbox 构建布局?(浮动:左|右)
- computer-vision - 从 Maskrcnn 中移除 Mask 分支