Flutter动画行在小于子元素的框中溢出

huangapple go评论82阅读模式
英文:

Flutter animated Row overflow inside box smaller than a child

问题

以下是翻译好的部分:

Overflow error (溢出错误)

How can this be avoided? (如何避免这个问题?)

This is code (这是代码):

英文:

There is a box in which I need to animate a child consisting of a Row in which there are two Text. (In short - running line). Both texts in the result must be on the same line.

The child I want to animate is wider than the parent anyway and when animating, an overflow error pops up.

Overflow error

Flutter动画行在小于子元素的框中溢出

How can this be avoided?

This is code:

  1. final Widget content = SizedBox(
  2. child: Row(
  3. mainAxisAlignment: MainAxisAlignment.start,
  4. children: [
  5. Text('TEXT 1'),
  6. Text('TEXT 2')
  7. ],
  8. ),
  9. );
  10. @override
  11. Widget build(BuildContext context) {
  12. return
  13. Container(
  14. alignment: Alignment.center,
  15. width: widget.parentWidth,
  16. height: UI_SIZE,
  17. child: ClipPath(
  18. clipBehavior: Clip.hardEdge,
  19. child: SlideTransition(
  20. position: _offsetAnimation,
  21. child: content,
  22. ),
  23. ),
  24. );
  25. }

答案1

得分: 0

I was able to fix it with OverflowBox.

  1. final Widget content = OverflowBox(
  2. maxWidth: double.infinity,
  3. child: Row(
  4. mainAxisAlignment: MainAxisAlignment.start,
  5. children: [
  6. Text('TEXT 1'),
  7. Text('TEXT 2')
  8. ],
  9. ),
  10. );

Maybe someone will help this solution.

英文:

I was able to fix it with OverflowBox.

  1. final Widget content = OverflowBox(
  2. maxWidth: double.infinity,
  3. child: Row(
  4. mainAxisAlignment: MainAxisAlignment.start,
  5. children: [
  6. Text('TEXT 1'),
  7. Text('TEXT 2')
  8. ],
  9. ),
  10. );

Maybe someone will help this solution

答案2

得分: 0

以下是您要翻译的内容:

  1. 尝试这个
  2. final Widget content = SizedBox(
  3. child: Row(
  4. mainAxisAlignment: MainAxisAlignment.start,
  5. children: [
  6. Expanded(child: Text('文本 1'),),
  7. Expanded(child: Text('文本 2'),),
  8. ],
  9. ),
  10. );
英文:

try this

  1. final Widget content = SizedBox(
  2. child: Row(
  3. mainAxisAlignment: MainAxisAlignment.start,
  4. children: [
  5. Expanded(child: Text('TEXT 1'),),
  6. Expanded(child: Text('TEXT 2'),),
  7. ],
  8. ),
  9. );

huangapple
  • 本文由 发表于 2023年2月9日 01:47:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75389806.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定