Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/resizable_widget.dart
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Provide [ResizableWidget].
library resizable_widget;

export 'src/resizable_widget.dart' show ResizableWidget, OnResizedFunc;
export 'src/resizable_widget.dart' show ResizableWidget, OnResizeBeginFunc, OnResizedFunc, OnResizeEndFunc;
export 'src/widget_size_info.dart' show WidgetSizeInfo;
16 changes: 11 additions & 5 deletions lib/src/resizable_widget.dart
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:flutter/material.dart';
import 'package:resizable_widget/src/resizable_widget_args_info.dart';
import 'resizable_widget_args_info.dart';
import 'resizable_widget_child_data.dart';
import 'resizable_widget_controller.dart';
import 'separator.dart';
import 'widget_size_info.dart';

/// The callback argument type of [ResizableWidget.onResized].
typedef OnResizedFunc = void Function(List<WidgetSizeInfo> infoList);
typedef OnResizeBeginFunc = void Function(int separatorIndex, DragDownDetails details);
typedef OnResizeEndFunc = void Function(int separatorIndex, DragEndDetails details);

/// Holds resizable widgets as children.
/// Users can resize the internal widgets by dragging.
Expand Down Expand Up @@ -48,23 +50,27 @@ class ResizableWidget extends StatefulWidget {
/// Note that [onResized] is called every frame when resizing [children].
final OnResizedFunc? onResized;

final OnResizeBeginFunc? onResizeBegin;

final OnResizeEndFunc? onResizeEnd;

/// Creates [ResizableWidget].
ResizableWidget({
Key? key,
required this.children,
this.percentages,
@Deprecated('Use [isHorizontalSeparator] instead')
this.isColumnChildren = false,
@Deprecated('Use [isHorizontalSeparator] instead') this.isColumnChildren = false,
this.isHorizontalSeparator = false,
this.isDisabledSmartHide = false,
this.separatorSize = 4,
this.separatorColor = Colors.white12,
this.onResized,
this.onResizeBegin,
this.onResizeEnd,
}) : super(key: key) {
assert(children.isNotEmpty);
assert(percentages == null || percentages!.length == children.length);
assert(percentages == null ||
percentages!.reduce((value, element) => value + element) == 1);
assert(percentages == null || percentages!.reduce((value, element) => value + element) == 1);
}

@override
Expand Down
6 changes: 5 additions & 1 deletion lib/src/resizable_widget_args_info.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class ResizableWidgetArgsInfo {
final bool isDisabledSmartHide;
final double separatorSize;
final Color separatorColor;
final OnResizeBeginFunc? onResizeBegin;
final OnResizedFunc? onResized;
final OnResizeEndFunc? onResizeEnd;

ResizableWidgetArgsInfo(ResizableWidget widget)
: children = widget.children,
Expand All @@ -20,5 +22,7 @@ class ResizableWidgetArgsInfo {
isDisabledSmartHide = widget.isDisabledSmartHide,
separatorSize = widget.separatorSize,
separatorColor = widget.separatorColor,
onResized = widget.onResized;
onResized = widget.onResized,
onResizeBegin = widget.onResizeBegin,
onResizeEnd = widget.onResizeEnd;
}
Empty file modified lib/src/resizable_widget_child_data.dart
100644 → 100755
Empty file.
15 changes: 13 additions & 2 deletions lib/src/resizable_widget_controller.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class ResizableWidgetController {
final ResizableWidgetModel _model;
List<ResizableWidgetChildData> get children => _model.children;

ResizableWidgetController(ResizableWidgetArgsInfo info)
: _model = ResizableWidgetModel(info) {
ResizableWidgetController(ResizableWidgetArgsInfo info) : _model = ResizableWidgetModel(info) {
_model.init(_separatorFactory);
}

Expand All @@ -21,13 +20,25 @@ class ResizableWidgetController {
_model.callOnResized();
}

void resizeStart(int separatorIndex, DragDownDetails details) {
_model.resizeStart(separatorIndex, details);
eventStream.add(this);
_model.callResizedBegin(separatorIndex, details);
}

void resize(int separatorIndex, Offset offset) {
_model.resize(separatorIndex, offset);

eventStream.add(this);
_model.callOnResized();
}

void resizeEnd(int separatorIndex, DragEndDetails details) {
_model.resizeEnd(separatorIndex, details);
eventStream.add(this);
_model.callResizedEnd(separatorIndex, details);
}

void tryHideOrShow(int separatorIndex) {
final result = _model.tryHideOrShow(separatorIndex);

Expand Down
28 changes: 20 additions & 8 deletions lib/src/resizable_widget_model.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ class ResizableWidgetModel {
void init(SeparatorFactory separatorFactory) {
final originalChildren = _info.children;
final size = originalChildren.length;
final originalPercentages =
_info.percentages ?? List.filled(size, 1 / size);
final originalPercentages = _info.percentages ?? List.filled(size, 1 / size);
for (var i = 0; i < size - 1; i++) {
children.add(ResizableWidgetChildData(
originalChildren[i], originalPercentages[i]));
children.add(ResizableWidgetChildData(originalChildren[i], originalPercentages[i]));
children.add(ResizableWidgetChildData(
separatorFactory.call(SeparatorArgsBasicInfo(
2 * i + 1,
Expand Down Expand Up @@ -62,6 +60,10 @@ class ResizableWidgetModel {
}
}

void resizeStart(int separatorIndex, DragDownDetails details) {
_info.onResizeBegin?.call(separatorIndex, details);
}

void resize(int separatorIndex, Offset offset) {
final leftSize = _resizeImpl(separatorIndex - 1, offset);
final rightSize = _resizeImpl(separatorIndex + 1, offset * (-1));
Expand Down Expand Up @@ -92,11 +94,21 @@ class ResizableWidgetModel {
}
}

void resizeEnd(int separatorIndex, DragEndDetails details) {
_info.onResizeEnd?.call(separatorIndex, details);
}

void callResizedBegin(int separatorIndex, DragDownDetails details) {
_info.onResizeBegin?.call(separatorIndex, details);
}

void callOnResized() {
_info.onResized?.call(children
.where((x) => x.widget is! Separator)
.map((x) => WidgetSizeInfo(x.size!, x.percentage!))
.toList());
_info.onResized?.call(
children.where((x) => x.widget is! Separator).map((x) => WidgetSizeInfo(x.size!, x.percentage!)).toList());
}

void callResizedEnd(int separatorIndex, DragEndDetails details) {
_info.onResizeEnd?.call(separatorIndex, details);
}

bool tryHideOrShow(int separatorIndex) {
Expand Down
2 changes: 2 additions & 0 deletions lib/src/separator.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class _SeparatorState extends State<Separator> {
height: _info.isHorizontalSeparator ? _info.size : double.infinity,
),
),
onPanDown: (details) => _controller.onPanStart(details),
onPanUpdate: (details) => _controller.onPanUpdate(details, context),
onPanEnd: (details) => _controller.onPanEnd(details),
onDoubleTap: () => _controller.onDoubleTap(),
);
}
Empty file modified lib/src/separator_args_info.dart
100644 → 100755
Empty file.
8 changes: 8 additions & 0 deletions lib/src/separator_controller.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ class SeparatorController {

const SeparatorController(this._index, this._parentController);

void onPanStart(DragDownDetails details) {
_parentController.resizeStart(_index, details);
}

void onPanUpdate(DragUpdateDetails details, BuildContext context) {
_parentController.resize(_index, details.delta);
}

void onPanEnd(DragEndDetails details) {
_parentController.resizeEnd(_index, details);
}

void onDoubleTap() {
_parentController.tryHideOrShow(_index);
}
Expand Down
Empty file modified lib/src/widget_size_info.dart
100644 → 100755
Empty file.