Skip to content

Commit

Permalink
Merge pull request #11 from devoncarew/rowHeight
Browse files Browse the repository at this point in the history
make the row height configurable
  • Loading branch information
devoncarew authored May 27, 2023
2 parents cec5624 + 1864b16 commit 4549900
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0

* Make the row height configurable; add a `VTable.rowHeight` parameter.

## 0.2.0

* Add a `includeCopyToClipboardAction` flag.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ const Duration defaultTooltipDelay = Duration(milliseconds: 350);
const double defaultIconSize = 20;
const double defaultSplashRadius = 20;

const toolbarHeight = 32.0;
const double toolbarHeight = 32.0;
const double defaultRowHeight = 42.0;
22 changes: 11 additions & 11 deletions lib/vtable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ typedef OnSelectionChanged<T> = void Function(T? selectedItem);
/// A Flutter table widget featuring virtualization, sorting, and custom cell
/// rendering.
class VTable<T> extends StatefulWidget {
static const double _rowHeight = 42;
static const double _vertPadding = 4;
static const double _horizPadding = 8;

Expand Down Expand Up @@ -61,6 +60,9 @@ class VTable<T> extends StatefulWidget {
/// validators.
final Duration tooltipDelay;

/// The height to use for table rows.
final double rowHeight;

/// Whether to include a 'copy to clipboard' action in the toolbar.
///
/// If included, this action will copy the table's contents as CSV to the
Expand Down Expand Up @@ -106,6 +108,7 @@ class VTable<T> extends StatefulWidget {
this.filterWidgets = const [],
this.actions = const [],
this.tooltipDelay = defaultTooltipDelay,
this.rowHeight = defaultRowHeight,
this.includeCopyToClipboardAction = false,
Key? key,
}) : super(key: key);
Expand Down Expand Up @@ -199,12 +202,7 @@ class _VTableState<T> extends State<VTable<T>> {
}

return Padding(
padding: const EdgeInsets.only(
left: 8,
top: 16,
// right: 8,
// bottom: 8,
),
padding: const EdgeInsets.only(left: 8, top: 16),
child: Row(
children: [
Text(widget.tableDescription ?? ''),
Expand All @@ -230,6 +228,7 @@ class _VTableState<T> extends State<VTable<T>> {
title: column.label,
icon: column.icon,
width: colWidths[column],
height: widget.rowHeight,
alignment: column.alignment,
sortAscending: column == sortColumn ? sortAscending : null,
),
Expand All @@ -246,7 +245,7 @@ class _VTableState<T> extends State<VTable<T>> {
return ListView.builder(
controller: scrollController,
itemCount: sortedItems.length,
itemExtent: VTable._rowHeight,
itemExtent: widget.rowHeight,
itemBuilder: (BuildContext context, int index) {
T item = sortedItems[index];
final selected = item == selectedItem.value;
Expand All @@ -264,7 +263,7 @@ class _VTableState<T> extends State<VTable<T>> {
Padding(
padding: const EdgeInsets.only(top: 1, right: 1),
child: SizedBox(
height: VTable._rowHeight - 1,
height: widget.rowHeight - 1,
width: colWidths[column]! - 1,
child: Tooltip(
message: column.validate(item)?.message ?? '',
Expand Down Expand Up @@ -329,7 +328,6 @@ class _VTableState<T> extends State<VTable<T>> {
if (col.grow > 0) {
var inc = width * (col.grow / totalGrow);
widths[col] = widths[col]! + inc;
// width -= inc;
}
}
}
Expand Down Expand Up @@ -359,13 +357,15 @@ class _VTableState<T> extends State<VTable<T>> {
class _ColumnHeader extends StatelessWidget {
final String title;
final double? width;
final double? height;
final IconData? icon;
final Alignment? alignment;
final bool? sortAscending;

const _ColumnHeader({
required this.title,
required this.width,
required this.height,
this.icon,
this.alignment,
this.sortAscending,
Expand All @@ -377,8 +377,8 @@ class _ColumnHeader extends StatelessWidget {
var swapSortIconSized = alignment != null && alignment!.x > 0;

return SizedBox(
height: VTable._rowHeight,
width: width,
height: height,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: VTable._horizPadding,
Expand Down
5 changes: 4 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ name: vtable
description: >-
A Flutter table widget featuring virtualization, sorting, and custom cell
rendering.
version: 0.2.0
version: 0.3.0
repository: https://github.com/devoncarew/vtable

topics:
- widgets

environment:
sdk: ^3.0.0
flutter: '>=1.17.0'
Expand Down

0 comments on commit 4549900

Please sign in to comment.