Разверните AnimatedContainer до его дочернего элемента - PullRequest
0 голосов
/ 11 марта 2020

У меня есть AnimatedContainer, который может изменять свою высоту чернильницей с помощью onTap. Причина в том, что Контейнер должен показывать все TextSpans RichText. Моя проблема в том, что я понятия не имею, как получить высоту гибкого onTap. Если я добавлю больше TextSpans, мне придется редактировать высоту в Inkwell, чтобы установить новую высоту. Я хочу, чтобы контейнер показывал ВСЕ TextSpans.

class NotificationAnimated extends StatefulWidget {
  @override
  _NotificationAnimatedState createState() => _NotificationAnimatedState();
}

class _NotificationAnimatedState extends State<NotificationAnimated> {
  double customHeight = 72;
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        setState(() {
          if (customHeight == 72) {
            customHeight = 169;
            historyRed(customHeight);
          } else
            customHeight = 72;
        });
      }, 
      child: AnimatedContainer(
        duration: Duration(milliseconds: 250),
        width: 323,
        height: customHeight,
        margin: EdgeInsets.only(bottom: 10),
        color: Color(0xff2e2e2e),
        child: Row(
          children: <Widget>[
            historyRed(customHeight),
            Container(
              width: 43,
              height: 23,
              margin:
                  EdgeInsets.only(left: 20, top: 13, bottom: customHeight - 36),
              child: Text(
                '$time',
                style: TextStyle(
                  fontSize: 18,
                  fontFamily: "AssistantLight",
                  color: Color(0xffffffff),
                ),
              ),
            ),
            ConstrainedBox(
              constraints: BoxConstraints(minHeight: 46),
              child: Container(
                width: 240,
                margin: EdgeInsets.only(left: 15, bottom: 13, top: 13),
                height: customHeight,
                child: text,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

var text = RichText(
  text: TextSpan(
    style: TextStyle(
      fontSize: 18.0,
      fontFamily: "AssistantLight",
      color: Color(0xffffffff),
    ),
    children: <TextSpan>[
      TextSpan(
        text: 'Max Mustermann\nLOCKDOWN\n',
        style: TextStyle(fontFamily: "AssistantSemiBold"),
      ),
      TextSpan(text: 'Bürotür\n'),
      TextSpan(text: 'Zwischentür\n'),
      TextSpan(text: 'Haustür\n'),
      TextSpan(text: 'Garagentür'),
    ],
  ),
);
...