简体   繁体   English

如何修复颤振中的大小错误?

[英]How can I fix size errors in flutter?

I have 4 fields and with the standard behavior, just when I went to this page, everything is fine.我有 4 个字段和标准行为,就在我转到此页面时,一切都很好。 But when you click on the last field, it shows that there is not enough size, I want to make it scroll so that it would be visible what you enter.但是当您单击最后一个字段时,它显示没有足够的大小,我想让它滚动以便您输入的内容可见。 But I get an infinite size error, I don't know how to handle it.但是我收到一个无限大小的错误,我不知道如何处理。 Can anyone help?任何人都可以帮忙吗? it is desirable to have an example and, if possible, documentation to understand why this is happening...最好有一个例子,如果可能的话,有文档来理解为什么会发生这种情况......

import 'package:flutter/material.dart';
import 'package:testdb/models/cart.dart';
import 'package:testdb/widgets/cart_list_item.dart';
import 'package:provider/provider.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_masked_text/flutter_masked_text.dart';

class Order extends StatefulWidget {
  @override
  _OrderState createState() => _OrderState();
}

class _OrderState extends State<Order> {
  // String _name = "Tom";
  final _controllerName = TextEditingController();
  final _controllerAdr = TextEditingController();
  final _controllerCom = TextEditingController();
  final _controllerPhone = new MaskedTextController(mask: '+000(00)000-00-00');

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    _controllerName.dispose();
    _controllerPhone.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final cartData = context.watch<CartDataProvider>();
    return SingleChildScrollView(
        child:Scaffold(
        appBar: AppBar(
          title: Text('t'),
        ),
        body: Padding(
            padding: EdgeInsets.only(top: 50, left: 20, right: 20),
            child: Column(
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.only(bottom: 50),
                  child: Text("t",
                      style: TextStyle(
                        fontSize: 26,
                        fontWeight: FontWeight.bold,
                      )),
                ),
                TextFormField(
                    validator: (value) {
                      if (value == null || value.isEmpty) {
                        return 't';
                      }
                      return null;
                    },
                    decoration: InputDecoration(
                        hintText: "t",
                        labelText: "t",
                        icon: Icon(Icons.person)),
                    style: TextStyle(fontSize: 22),
                    controller: _controllerName),

                TextFormField(
                    validator: (value) {
                      if (value == null || value.isEmpty || value.length < 12) {
                        return 't';
                      }
                      return null;
                    },
                    decoration: InputDecoration(
                      hintText: "333",
                      labelText: "t",
                      icon: Icon(Icons.phone),
                    ),
                    style: TextStyle(fontSize: 22),
                    keyboardType: TextInputType.number,
                    controller: _controllerPhone),
                TextFormField(
                    validator: (value) {
                      if (value == null || value.isEmpty) {
                        return 't';
                      }
                      return null;
                    },
                    decoration: InputDecoration(
                        hintText: "t",
                        labelText: "t",
                        icon: Icon(Icons.home)),
                    style: TextStyle(fontSize: 22),
                    controller: _controllerAdr),
                TextFormField(
                    validator: (value) {
                      if (value == null || value.isEmpty) {
                        return 't';
                      }
                      return null;
                    },
                    maxLines: null,
                    keyboardType: TextInputType.multiline,
                    decoration: InputDecoration(
                        hintText: "t",
                        labelText: "test",
                        icon: Icon(Icons.message)),
                    style: TextStyle(fontSize: 22),
                    controller: _controllerCom),
                Padding(
                  padding: EdgeInsets.only(top: 50),
                  child:ElevatedButton(
                      child: Text("test"),
                      onPressed: () {
                        var text = '''
                      Test order
                      ${_controllerName.text}
                      ${_controllerPhone.text}
                      ${_controllerAdr.text}
                      ${_controllerAdr.text}
                      ${cartData.toString()}
                      ''';
                        var response = http.get(Uri.parse(
                            ''));
                      })
                )

              ],
            ))));
  }
}

在此处输入图片说明

import 'package:flutter/material.dart';
import 'package:testdb/models/cart.dart';
import 'package:testdb/widgets/cart_list_item.dart';
import 'package:provider/provider.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_masked_text/flutter_masked_text.dart';

class Order extends StatefulWidget {
  @override
  _OrderState createState() => _OrderState();
}

class _OrderState extends State<Order> {
  // String _name = "Tom";
  final _controllerName = TextEditingController();
  final _controllerAdr = TextEditingController();
  final _controllerCom = TextEditingController();
  final _controllerPhone = new MaskedTextController(mask: '+000(00)000-00-00');

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    _controllerName.dispose();
    _controllerPhone.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final cartData = context.watch<CartDataProvider>();
    return Scaffold(
        appBar: AppBar(
          title: Text('t'),
        ),
        body: SingleChildScrollView(
          child: Padding(
              padding: EdgeInsets.only(top: 50, left: 20, right: 20),
              child: Column(
                children: <Widget>[
                  Padding(
                    padding: EdgeInsets.only(bottom: 50),
                    child: Text("t",
                        style: TextStyle(
                          fontSize: 26,
                          fontWeight: FontWeight.bold,
                        )),
                  ),
                  TextFormField(
                      validator: (value) {
                        if (value == null || value.isEmpty) {
                          return 't';
                        }
                        return null;
                      },
                      decoration: InputDecoration(
                          hintText: "t",
                          labelText: "t",
                          icon: Icon(Icons.person)),
                      style: TextStyle(fontSize: 22),
                      controller: _controllerName),

                  TextFormField(
                      validator: (value) {
                        if (value == null || value.isEmpty || value.length < 12) {
                          return 't';
                        }
                        return null;
                      },
                      decoration: InputDecoration(
                        hintText: "333",
                        labelText: "t",
                        icon: Icon(Icons.phone),
                      ),
                      style: TextStyle(fontSize: 22),
                      keyboardType: TextInputType.number,
                      controller: _controllerPhone),
                  TextFormField(
                      validator: (value) {
                        if (value == null || value.isEmpty) {
                          return 't';
                        }
                        return null;
                      },
                      decoration: InputDecoration(
                          hintText: "t",
                          labelText: "t",
                          icon: Icon(Icons.home)),
                      style: TextStyle(fontSize: 22),
                      controller: _controllerAdr),
                  TextFormField(
                      validator: (value) {
                        if (value == null || value.isEmpty) {
                          return 't';
                        }
                        return null;
                      },
                      maxLines: null,
                      keyboardType: TextInputType.multiline,
                      decoration: InputDecoration(
                          hintText: "t",
                          labelText: "test",
                          icon: Icon(Icons.message)),
                      style: TextStyle(fontSize: 22),
                      controller: _controllerCom),
                  Padding(
                      padding: EdgeInsets.only(top: 50),
                      child:ElevatedButton(
                          child: Text("test"),
                          onPressed: () {
                            var text = '''
                    Test order
                    ${_controllerName.text}
                    ${_controllerPhone.text}
                    ${_controllerAdr.text}
                    ${_controllerAdr.text}
                    ${cartData.toString()}
                    ''';
                            var response = http.get(Uri.parse(
                                ''));
                          })
                  )

                ],
              )),
        ));
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM