how to match height of a row widget which is tallest among other widgets
我已经定义了一行列小部件,但无法匹配行中定义的其他小部件的高度
我尝试过 Expand 、Intrinsic Height、width、Contrained box,并在每列中定义容器。
预期结果是将高度与父/其他行小部件匹配[在此处输入图像描述][1]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | Widget columnOne(String t1, String t2) { return ClipRRect( borderRadius: BorderRadius.all(Radius.circular(8)), child: Container( color: Colors.white, child: Column( mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.stretch, children: <Widget>[ Container( color: Colors.white, child: Padding( padding: EdgeInsets.fromLTRB(10, 10, 10, 10), child: Align( alignment: Alignment.center, child: Text(t1, style: TextStyle( fontSize: 30, color: Colors.black, backgroundColor: Colors.white, fontFamily: 'FJ',fontWeight: FontWeight.bold )), ) ), ), IntrinsicHeight( child: ConstrainedBox( constraints: const BoxConstraints(minWidth: double.infinity), child: Container( color: Colors.red, child: Padding( padding: EdgeInsets.all(10), child: Align( alignment: Alignment.center, child: Text(t2 , textAlign: TextAlign.center, textWidthBasis: TextWidthBasis.parent, style: TextStyle( fontSize: 16, color: Colors.black, backgroundColor: Colors.red, )), ))), ) ) ], ), ), ); } |
https://i.stack.imgur.com/HfYOl.png
当前结果如果我更改文本/溢出文本
https://i.stack.imgur.com/t9MTK.png
预期
从设计来看,卡底只能是一两行高。
在这种情况下,更容易不依赖自动高度,而是使用固定值。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | import 'package:flutter/material.dart'; import 'package:vector_math/vector_math.dart' as v_math; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: Scaffold( backgroundColor: Colors.black, body: SafeArea( child: RowExample(), ), ), ); } } class RowExample extends StatelessWidget { final List<List<String>> entities = [ ['22', 'fdslfdssdf'], ['22', 'sdfdssf fd fasdf '], ['3242', 'sdsf'], ]; @override Widget build(BuildContext context) { return Row( children: entities.map((item) => columnOne(item[0], item[1])).toList(), ); } Widget columnOne(String t1, String t2) { return ClipRRect( borderRadius: BorderRadius.all(Radius.circular(8)), child: Container( height: 130, width: 100, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(8)), color: Colors.white, ), child: Column( children: <Widget>[ Container( height: 70, color: Colors.white, child: Padding( padding: EdgeInsets.fromLTRB(10, 10, 10, 10), child: Align( alignment: Alignment.center, child: Text(t1, style: TextStyle( fontSize: 30, color: Colors.black, backgroundColor: Colors.white, fontFamily: 'FJ', fontWeight: FontWeight.bold)), )), ), Expanded( child: Container( color: Colors.red, child: Padding( padding: EdgeInsets.all(10), child: Align( alignment: Alignment.center, child: Text(t2, textAlign: TextAlign.center, textWidthBasis: TextWidthBasis.parent, style: TextStyle( fontSize: 16, color: Colors.black, backgroundColor: Colors.red, )), ))), ) ], ), ), ); } } |