-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from letsar/feature/2_percentage_observer
Fix issue #2
- Loading branch information
Showing
6 changed files
with
318 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:flutter/rendering.dart'; | ||
|
||
/// Immutable layout constraints for sticky header | ||
class StickyHeaderConstraints extends BoxConstraints { | ||
StickyHeaderConstraints({ | ||
this.scrollPercentage, | ||
BoxConstraints boxConstraints, | ||
}) : assert(scrollPercentage != null), | ||
assert(boxConstraints != null), | ||
super( | ||
minWidth: boxConstraints.minWidth, | ||
maxWidth: boxConstraints.maxWidth, | ||
minHeight: boxConstraints.minHeight, | ||
maxHeight: boxConstraints.maxHeight, | ||
); | ||
|
||
final double scrollPercentage; | ||
|
||
@override | ||
bool get isNormalized => | ||
scrollPercentage >= 0.0 && scrollPercentage <= 1.0 && super.isNormalized; | ||
|
||
@override | ||
bool operator ==(dynamic other) { | ||
assert(debugAssertIsValid()); | ||
if (identical(this, other)) return true; | ||
if (other is! StickyHeaderConstraints) return false; | ||
final StickyHeaderConstraints typedOther = other; | ||
assert(typedOther.debugAssertIsValid()); | ||
return scrollPercentage == typedOther.scrollPercentage && | ||
minWidth == typedOther.minWidth && | ||
maxWidth == typedOther.maxWidth && | ||
minHeight == typedOther.minHeight && | ||
maxHeight == typedOther.maxHeight; | ||
} | ||
|
||
@override | ||
int get hashCode { | ||
assert(debugAssertIsValid()); | ||
return hashValues( | ||
minWidth, maxWidth, minHeight, maxHeight, scrollPercentage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import 'package:flutter/rendering.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_sticky_header/src/rendering/sticky_header_constraints.dart'; | ||
|
||
class RenderStickyHeaderLayoutBuilder extends RenderBox | ||
with RenderObjectWithChildMixin<RenderBox> { | ||
RenderStickyHeaderLayoutBuilder({ | ||
LayoutCallback<StickyHeaderConstraints> callback, | ||
}) : _callback = callback; | ||
|
||
LayoutCallback<StickyHeaderConstraints> get callback => _callback; | ||
LayoutCallback<StickyHeaderConstraints> _callback; | ||
set callback(LayoutCallback<StickyHeaderConstraints> value) { | ||
if (value == _callback) return; | ||
_callback = value; | ||
markNeedsLayout(); | ||
} | ||
|
||
// layout input | ||
@override | ||
StickyHeaderConstraints get constraints => super.constraints; | ||
|
||
bool _debugThrowIfNotCheckingIntrinsics() { | ||
assert(() { | ||
if (!RenderObject.debugCheckingIntrinsics) { | ||
throw new FlutterError( | ||
'StickyHeaderLayoutBuilder does not support returning intrinsic dimensions.\n' | ||
'Calculating the intrinsic dimensions would require running the layout ' | ||
'callback speculatively, which might mutate the live render object tree.'); | ||
} | ||
return true; | ||
}()); | ||
return true; | ||
} | ||
|
||
@override | ||
double computeMinIntrinsicWidth(double height) { | ||
assert(_debugThrowIfNotCheckingIntrinsics()); | ||
return 0.0; | ||
} | ||
|
||
@override | ||
double computeMaxIntrinsicWidth(double height) { | ||
assert(_debugThrowIfNotCheckingIntrinsics()); | ||
return 0.0; | ||
} | ||
|
||
@override | ||
double computeMinIntrinsicHeight(double width) { | ||
assert(_debugThrowIfNotCheckingIntrinsics()); | ||
return 0.0; | ||
} | ||
|
||
@override | ||
double computeMaxIntrinsicHeight(double width) { | ||
assert(_debugThrowIfNotCheckingIntrinsics()); | ||
return 0.0; | ||
} | ||
|
||
@override | ||
void performLayout() { | ||
assert(callback != null); | ||
invokeLayoutCallback(callback); | ||
if (child != null) { | ||
child.layout(constraints, parentUsesSize: true); | ||
size = constraints.constrain(child.size); | ||
} else { | ||
size = constraints.biggest; | ||
} | ||
} | ||
|
||
@override | ||
bool hitTestChildren(HitTestResult result, {Offset position}) { | ||
return child?.hitTest(result, position: position) ?? false; | ||
} | ||
|
||
@override | ||
void paint(PaintingContext context, Offset offset) { | ||
if (child != null) context.paintChild(child, offset); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.