flutter 自定义控件不能放输入框

本人初学flutter ,今天要自定义一个输入框控件,结果遇到一个奇怪的问题,自定义的空间框里,不能放入输入框,放入就报错,代码如下,是不是哪里冲突里?

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class SearchTextInput extends StatelessWidget {
@override
Widget build(BuildContext context) {

// TODO: implement build
return Container(
  height: 20,
  decoration:
      BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(5))),
  child: Row(
    mainAxisSize: MainAxisSize.max,
    mainAxisAlignment: MainAxisAlignment.center,
    crossAxisAlignment: CrossAxisAlignment.center,
    children: <Widget>[
      Container(
        decoration: BoxDecoration(
            border:
                Border(right: BorderSide(color: Colors.black, width: 1))),
        child: Row(
          children: <Widget>[Text("北京"), Icon(Icons.arrow_drop_down)],
        ),
      ),
      Padding(
        padding: EdgeInsets.only(
          left: 5,
        ),

// child: Text("---sssssssssssssssssssssssssssss"), //这行代码可以

        child: TextField( ), //这行代码不行
      ),
    ],
  ),
);

}
}

直接只放一个输入框,没有问题,一旦放了布局控件,就报错,错误内容:

Performing hot reload...
Syncing files to device Android SDK built for x86...
I/flutter (15752): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (15752): The following assertion was thrown during performLayout():
I/flutter (15752): BoxConstraints forces an infinite width.
I/flutter (15752): These invalid constraints were provided to RenderRepaintBoundary's layout() function by the
I/flutter (15752): following function, which probably computed the invalid constraints in question:
I/flutter (15752): _RenderDecoration._layout.layoutLineBox (package:flutter/src/material/input_decorator.dart:815:11)
I/flutter (15752): The offending constraints were:
I/flutter (15752): BoxConstraints(w=Infinity, 0.0<=h<=120.0)

环境: window 10 家庭版,
代码位置: https://github.com/alvin19876...

希望有大神指点一下

阅读 3.8k
2 个回答
新手上路,请多包涵
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题