RenderFlex 在底部溢出了 103 个像素

时间:2021-06-12 21:17:17

标签: flutter

======== 渲染库捕获的异常============================== RenderFlex 在底部溢出了 103 个像素。 相关的导致错误的小部件是 柱子 lib\...\words\add.dart:61

我应该在代码中更改什么?有什么办法吗?如果您想查看代码,请告诉我我会更新更多

import 'package:flutter/material.dart';
import 'package:quiz2/const/const.dart';
import 'package:quiz2/database/firebase.dart';
import 'package:quiz2/widgets/widgets.dart';

class AddQuestion extends StatefulWidget {

  final String quizId;
  AddQuestion(this.quizId);

  @override
  _AddQuestionState createState() => _AddQuestionState();
}

class _AddQuestionState extends State<AddQuestion> {

  final _formKey = GlobalKey<FormState>();
  String question, option1, option2, option3, option4;
  bool _isLoading = false;
  DatabaseService databaseService = new DatabaseService();

  uploadQuestionData() {
    if(_formKey.currentState.validate()) {

      setState(() {
        _isLoading = true;
      });
      Map<String, String> questionMap = {
        "question" : question,
        "option1" : option1,
        "option2" : option2,
        "option3" : option3,
        "option4" : option4,
      };
         databaseService.addQuestionData(questionMap, widget.quizId).then((value) {
            setState(() {
              _isLoading = false;
            });
         });
      }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
         title: Text("Додати запитання")
      ),
      body: _isLoading ? Container(
        child: Center(child: CircularProgressIndicator(),),
      ) : Form(
        key: _formKey,
        child: Container(
          decoration: BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage('assets/images/word.jpg'),
                      fit: BoxFit.cover,
                    ),
                  ),
          padding: EdgeInsets.symmetric(horizontal: 24),
          child: Column(
            children: [
              SizedBox(
                height: 20,
              ),
              TextFormField(
                validator: (val) =>
                val.isEmpty ? "Введіть запитання" : null,
                decoration: kTextFieldDecoration.copyWith(
                  hintText: "Запитання",
                  prefixIcon: Icon(Icons.question_answer,
                                      color: Colors.white, size: 30)
                ),
                onChanged: (val) {
                  question = val;
                },
              ),
              SizedBox(
                height: 6,
              ),
              TextFormField(
                validator: (val) =>
                val.isEmpty ? "Option1" : null,
                decoration: kTextFieldDecoration.copyWith(
                  hintText: "Варіант 1 (правильна відповідь)",
                  prefixIcon: Icon(Icons.done,
                                      color: Colors.white, size: 30)
                ),
                onChanged: (val) {
                  option1 = val;
                },
              ),
              SizedBox(
                height: 6,
              ),
              TextFormField(
                validator: (val) =>
                val.isEmpty ? "Option2" : null,
                decoration: kTextFieldDecoration.copyWith(
                  hintText: "Варіант 2",
                  prefixIcon: Icon(Icons.backspace_sharp,
                                      color: Colors.white, size: 30)
                ),
                onChanged: (val) {
                  option2 = val;
                },
              ),
              SizedBox(
                height: 6,
              ),
              TextFormField(
                validator: (val) =>
                val.isEmpty ? "Option3" : null,
                decoration: kTextFieldDecoration.copyWith(
                  hintText: "Варіант 3",
                  prefixIcon: Icon(Icons.backspace_sharp,
                                      color: Colors.white, size: 30)
                ),
                onChanged: (val) {
                  option3 = val;
                },
              ),
              SizedBox(
                height: 6,
              ),
              TextFormField(
                validator: (val) =>
                val.isEmpty ? "Option4" : null,
                decoration: kTextFieldDecoration.copyWith(
                  hintText: "Варіант 4",
                  prefixIcon: Icon(Icons.backspace_sharp,
                                      color: Colors.white, size: 30)
                ),
                onChanged: (val) {
                  option4 = val;
                },
              ),
              Spacer(),
              Row(
                children: [
                  GestureDetector(
                    onTap: () {
                      Navigator.pop(context);
                    },
                      child: blueButton(context: context, label: "Готово", buttonWidth: MediaQuery.of(context).size.width/2 - 36)),
                  SizedBox(width: 24,),
                  GestureDetector(
                      onTap: () {
                        uploadQuestionData();
                      },
                      child: blueButton(context: context, label: "Додати ще", buttonWidth: MediaQuery.of(context).size.width/2 - 36)),
                ],
              ),
              SizedBox(height: 60,),
            ],
          ),
        ),
      )
    );
  }
}

enter image description here

我应该在代码中更改什么?有什么办法吗?如果您想查看代码,请告诉我我会更新更多

1 个答案:

答案 0 :(得分:1)

Form 包裹 SingleChildScrollView 小部件

当 Widget 的内容大于其父级的大小时会发生此错误。