Skip to content

Instantly share code, notes, and snippets.

@kherel
Last active August 28, 2020 06:55
Show Gist options
  • Save kherel/3560f68668fec6273ee957ad3a84878c to your computer and use it in GitHub Desktop.
Save kherel/3560f68668fec6273ee957ad3a84878c to your computer and use it in GitHub Desktop.
TableColumnWidth example
/// example for https://stackoverflow.com/questions/63627339/flutter-table-layout-is-not-responding-according-to-expected
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
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(
body: Column(
children: [
Padding(
padding: EdgeInsets.all(40),
child: MyHomePage(),
),
],
),
),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({
Key key,
}) : super(key: key);
final List<List<String>> data = [
[
'VerylongstringwithnospacesVerylongstringwithnospaces',
'VerylongstringwithnospacesVerylongstringwithnospaces'
],
['abc', '123456789'],
['abcdefg', '123'],
];
@override
Widget build(BuildContext context) {
return Table(
border: TableBorder.all(color: Colors.red),
columnWidths: {
// IntrinsicColumnWidth(),
0: MinColumnWidth(
FixedColumnWidth(100),
IntrinsicColumnWidth(),
),
},
children: data
.map<TableRow>((x) => (TableRow(
children: <TableCell>[
TableCell(
child: Container(
padding: EdgeInsets.only(right: 20),
child: Text(
x[0],
softWrap: true,
))),
TableCell(
child: Container(
color: Colors.green,
child: Text(x[1]),
),
),
],
)))
.toList(),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment