dart - SingleChildScrollView 底部溢出 42 像素

标签 dart flutter

我在 SingleChildScrollView 中使用了一个表单,一切正常:

表格: 一切正常, enter image description here

这段代码我用过

@override
  Widget build(BuildContext context) {
    double stackHeight = MediaQuery.of(context).size.height/4;
    double width = MediaQuery.of(context).size.width;
    return Scaffold(
      body: SingleChildScrollView(
        child :SafeArea(
          child: Container(
            decoration: BoxDecoration(
                gradient: LinearGradient(
                    begin: Alignment.topLeft,
                    end: Alignment.bottomRight,
                    colors: [const Color(0xFF3023AE), const Color(0xFFC86DD7)])),
            child: Column(
              children: <Widget>[
                Container(
                  height: stackHeight*2.6,
                  child: IntroViewsFlutter(
                    pages,
                    onTapDoneButton: (){
                      Navigator.pop(context);
                    },
                    showSkipButton: false,
                    pageButtonsColor: btnColors,
                  ),
                ),
                Container(
                    height: stackHeight*1.4,
                    child: bottomHomePage(),
                    color: pageColor,
                    width: width,
                ),
              ],
            ),
          )
      ),
      )
    );

但是当出现错误时,会发生以下情况:

enter image description here

我尝试了很多东西,我听说过 layoutBuilder,但不知道它是否适合我,或者是否有其他解决方案可以适应运行时事件。

更新: 问题仅在于在列内使用扩展:这里我们又是代码:

 @override
  Widget build(BuildContext context) {
      return SafeArea(
        child: Scaffold(
            body: SingleChildScrollView(
              child: Center (
                child: Container(
                    decoration: BoxDecoration(
                        gradient: LinearGradient(
                            begin: Alignment.topLeft,
                            end: Alignment.bottomRight,
                            colors: [const Color(0xFF3023AE), const Color(0xFFC86DD7)])),
                    child: Form(
                      key: _formKey,
                      child: Column(
                        children: <Widget>[
                          Padding(
                            padding: const EdgeInsets.only(top: 70.0, bottom: 20.0),
                            child: Text(
                              "C'est parti !",
                              style: TextStyle(fontSize: 32, color: Colors.white),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(bottom: 8.0),
                            child: Container(
                                width: width_textFormField + 15.0,
                                child: Text(
                                  " Avant de commencer, sache que pour utiliser pleinement ta BanKids tu devras demander à tes parents de s'inscrire pour te débloquer toutes les fonctionnalités",
                                  style: TextStyle(
                                    fontSize: 14,
                                    color: Colors.white,
                                  ),
                                  textAlign: TextAlign.center,
                                )),
                          ),
                          Container(
                              alignment: Alignment.center,
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Container(
                                    child: Text(
                                      "Client Bank ?",
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold,
                                          color: Colors.white),
                                    ),
                                  ),
                                  Container(
                                      child: Row(
                                        children: <Widget>[
                                          Text(
                                            "Oui",
                                            style: TextStyle(color: Colors.white),
                                          ),
                                          Radio(
                                            value: 1,
                                            activeColor: Colors.white,
                                            groupValue: _grpVal,
                                            onChanged: _handleRadioValueChange1,
                                          ),
                                        ],
                                      )),
                                  Container(
                                      child: Row(
                                        children: <Widget>[
                                          Text(
                                            "Non",
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.white),
                                          ),
                                          Radio(
                                            activeColor: Colors.white,
                                            value: 2,
                                            groupValue: _grpVal,
                                            onChanged: _handleRadioValueChange1,
                                          ),
                                        ],
                                      )),
                                ],
                              )),
                          Container(
                            child: Column(
                              children: <Widget>[
                                customizedTextFormField(
                                    hintText: "Nom",
                                    width: width_textFormField + 10.0,
                                    txtColor: Colors.black),
                                customizedTextFormField(
                                    hintText: "Prénom",
                                    width: width_textFormField + 10.0,
                                    txtColor: Colors.black),
                                customizedTextFormField(
                                    hintText: "Date de Naissance",
                                    width: width_textFormField + 10.0,
                                    txtColor: Colors.black),
                                customizedTextFormField(
                                    hintText: "CIN",
                                    width: width_textFormField + 10.0,
                                    txtColor: Colors.black),
                                customizedTextFormField(
                                    hintText: "Email",
                                    width: width_textFormField + 10.0,
                                    txtColor: Colors.black)
                              ],
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(top: 8.0),
                            child: Container(
                              width: width_textFormField,
                              child: Row(
                                children: <Widget>[
                                  Checkbox(
                                    checkColor: Color(0xFF3023AE),
                                    value: isCheck,
                                    activeColor: Colors.white,
                                    onChanged: _handleCheckBox,
                                  ),
                                  Expanded(
                                    child: Text(
                                      "En continuant l'inscription, je déclare accepter ces conditions d'utilisations ",
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                          //************ next work
                         Container(
                                  width: 200,
                                  height: 60,
                                  margin: EdgeInsets.only(right: 8.0,bottom: 8.0),
                                  alignment: Alignment.center,
                                  child: new Row(
                                    children: <Widget>[
                                      Button_with_icon(
                                        backgroundColor: Color(0xFF7CB342),
                                        textColor: Colors.white,
                                        textButton: "Continuer",
                                        onPressed: (){
                                          if(_formKey.currentState.validate()){
                                            print("say l3adab");
                                          }
                                        },
                                        icon: Icon(Icons.arrow_forward_ios),
                                      ),
                                    ],
                                  )
                         ),
                        ],
                      ),
                    )),
              ),
            )
        ),
      );

最佳答案

问题只是在我的表单中使用了扩展,所以我已经删除并删除了我给容器的高度和宽度:

@override
  Widget build(BuildContext context) {
      return SafeArea(
        child: Scaffold(
            body: SingleChildScrollView(
              child: Center (
                child: Container(
                    decoration: BoxDecoration(
                        gradient: LinearGradient(
                            begin: Alignment.topLeft,
                            end: Alignment.bottomRight,
                            colors: [const Color(0xFF3023AE), const Color(0xFFC86DD7)])),
                    child: Form(
                      key: _formKey,
                      child: Column(
                        children: <Widget>[
                          Padding(
                            padding: const EdgeInsets.only(top: 70.0, bottom: 20.0),
                            child: Text(
                              "C'est parti !",
                              style: TextStyle(fontSize: 32, color: Colors.white),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(bottom: 8.0),
                            child: Container(
                                width: width_textFormField + 15.0,
                                child: Text(
                                  " Avant de commencer, sache que pour utiliser pleinement ta BanKids tu devras demander à tes parents de s'inscrire pour te débloquer toutes les fonctionnalités",
                                  style: TextStyle(
                                    fontSize: 14,
                                    color: Colors.white,
                                  ),
                                  textAlign: TextAlign.center,
                                )),
                          ),
                          Container(
                              alignment: Alignment.center,
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Container(
                                    child: Text(
                                      "Client Bank ?",
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold,
                                          color: Colors.white),
                                    ),
                                  ),
                                  Container(
                                      child: Row(
                                        children: <Widget>[
                                          Text(
                                            "Oui",
                                            style: TextStyle(color: Colors.white),
                                          ),
                                          Radio(
                                            value: 1,
                                            activeColor: Colors.white,
                                            groupValue: _grpVal,
                                            onChanged: _handleRadioValueChange1,
                                          ),
                                        ],
                                      )),
                                  Container(
                                      child: Row(
                                        children: <Widget>[
                                          Text(
                                            "Non",
                                            style: TextStyle(
                                                fontWeight: FontWeight.bold,
                                                color: Colors.white),
                                          ),
                                          Radio(
                                            activeColor: Colors.white,
                                            value: 2,
                                            groupValue: _grpVal,
                                            onChanged: _handleRadioValueChange1,
                                          ),
                                        ],
                                      )),
                                ],
                              )),
                          Container(
                            child: Column(
                              children: <Widget>[
                                customizedTextFormField(
                                    hintText: "Nom",
                                    width: width_textFormField + 10.0,
                                    txtColor: Colors.black),
                                customizedTextFormField(
                                    hintText: "Prénom",
                                    width: width_textFormField + 10.0,
                                    txtColor: Colors.black),
                                customizedTextFormField(
                                    hintText: "Date de Naissance",
                                    width: width_textFormField + 10.0,
                                    txtColor: Colors.black),
                                customizedTextFormField(
                                    hintText: "CIN",
                                    width: width_textFormField + 10.0,
                                    txtColor: Colors.black),
                                customizedTextFormField(
                                    hintText: "Email",
                                    width: width_textFormField + 10.0,
                                    txtColor: Colors.black)
                              ],
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(top: 8.0),
                            child: Container(
                              width: width_textFormField,
                              child: Row(
                                children: <Widget>[
                                  Checkbox(
                                    checkColor: Color(0xFF3023AE),
                                    value: isCheck,
                                    activeColor: Colors.white,
                                    onChanged: _handleCheckBox,
                                  ),
                                  Expanded(
                                    child: Text(
                                      "En continuant l'inscription, je déclare accepter ces conditions d'utilisations ",
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                          //************ next work
                         Container(
                                  width: 200,
                                  height: 60,
                                  margin: EdgeInsets.only(right: 8.0,bottom: 8.0),
                                  alignment: Alignment.center,
                                  child: new Row(
                                    children: <Widget>[
                                      Button_with_icon(
                                        backgroundColor: Color(0xFF7CB342),
                                        textColor: Colors.white,
                                        textButton: "Continuer",
                                        onPressed: (){
                                          if(_formKey.currentState.validate()){
                                            print("say l3adab");
                                          }
                                        },
                                        icon: Icon(Icons.arrow_forward_ios),
                                      ),
                                    ],
                                  )
                         ),
                        ],
                      ),
                    )),
              ),
            )
        ),
      );

关于dart - SingleChildScrollView 底部溢出 42 像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55864913/

相关文章:

dart - pub全局激活命令-$ HOME/.pub-cache/bin不在路径上

flutter gen-l10n 与 l10n.yaml

google-maps - 如何模拟 'google_maps_flutter' 包进行 flutter 测试?

firebase - 如何从Firebase Flutter中提取带有流的嵌套引用

flutter - Dart/Flutter 中 Money 的数据类型

flutter - https ://api. flutter.dev 中记录的小部件的发行版本是什么?例如动画网格在哪里?

android - 在 flutter 应用程序中添加启动画面的正确方法是什么?

Flutter 移动应用程序中的 Python 和 Dart 集成

flutter - Flutter 中小部件从屏幕外滑动?类似于 Android 8 应用程序抽屉

firebase - 如何阅读 Firebase 文档