Skip to content

Commit

Permalink
Merge pull request #14 from devoncarew/headers_toolbar_params
Browse files Browse the repository at this point in the history
add showHeaders and showToolbars params
  • Loading branch information
devoncarew authored Jul 1, 2023
2 parents 7d4a277 + 3e445f4 commit e9804b1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.4.0

* Add a `showHeaders` parameter to `VTable`.
* Add a `showToolbar` parameter to `VTable`.
* Improve the display of the table in dark themes.

## 0.3.1

* Use the `Theme.dividerColor` color to separate rows.
Expand Down
58 changes: 43 additions & 15 deletions lib/vtable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class VTable<T> extends StatefulWidget {
/// system clipboard.
final bool includeCopyToClipboardAction;

/// Whether to show column headers.
final bool showHeaders;

/// Whether to show a table toolbar.
final bool showToolbar;

/// Construct a new `VTable` instance.
///
/// E.g:
Expand Down Expand Up @@ -110,6 +116,8 @@ class VTable<T> extends StatefulWidget {
this.tooltipDelay = defaultTooltipDelay,
this.rowHeight = defaultRowHeight,
this.includeCopyToClipboardAction = false,
this.showHeaders = true,
this.showToolbar = true,
Key? key,
}) : super(key: key);

Expand Down Expand Up @@ -167,16 +175,16 @@ class _VTableState<T> extends State<VTable<T>> {
Widget build(BuildContext context) {
return Column(
children: [
createActionRow(context),
const Divider(),
if (widget.showToolbar) createActionRow(context),
if (widget.showToolbar) const Divider(),
Expanded(
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
Map<VTableColumn, double> colWidths = _layoutColumns(constraints);

return Column(
children: [
createHeaderRow(colWidths),
if (widget.showHeaders) createHeaderRow(colWidths),
Expanded(
child: createRowsListView(context, colWidths),
),
Expand Down Expand Up @@ -246,6 +254,9 @@ class _VTableState<T> extends State<VTable<T>> {
border: Border(top: BorderSide(color: theme.dividerColor)),
);

final colorScheme = theme.colorScheme;
final darkMode = colorScheme.brightness == Brightness.dark;

return ListView.builder(
controller: scrollController,
itemCount: sortedItems.length,
Expand All @@ -260,7 +271,9 @@ class _VTableState<T> extends State<VTable<T>> {
onTap: () => _select(item),
onDoubleTap: () => _doubleTap(item),
child: DecoratedBox(
decoration: rowSeparator,
decoration: (widget.showHeaders || index != 0)
? rowSeparator
: const BoxDecoration(),
child: Row(
children: [
for (var column in columns)
Expand All @@ -278,7 +291,9 @@ class _VTableState<T> extends State<VTable<T>> {
horizontal: VTable._horizPadding,
vertical: VTable._vertPadding,
),
color: column.validate(item)?.colorForSeverity,
color: column
.validate(item)
?.colorForSeverity(darkMode: darkMode),
child: column.widgetFor(context, item),
),
),
Expand Down Expand Up @@ -573,16 +588,29 @@ class ValidationResult {
factory ValidationResult.info(String message) =>
ValidationResult(message, Severity.info);

Color get colorForSeverity {
switch (severity) {
case Severity.info:
return Colors.grey.shade400.withAlpha(127);
case Severity.note:
return Colors.blue.shade200.withAlpha(127);
case Severity.warning:
return Colors.yellow.shade200.withAlpha(127);
case Severity.error:
return Colors.red.shade300.withAlpha(127);
Color colorForSeverity({bool darkMode = true}) {
if (darkMode) {
switch (severity) {
case Severity.info:
return Colors.grey.shade400;
case Severity.note:
return Colors.blue.shade400;
case Severity.warning:
return Colors.yellow.shade700;
case Severity.error:
return Colors.red.shade400;
}
} else {
switch (severity) {
case Severity.info:
return Colors.grey.shade400.withAlpha(127);
case Severity.note:
return Colors.blue.shade200.withAlpha(127);
case Severity.warning:
return Colors.yellow.shade200.withAlpha(127);
case Severity.error:
return Colors.red.shade300.withAlpha(127);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: vtable
description: >-
A Flutter table widget featuring virtualization, sorting, and custom cell
rendering.
version: 0.3.1
version: 0.4.0
repository: https://github.com/devoncarew/vtable

topics:
- widgets

environment:
sdk: ^3.0.0
flutter: '>=1.17.0'
flutter: '>=3.10.0'

dependencies:
flutter:
Expand Down

0 comments on commit e9804b1

Please sign in to comment.