Skip to content

Commit

Permalink
reformat to 80 line length
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp committed May 11, 2018
1 parent 5db6fc9 commit d0edb65
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
9 changes: 6 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class _MyHomePageState extends State<MyHomePage> {

final draggedItem = _items[draggingIndex];
setState(() {
debugPrint("Reordering " + item.toString() + " -> " + newPosition.toString());
debugPrint(
"Reordering " + item.toString() + " -> " + newPosition.toString());
_items.removeAt(draggingIndex);
_items.insert(newPositionIndex, draggedItem);
});
Expand Down Expand Up @@ -119,14 +120,16 @@ class Item extends StatelessWidget {
Widget _buildChild(BuildContext context, bool dragging) {
return Container(
// slightly transparent background white dragging (just like on iOS)
decoration: BoxDecoration(color: dragging ? Color(0xD0FFFFFF) : Colors.white),
decoration:
BoxDecoration(color: dragging ? Color(0xD0FFFFFF) : Colors.white),
child: SafeArea(
top: false,
bottom: false,
child: Row(
children: <Widget>[
Expanded(
child: Text(data.title, style: Theme.of(context).textTheme.subhead)),
child: Text(data.title,
style: Theme.of(context).textTheme.subhead)),
Icon(Icons.reorder,
color: dragging ? Color(0xFF555555) : Color(0xFF888888)),
],
Expand Down
61 changes: 36 additions & 25 deletions lib/reorderable_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class ReorderableList extends StatefulWidget {
State<StatefulWidget> createState() => new _ReorderableListState();
}

class _ReorderableListState extends State<ReorderableList> with TickerProviderStateMixin {
class _ReorderableListState extends State<ReorderableList>
with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return new Stack(
Expand Down Expand Up @@ -70,7 +71,8 @@ class _ReorderableListState extends State<ReorderableList> with TickerProviderSt
HapticFeedback.selectionClick();
final draggedItem = _items[_dragging];
draggedItem.update();
_dragProxy.setWidget(draggedItem.widget.childBuilder(draggedItem.context, true),
_dragProxy.setWidget(
draggedItem.widget.childBuilder(draggedItem.context, true),
draggedItem.context.findRenderObject());
this._scrollController.addListener(this._scrolled);
}
Expand Down Expand Up @@ -99,16 +101,17 @@ class _ReorderableListState extends State<ReorderableList> with TickerProviderSt
double top = d?.padding?.top ?? 0.0;
double bottom = context.size.height - (d?.padding?.bottom ?? 0.0);

if (_dragProxy.offset < top && position.pixels > position.minScrollExtent) {
if (_dragProxy.offset < top &&
position.pixels > position.minScrollExtent) {
final overdrag = max(top - _dragProxy.offset, overdragMax);
newOffset = max(
position.minScrollExtent, position.pixels - step * overdrag / overdragCoef);
newOffset = max(position.minScrollExtent,
position.pixels - step * overdrag / overdragCoef);
} else if (_dragProxy.offset + _dragProxy.height > bottom &&
position.pixels < position.maxScrollExtent) {
final overdrag =
max<double>(_dragProxy.offset + _dragProxy.height - bottom, overdragMax);
newOffset = min(
position.maxScrollExtent, position.pixels + step * overdrag / overdragCoef);
final overdrag = max<double>(
_dragProxy.offset + _dragProxy.height - bottom, overdragMax);
newOffset = min(position.maxScrollExtent,
position.pixels + step * overdrag / overdragCoef);
}

if (newOffset != null && (newOffset - position.pixels).abs() >= 1.0) {
Expand Down Expand Up @@ -165,8 +168,9 @@ class _ReorderableListState extends State<ReorderableList> with TickerProviderSt
duration: Duration(milliseconds: 300));

_finalAnimation.addListener(() {
_dragProxy.offset = Tween<double>(begin: dragProxyOffset, end: originalOffset)
.lerp(_finalAnimation.value);
_dragProxy.offset =
Tween<double>(begin: dragProxyOffset, end: originalOffset)
.lerp(_finalAnimation.value);
_dragProxy.shadowOpacity = 1.0 - _finalAnimation.value;
});

Expand Down Expand Up @@ -206,14 +210,15 @@ class _ReorderableListState extends State<ReorderableList> with TickerProviderSt
if (item.key == _dragging) continue;
final itemTop = _itemOffset(item);
if (itemTop > draggingTop) continue;
final itemBottom =
itemTop + (item.context.findRenderObject() as RenderBox).size.height / 2;
final itemBottom = itemTop +
(item.context.findRenderObject() as RenderBox).size.height / 2;

if (_dragProxy.offset < itemBottom) {
onReorderApproved.add(() {
_adjustItemTranslation(item.key, -draggingHeight, draggingHeight);
});
if (closest == null || closestDistance > (itemBottom - _dragProxy.offset)) {
if (closest == null ||
closestDistance > (itemBottom - _dragProxy.offset)) {
closest = item;
closestDistance = (itemBottom - _dragProxy.offset);
}
Expand All @@ -227,13 +232,14 @@ class _ReorderableListState extends State<ReorderableList> with TickerProviderSt
final itemTop = _itemOffset(item);
if (itemTop < draggingTop) continue;

final itemBottom =
itemTop + (item.context.findRenderObject() as RenderBox).size.height / 2;
final itemBottom = itemTop +
(item.context.findRenderObject() as RenderBox).size.height / 2;
if (draggingBottom > itemBottom) {
onReorderApproved.add(() {
_adjustItemTranslation(item.key, draggingHeight, draggingHeight);
});
if (closest == null || closestDistance > (draggingBottom - itemBottom)) {
if (closest == null ||
closestDistance > (draggingBottom - itemBottom)) {
closest = item;
closestDistance = draggingBottom - itemBottom;
}
Expand All @@ -243,7 +249,9 @@ class _ReorderableListState extends State<ReorderableList> with TickerProviderSt

// _lastReportedKey check is to ensure we don't keep spamming the callback when reorder
// was rejected for this key;
if (closest != null && closest.key != _dragging && closest.key != _lastReportedKey) {
if (closest != null &&
closest.key != _dragging &&
closest.key != _lastReportedKey) {
SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) {
_scheduledRebuild = false;
});
Expand Down Expand Up @@ -283,7 +291,8 @@ class _ReorderableListState extends State<ReorderableList> with TickerProviderSt
}

static _ReorderableListState of(BuildContext context) {
return context.ancestorStateOfType(new TypeMatcher<_ReorderableListState>());
return context
.ancestorStateOfType(new TypeMatcher<_ReorderableListState>());
}

//
Expand Down Expand Up @@ -374,8 +383,8 @@ class _ReorderableItemState extends State<ReorderableItem> {
return Listener(
onPointerDown: _routePointer,
child: Transform(
transform:
new Matrix4.translationValues(0.0, _listState.itemTranslation(key), 0.0),
transform: new Matrix4.translationValues(
0.0, _listState.itemTranslation(key), 0.0),
child: DecoratedBox(
position: DecorationPosition.foreground,
decoration: widget.decorationBuilder != null
Expand Down Expand Up @@ -479,7 +488,8 @@ class _DragProxyState extends State<_DragProxy> {
height: decorationHeight,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Color(0x50000000), width: 0.5)),
bottom: BorderSide(
color: Color(0x50000000), width: 0.5)),
gradient: LinearGradient(
begin: Alignment(0.0, -1.0),
end: Alignment(0.0, 1.0),
Expand All @@ -496,7 +506,8 @@ class _DragProxyState extends State<_DragProxy> {
height: decorationHeight,
decoration: BoxDecoration(
border: Border(
top: BorderSide(color: Color(0x50000000), width: 0.5)),
top: BorderSide(
color: Color(0x50000000), width: 0.5)),
gradient: LinearGradient(
begin: Alignment(0.0, -1.0),
end: Alignment(0.0, 1.0),
Expand All @@ -508,8 +519,8 @@ class _DragProxyState extends State<_DragProxy> {
)),
],
),
rect: new Rect.fromLTWH(0.0, _offset - decorationHeight, _size.width,
_size.height + decorationHeight * 2 + 1.0))
rect: new Rect.fromLTWH(0.0, _offset - decorationHeight,
_size.width, _size.height + decorationHeight * 2 + 1.0))
: new Container(width: 0.0, height: 0.0);
}

Expand Down

0 comments on commit d0edb65

Please sign in to comment.