@@ -262,11 +262,15 @@ class DataTable extends StatelessWidget {
262
262
this .sortColumnIndex,
263
263
this .sortAscending = true ,
264
264
this .onSelectAll,
265
+ this .horizontalMargin = 24.0 ,
266
+ this .columnSpacing = 56.0 ,
265
267
@required this .rows,
266
268
}) : assert (columns != null ),
267
269
assert (columns.isNotEmpty),
268
270
assert (sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)),
269
271
assert (sortAscending != null ),
272
+ assert (horizontalMargin != null ),
273
+ assert (columnSpacing != null ),
270
274
assert (rows != null ),
271
275
assert (! rows.any ((DataRow row) => row.cells.length != columns.length)),
272
276
_onlyTextColumn = _initOnlyTextColumn (columns),
@@ -311,6 +315,20 @@ class DataTable extends StatelessWidget {
311
315
/// row is selectable.
312
316
final ValueSetter <bool > onSelectAll;
313
317
318
+ /// The horizontal margin between the edges of the table and the content
319
+ /// in the first and last cells of each row.
320
+ ///
321
+ /// When a checkbox is displayed, it is also the margin between the checkbox
322
+ /// the content in the first data column.
323
+ ///
324
+ /// This value defaults to 24.0 to adhere to the Material Design specifications.
325
+ final double horizontalMargin;
326
+
327
+ /// The horizontal margin between the contents of each data column.
328
+ ///
329
+ /// This value defaults to 56.0 to adhere to the Material Design specifications.
330
+ final double columnSpacing;
331
+
314
332
/// The data to show in each row (excluding the row that contains
315
333
/// the column headings). Must be non-null, but may be empty.
316
334
final List <DataRow > rows;
@@ -351,8 +369,6 @@ class DataTable extends StatelessWidget {
351
369
352
370
static const double _headingRowHeight = 56.0 ;
353
371
static const double _dataRowHeight = 48.0 ;
354
- static const double _tablePadding = 24.0 ;
355
- static const double _columnSpacing = 56.0 ;
356
372
static const double _sortArrowPadding = 2.0 ;
357
373
static const double _headingFontSize = 12.0 ;
358
374
static const Duration _sortArrowAnimationDuration = Duration (milliseconds: 150 );
@@ -368,7 +384,7 @@ class DataTable extends StatelessWidget {
368
384
Widget contents = Semantics (
369
385
container: true ,
370
386
child: Padding (
371
- padding: const EdgeInsetsDirectional .only (start: _tablePadding , end: _tablePadding / 2.0 ),
387
+ padding: EdgeInsetsDirectional .only (start: horizontalMargin , end: horizontalMargin / 2.0 ),
372
388
child: Center (
373
389
child: Checkbox (
374
390
activeColor: color,
@@ -533,7 +549,7 @@ class DataTable extends StatelessWidget {
533
549
534
550
int displayColumnIndex = 0 ;
535
551
if (showCheckboxColumn) {
536
- tableColumns[0 ] = const FixedColumnWidth (_tablePadding + Checkbox .width + _tablePadding / 2.0 );
552
+ tableColumns[0 ] = FixedColumnWidth (horizontalMargin + Checkbox .width + horizontalMargin / 2.0 );
537
553
tableRows[0 ].children[0 ] = _buildCheckbox (
538
554
color: theme.accentColor,
539
555
checked: allChecked,
@@ -554,9 +570,26 @@ class DataTable extends StatelessWidget {
554
570
555
571
for (int dataColumnIndex = 0 ; dataColumnIndex < columns.length; dataColumnIndex += 1 ) {
556
572
final DataColumn column = columns[dataColumnIndex];
573
+
574
+ double paddingStart;
575
+ if (dataColumnIndex == 0 && showCheckboxColumn) {
576
+ paddingStart = horizontalMargin / 2.0 ;
577
+ } else if (dataColumnIndex == 0 && ! showCheckboxColumn) {
578
+ paddingStart = horizontalMargin;
579
+ } else {
580
+ paddingStart = columnSpacing / 2.0 ;
581
+ }
582
+
583
+ double paddingEnd;
584
+ if (dataColumnIndex == columns.length - 1 ) {
585
+ paddingEnd = horizontalMargin;
586
+ } else {
587
+ paddingEnd = columnSpacing / 2.0 ;
588
+ }
589
+
557
590
final EdgeInsetsDirectional padding = EdgeInsetsDirectional .only (
558
- start: dataColumnIndex == 0 ? showCheckboxColumn ? _tablePadding / 2.0 : _tablePadding : _columnSpacing / 2.0 ,
559
- end: dataColumnIndex == columns.length - 1 ? _tablePadding : _columnSpacing / 2.0 ,
591
+ start: paddingStart ,
592
+ end: paddingEnd ,
560
593
);
561
594
if (dataColumnIndex == _onlyTextColumn) {
562
595
tableColumns[displayColumnIndex] = const IntrinsicColumnWidth (flex: 1.0 );
0 commit comments