【问题标题】:Flutter Custom Painter and Keyboard IssueFlutter 自定义画家和键盘问题
【发布时间】:2020-06-22 16:31:40
【问题描述】:

我创建了一个 Painter 类,它应该在屏幕上绘制一条弧线,但当键盘聚焦在 TextField 上时它会升高。删除了 SingleChildScrollView 解决了这个问题,但它显示了 n 像素的溢出问题。还尝试了resizeToAvoidBottomInset,但它不会让我滚动查看所有字段。

这是一个快速预览: Custom Painter floats with the keyboard

页面类

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;
  }
}

【问题讨论】:

    标签: flutter dart flutter-layout flutter-animation


    【解决方案1】:

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

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

    该属性将避免移动。

    【讨论】:

      猜你喜欢
      • 2018-10-23
      • 2022-07-12
      • 2019-01-05
      • 2015-04-24
      • 1970-01-01
      • 2014-11-29
      • 2015-06-11
      • 2017-02-22
      • 1970-01-01
      相关资源
      最近更新 更多