Как сделать высоту по содержанию с максимумом во флаттере? - PullRequest
0 голосов
/ 27 апреля 2020

У меня есть экран с некоторыми элементами c и динамическими c частями на нем. Цель, которую я хочу достичь, состоит в том, чтобы минимизировать вопросный раздел в соответствии с содержанием и максимально увеличить его до роста. И затем, когда есть еще вопросы, которые можно было бы показать: контейнер должен иметь максимальный размер.

На самом деле этот вопрос похож на этот в HTML: amp-list с гибкой высотой. до макс.

Упрощенное представление:

Example

Если пробовали несколько подходов. Например, есть Flexables и так далее. Но, похоже, ничего не работает. Один из подходов, если взять, это:

body: Column(
  mainAxisAlignment: MainAxisAlignment.end,
  mainAxisSize: MainAxisSize.min,
  children: <Widget>[
    Container(
      width: MediaQuery.of(context).size.width,
      margin: EdgeInsets.symmetric(vertical: 20),
      padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
      alignment: Alignment.topRight,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
          FlatButton(
            onPressed: () {},
            child: Text('SKIP THE PROCESS'),
          ),
        ],
      ),
    ),
    Container(
      width: MediaQuery.of(context).size.width,
      height: 20,
      padding: EdgeInsets.symmetric(horizontal: 20),
      decoration: BoxDecoration(
        color: BBColors.White100,
        borderRadius: BorderRadius.vertical(
          top: Radius.circular(30),
        ),
        boxShadow: [
          BoxShadow(
              color: BBColors.Black10,
              offset: Offset(0.0, -5.0),
              blurRadius: 5.0,
              spreadRadius: 1.0),
        ],
      ),
    ),
    Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height - 148,
      color: BBColors.White100,
      padding: EdgeInsets.symmetric(horizontal: 20),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Expanded(child: _questions(context)),
        ],
      ),
    ),
  ],
),

_questions(context) просто возвращает Streambuilder с ListView:

return StreamBuilder(
      stream: streamData,
      builder: (BuildContext context, snapshot) {
        if (!snapshot.hasData) return Loading(withScaffold: false);
        return ListView(
          reverse: true,
          children: _questionWidgets).toList(),
        );
      },
    );
...