Skip to content

Commit

Permalink
feat(scrollbars): draggable vertical scrollbar
Browse files Browse the repository at this point in the history
New settings to control scrollbars appearance.
Draggable vertical scrollbar functionality with CupertinoScrollbar widget
regardless of target platform (optionally)
  • Loading branch information
ASGAlex committed Nov 7, 2020
1 parent 870ed88 commit 9124bce
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/pluto_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:async';
import 'dart:developer' as developer;
import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
Expand Down
47 changes: 47 additions & 0 deletions lib/src/pluto_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class PlutoConfiguration {

final PlutoGridLocaleText localeText;

/// Customise scrollbars for desktop usage
final PlutoScrollbarConfig scrollbarConfig;

PlutoConfiguration({
this.enableColumnBorder = false,
this.gridBackgroundColor = Colors.white,
Expand All @@ -75,6 +78,7 @@ class PlutoConfiguration {
this.enableMoveDownAfterSelecting = true,
this.enterKeyAction = PlutoEnterKeyAction.EditingAndMoveDown,
this.localeText = const PlutoGridLocaleText(),
this.scrollbarConfig = const PlutoScrollbarConfig.noScroll()
});

PlutoConfiguration.dark({
Expand Down Expand Up @@ -102,6 +106,7 @@ class PlutoConfiguration {
this.enableMoveDownAfterSelecting = true,
this.enterKeyAction = PlutoEnterKeyAction.EditingAndMoveDown,
this.localeText = const PlutoGridLocaleText(),
this.scrollbarConfig = const PlutoScrollbarConfig.noScroll()
});
}

Expand Down Expand Up @@ -180,3 +185,45 @@ extension PlutoEnterKeyActionExtension on PlutoEnterKeyAction {

bool get isNone => this == null || this == PlutoEnterKeyAction.None;
}

/// Allows to customise scrollbars "look and feel"
/// The general feature is making vertical scrollbar draggable and therefore more useful
/// for desktop systems. Set [draggableScrollbar] to true to achieve this behavior. Also
/// changing [isAlwaysShown] to true is recommended for more usability at desktops
///
/// Unfortunately, horizontal scrollbar still will not be draggable, it seems like
/// framework limitation
class PlutoScrollbarConfig {
PlutoScrollbarConfig({
this.draggableScrollbar = false,
this.isAlwaysShown = false,
Radius scrollbarRadius,
Radius scrollbarRadiusWhileDragging,
double scrollbarThickness,
double scrollbarThicknessWhileDragging})
: this.scrollbarThickness = scrollbarThickness ??
(draggableScrollbar ? (CupertinoScrollbar.defaultThickness) : 6.0),
this.scrollbarRadius = scrollbarRadius ??
(draggableScrollbar ? (CupertinoScrollbar.defaultRadius) : null),
this.scrollbarThicknessWhileDragging = scrollbarThicknessWhileDragging ??
CupertinoScrollbar.defaultThicknessWhileDragging,
this.scrollbarRadiusWhileDragging =
scrollbarRadiusWhileDragging ?? CupertinoScrollbar.defaultRadiusWhileDragging;

const PlutoScrollbarConfig.noScroll()
: draggableScrollbar= false,
isAlwaysShown = false,
scrollbarRadius= CupertinoScrollbar.defaultRadius,
scrollbarRadiusWhileDragging= CupertinoScrollbar.defaultRadiusWhileDragging,
scrollbarThickness= null,
scrollbarThicknessWhileDragging= CupertinoScrollbar.defaultThicknessWhileDragging;

/// Force use Cupertino scrollbars regardless of target platform.
final bool draggableScrollbar;
final bool isAlwaysShown;

final double scrollbarThickness;
final double scrollbarThicknessWhileDragging;
final Radius scrollbarRadius;
final Radius scrollbarRadiusWhileDragging;
}
58 changes: 37 additions & 21 deletions lib/src/ui/body_rows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,45 @@ class _BodyRowsState extends State<BodyRows> {

@override
Widget build(BuildContext context) {
return Scrollbar(
child: SingleChildScrollView(
controller: horizontalScroll,
scrollDirection: Axis.horizontal,
child: SizedBox(
width: _width,
child: ListView.builder(
controller: verticalScroll,
scrollDirection: Axis.vertical,
itemCount: _rows.length,
itemExtent: PlutoDefaultSettings.rowTotalHeight,
itemBuilder: (ctx, i) {
return RowWidget(
key: ValueKey('body_row_${_rows[i]._key}'),
stateManager: widget.stateManager,
rowIdx: i,
row: _rows[i],
columns: _columns,
);
},
),
final body = SingleChildScrollView(
controller: horizontalScroll,
scrollDirection: Axis.horizontal,
child: SizedBox(
width: _width,
child: ListView.builder(
controller: verticalScroll,
scrollDirection: Axis.vertical,
itemCount: _rows.length,
itemExtent: PlutoDefaultSettings.rowTotalHeight,
itemBuilder: (ctx, i) {
return RowWidget(
key: ValueKey('body_row_${_rows[i]._key}'),
stateManager: widget.stateManager,
rowIdx: i,
row: _rows[i],
columns: _columns,
);
},
),
),
);

if (widget.stateManager.configuration.scrollbarConfig.draggableScrollbar) {
return CupertinoScrollbar(
child: body,
isAlwaysShown: widget.stateManager.configuration.scrollbarConfig.isAlwaysShown,
controller: verticalScroll,
thickness: widget.stateManager.configuration.scrollbarConfig.scrollbarThickness,
thicknessWhileDragging: widget
.stateManager.configuration.scrollbarConfig.scrollbarThicknessWhileDragging,
radius: widget.stateManager.configuration.scrollbarConfig.scrollbarRadius,
radiusWhileDragging: widget
.stateManager.configuration.scrollbarConfig.scrollbarRadiusWhileDragging);
}
return Scrollbar(
thickness: widget.stateManager.configuration.scrollbarConfig.scrollbarThickness,
radius: widget.stateManager.configuration.scrollbarConfig.scrollbarRadius,
child: body,
);
}
}

0 comments on commit 9124bce

Please sign in to comment.