Space between Column's children in Flutter

后端 未结 14 1017
刺人心
刺人心 2021-02-02 04:33

I have a Column widget with two TextField widgets as children and I want to have some space between both of them.

I already tried mainAxi

14条回答
  •  爱一瞬间的悲伤
    2021-02-02 05:30

    You can also use a helper function to add spacing after each child.

    List childrenWithSpacing({
      @required List children,
      double spacing = 8,
    }) {
      final space = Container(width: spacing, height: spacing);
      return children.expand((widget) => [widget, space]).toList();
    }
    

    So then, the returned list may be used as a children of a column

    Column(
      children: childrenWithSpacing(
        spacing: 14,
        children: [
          Text('This becomes a text with an adjacent spacing'),
          if (true == true) Text('Also, makes it easy to add conditional widgets'),
        ],
      ),
    );
    

    I'm not sure though if it's wrong or have a performance penalty to run the children through a helper function for the same goal?

提交回复
热议问题