Я думаю, это происходит из-за того, как Row
естественным образом работает. Требуется столько, сколько доступно горизонтальной оси. Хотя mainAxisSize
можно настроить (мин. Или макс.) В соответствии с дочерними параметрами, DataTable
не имеет начальной ширины, поэтому Text
не переносится.
Для быстрого исправления вы можете обернуть Data Table
in Container
и задайте ему постоянную ширину.
Быстрый тест на DartPad: https://dartpad.dev/a664a29160b6e0443e9ca3bf28d5ec69
Фрагмент:
class Testing extends StatefulWidget {
Testing({Key key}) : super(key: key);
@override
_MyDataTableState createState() => _MyDataTableState();
}
class _MyDataTableState extends State<Testing> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("DataTable"),
),
body: Row(
children: [
Container(
width: 300, // Give the DataTable a const width.
child: DataTable(
columns: [
DataColumn(
label: Container(
width: 100,
child: Text('Item Code'),
),
),
DataColumn(
label: Text('Stock Item'),
),
],
rows: [
DataRow(
cells: [
DataCell(
Text('Yup. text.'),
),
DataCell(
Wrap(
children: [
Text(
'This is a really long text. It\'s supposed to be long so that I can figure out what in the hell is happening to the ability to have the text wrap in this datacell. So far, I haven\'t been able to figure it out.')
],
),
)
],
),
],
),
)
],
),
);
}
}