由于容器的子项不起作用而导致行颤动

问题描述

我有以下有效的代码。但是,当我在以下代码中将Column替换为Row时,出现错误Horizontal RenderFlex with multiple children has a null textDirection,so the layout order is undefined.

  Widget build(BuildContext context) {
    return new Container(
      color: Colors.red,child: Column(
        children: <Widget>[
          Container(
            width: 100,height: 100,color: Colors.white,),Container(
            width: 100,color: Colors.black,color: Colors.blue,],)
    );
  }

以下代码会产生错误

  Widget build(BuildContext context) {
    return new Container(
      color: Colors.red,child: Row(
        children: <Widget>[
          ...,...,)
    );
  }

解决方法

行需要textDirection进行如下设置。

Row(
  textDirection: TextDirection.ltr,children: [...],)