gpt4 book ai didi

flutter - 如何在 flutter DataTable DataCell 中添加列小部件?

转载 作者:行者123 更新时间:2023-12-05 06:57:46 25 4
gpt4 key购买 nike

DataTable DataCell 中小部件的高度可以变化:

 DataCell(Text('Professor\nProfessor\nProfessor\nProfessor\nProfessor\nProfessor\n'))

enter image description here

但是如果您将数据添加为列,单元格就会溢出。为什么?以及如何解决?

 DataRow(
cells: <DataCell>[
DataCell(Text('Janine')),
DataCell(Text('43')),
DataCell(Column(mainAxisSize: MainAxisSize.min, children: [
Text("Professor"),
Text("Professor"),
Text("Professor"),
Text("Professor"),
])),
// DataCell(Text('Professor\nProfessor\nProfessor\nProfessor\nProfessor\nProfessor\n')),
],
),

enter image description here

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

/// This is the main application widget.
class MyApp extends StatelessWidget {
static const String _title = 'Flutter Code Sample';

@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: MyStatelessWidget(),
),
);
}
}

/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget {
MyStatelessWidget({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return DataTable(
columns: const <DataColumn>[
DataColumn(
label: Text(
'Name',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
DataColumn(
label: Text(
'Age',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
DataColumn(
label: Text(
'Role',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
],
rows: <DataRow>[
DataRow(
cells: <DataCell>[
DataCell(Text('Sarah')),
DataCell(Text('19')),
DataCell(Text('Student')),
],
),
DataRow(
cells: <DataCell>[
DataCell(Text('Janine')),
DataCell(Text('43')),
DataCell(Column(mainAxisSize: MainAxisSize.min, children: [
Text("Professor"),
Text("Professor"),
Text("Professor"),
Text("Professor"),
])),
// DataCell(Text('Professor\nProfessor\nProfessor\nProfessor\nProfessor\nProfessor\n')),
],
),
DataRow(
cells: <DataCell>[
DataCell(Text('William')),
DataCell(Text('27')),
DataCell(Text('Associate Professor')),
],
),
],
);
}
}

最佳答案

您需要使用 SingleChildScrollView 包装您的列。这是我的解决方案。

DataCell(Expanded(
child: SingleChildScrollView(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Text("Professor"),
Text("Professor"),
Text("Professor"),
Text("Professor"),
]),
),
))

关于flutter - 如何在 flutter DataTable DataCell 中添加列小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64829910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com