首页 > 解决方案 > 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;
  }
}

标签: flutterdartflutter-layoutflutter-animation

解决方案


我想你已经解决了这个问题,但以防万一其他人发现这篇文章,这里是解决方案。

return Scaffold(
      **resizeToAvoidBottomInset: false,**
      body: SafeArea(
  

该属性将避免移动。


推荐阅读