diff --git a/CHANGELOG.md b/CHANGELOG.md index 054bf2f..b50159b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.6.0 +### Changed +* Migrated to sound null-safety. +* Increase the minimum version of Flutter. +* Increase the minimum version of Dart SDK. + ## 0.5.0 ### Changed * The minimum version of Flutter. diff --git a/example/lib/common.dart b/example/lib/common.dart index 046d93e..b66a549 100644 --- a/example/lib/common.dart +++ b/example/lib/common.dart @@ -3,9 +3,9 @@ import 'package:flutter_sticky_header/flutter_sticky_header.dart'; class AppScaffold extends StatelessWidget { const AppScaffold({ - Key key, - @required this.title, - @required this.slivers, + Key? key, + required this.title, + required this.slivers, this.reverse = false, }) : super(key: key); @@ -32,7 +32,7 @@ class AppScaffold extends StatelessWidget { class _FloatingActionButton extends StatelessWidget { const _FloatingActionButton({ - Key key, + Key? key, }) : super(key: key); @override @@ -42,8 +42,8 @@ class _FloatingActionButton extends StatelessWidget { backgroundColor: Colors.green, onPressed: () { final double offset = - DefaultStickyHeaderController.of(context).stickyHeaderScrollOffset; - PrimaryScrollController.of(context).animateTo( + DefaultStickyHeaderController.of(context)!.stickyHeaderScrollOffset; + PrimaryScrollController.of(context)!.animateTo( offset, duration: Duration(milliseconds: 300), curve: Curves.easeIn, @@ -55,14 +55,14 @@ class _FloatingActionButton extends StatelessWidget { class Header extends StatelessWidget { const Header({ - Key key, + Key? key, this.index, this.title, this.color = Colors.lightBlue, }) : super(key: key); - final String title; - final int index; + final String? title; + final int? index; final Color color; @override diff --git a/example/lib/examples/animated_header.dart b/example/lib/examples/animated_header.dart index 01237e8..f624c57 100644 --- a/example/lib/examples/animated_header.dart +++ b/example/lib/examples/animated_header.dart @@ -5,7 +5,7 @@ import '../common.dart'; class AnimatedHeaderExample extends StatelessWidget { const AnimatedHeaderExample({ - Key key, + Key? key, }) : super(key: key); @override @@ -24,11 +24,11 @@ class AnimatedHeaderExample extends StatelessWidget { class _StickyHeaderList extends StatelessWidget { const _StickyHeaderList({ - Key key, + Key? key, this.index, }) : super(key: key); - final int index; + final int? index; @override Widget build(BuildContext context) { @@ -54,19 +54,19 @@ class _StickyHeaderList extends StatelessWidget { class _AnimatedHeader extends StatelessWidget { const _AnimatedHeader({ - Key key, + Key? key, this.state, this.index, }) : super(key: key); - final int index; - final SliverStickyHeaderState state; + final int? index; + final SliverStickyHeaderState? state; @override Widget build(BuildContext context) { return Header( index: index, - color: Colors.lightBlue.withOpacity(1 - state.scrollPercentage), + color: Colors.lightBlue.withOpacity(1 - state!.scrollPercentage), ); } } diff --git a/example/lib/examples/grid.dart b/example/lib/examples/grid.dart index 2b2312f..da1af75 100644 --- a/example/lib/examples/grid.dart +++ b/example/lib/examples/grid.dart @@ -5,7 +5,7 @@ import '../common.dart'; class GridExample extends StatelessWidget { const GridExample({ - Key key, + Key? key, }) : super(key: key); @override @@ -24,11 +24,11 @@ class GridExample extends StatelessWidget { class _StickyHeaderGrid extends StatelessWidget { const _StickyHeaderGrid({ - Key key, + Key? key, this.index, }) : super(key: key); - final int index; + final int? index; @override Widget build(BuildContext context) { diff --git a/example/lib/examples/list.dart b/example/lib/examples/list.dart index f94f841..27f5c42 100644 --- a/example/lib/examples/list.dart +++ b/example/lib/examples/list.dart @@ -5,7 +5,7 @@ import '../common.dart'; class ListExample extends StatelessWidget { const ListExample({ - Key key, + Key? key, }) : super(key: key); @override @@ -24,11 +24,11 @@ class ListExample extends StatelessWidget { class _StickyHeaderList extends StatelessWidget { const _StickyHeaderList({ - Key key, + Key? key, this.index, }) : super(key: key); - final int index; + final int? index; @override Widget build(BuildContext context) { diff --git a/example/lib/examples/mix_slivers.dart b/example/lib/examples/mix_slivers.dart index 698c352..ce4b8e3 100644 --- a/example/lib/examples/mix_slivers.dart +++ b/example/lib/examples/mix_slivers.dart @@ -5,7 +5,7 @@ import '../common.dart'; class MixSliversExample extends StatelessWidget { const MixSliversExample({ - Key key, + Key? key, }) : super(key: key); @override @@ -36,11 +36,11 @@ class MixSliversExample extends StatelessWidget { class _StickyHeaderList extends StatelessWidget { const _StickyHeaderList({ - Key key, + Key? key, this.index, }) : super(key: key); - final int index; + final int? index; @override Widget build(BuildContext context) { diff --git a/example/lib/examples/not_sticky.dart b/example/lib/examples/not_sticky.dart index af205f2..a6d7015 100644 --- a/example/lib/examples/not_sticky.dart +++ b/example/lib/examples/not_sticky.dart @@ -5,7 +5,7 @@ import '../common.dart'; class NotStickyExample extends StatelessWidget { const NotStickyExample({ - Key key, + Key? key, }) : super(key: key); @override @@ -24,11 +24,11 @@ class NotStickyExample extends StatelessWidget { class _NotStickyList extends StatelessWidget { const _NotStickyList({ - Key key, + Key? key, this.index, }) : super(key: key); - final int index; + final int? index; @override Widget build(BuildContext context) { diff --git a/example/lib/examples/reverse.dart b/example/lib/examples/reverse.dart index 9279f76..17fea56 100644 --- a/example/lib/examples/reverse.dart +++ b/example/lib/examples/reverse.dart @@ -5,7 +5,7 @@ import '../common.dart'; class ReverseExample extends StatelessWidget { const ReverseExample({ - Key key, + Key? key, }) : super(key: key); @override @@ -25,11 +25,11 @@ class ReverseExample extends StatelessWidget { class _StickyHeaderList extends StatelessWidget { const _StickyHeaderList({ - Key key, + Key? key, this.index, }) : super(key: key); - final int index; + final int? index; @override Widget build(BuildContext context) { diff --git a/example/lib/examples/side_header.dart b/example/lib/examples/side_header.dart index 8c6074e..a7602da 100644 --- a/example/lib/examples/side_header.dart +++ b/example/lib/examples/side_header.dart @@ -5,7 +5,7 @@ import '../common.dart'; class SideHeaderExample extends StatelessWidget { const SideHeaderExample({ - Key key, + Key? key, }) : super(key: key); @override @@ -24,11 +24,11 @@ class SideHeaderExample extends StatelessWidget { class _StickyHeaderGrid extends StatelessWidget { const _StickyHeaderGrid({ - Key key, + Key? key, this.index, }) : super(key: key); - final int index; + final int? index; @override Widget build(BuildContext context) { @@ -68,11 +68,11 @@ class _StickyHeaderGrid extends StatelessWidget { class _SideHeader extends StatelessWidget { const _SideHeader({ - Key key, + Key? key, this.index, }) : super(key: key); - final int index; + final int? index; @override Widget build(BuildContext context) { diff --git a/example/lib/main.dart b/example/lib/main.dart index a2cdd50..e1ddcc5 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,18 +1,18 @@ import 'package:flutter/material.dart'; -import 'examples/list.dart'; +import 'examples/animated_header.dart'; import 'examples/grid.dart'; +import 'examples/list.dart'; +import 'examples/mix_slivers.dart'; import 'examples/not_sticky.dart'; -import 'examples/side_header.dart'; -import 'examples/animated_header.dart'; import 'examples/reverse.dart'; -import 'examples/mix_slivers.dart'; +import 'examples/side_header.dart'; void main() => runApp(const App()); class App extends StatelessWidget { const App({ - Key key, + Key? key, }) : super(key: key); @override @@ -26,7 +26,7 @@ class App extends StatelessWidget { class _Home extends StatelessWidget { const _Home({ - Key key, + Key? key, }) : super(key: key); @override @@ -73,9 +73,9 @@ class _Home extends StatelessWidget { class _Item extends StatelessWidget { const _Item({ - Key key, - @required this.text, - @required this.builder, + Key? key, + required this.text, + required this.builder, }) : super(key: key); final String text; diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 04c5dc2..08a01a8 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: @@ -29,7 +29,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.3 + cupertino_icons: ^1.0.2 dev_dependencies: flutter_test: diff --git a/lib/src/rendering/sliver_sticky_header.dart b/lib/src/rendering/sliver_sticky_header.dart index 83b7262..a1c300a 100644 --- a/lib/src/rendering/sliver_sticky_header.dart +++ b/lib/src/rendering/sliver_sticky_header.dart @@ -12,28 +12,26 @@ import 'package:value_layout_builder/value_layout_builder.dart'; /// the [child] scrolls off the viewport. class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { RenderSliverStickyHeader({ - RenderObject header, - RenderSliver child, + RenderObject? header, + RenderSliver? child, bool overlapsContent: false, bool sticky: true, - StickyHeaderController controller, - }) : assert(overlapsContent != null), - assert(sticky != null), - _overlapsContent = overlapsContent, + StickyHeaderController? controller, + }) : _overlapsContent = overlapsContent, _sticky = sticky, _controller = controller { - this.header = header; + this.header = header as RenderBox?; this.child = child; } - SliverStickyHeaderState _oldState; - double _headerExtent; - bool _isPinned; + SliverStickyHeaderState? _oldState; + double? _headerExtent; + late bool _isPinned; bool get overlapsContent => _overlapsContent; bool _overlapsContent; + set overlapsContent(bool value) { - assert(value != null); if (_overlapsContent == value) return; _overlapsContent = value; markNeedsLayout(); @@ -41,40 +39,43 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { bool get sticky => _sticky; bool _sticky; + set sticky(bool value) { - assert(value != null); if (_sticky == value) return; _sticky = value; markNeedsLayout(); } - StickyHeaderController get controller => _controller; - StickyHeaderController _controller; - set controller(StickyHeaderController value) { + StickyHeaderController? get controller => _controller; + StickyHeaderController? _controller; + + set controller(StickyHeaderController? value) { if (_controller == value) return; if (_controller != null && value != null) { // We copy the state of the old controller. - value.stickyHeaderScrollOffset = _controller.stickyHeaderScrollOffset; + value.stickyHeaderScrollOffset = _controller!.stickyHeaderScrollOffset; } _controller = value; } /// The render object's header - RenderBox get header => _header; - RenderBox _header; - set header(RenderBox value) { - if (_header != null) dropChild(_header); + RenderBox? get header => _header; + RenderBox? _header; + + set header(RenderBox? value) { + if (_header != null) dropChild(_header!); _header = value; - if (_header != null) adoptChild(_header); + if (_header != null) adoptChild(_header!); } /// The render object's unique child - RenderSliver get child => _child; - RenderSliver _child; - set child(RenderSliver value) { - if (_child != null) dropChild(_child); + RenderSliver? get child => _child; + RenderSliver? _child; + + set child(RenderSliver? value) { + if (_child != null) dropChild(_child!); _child = value; - if (_child != null) adoptChild(_child); + if (_child != null) adoptChild(_child!); } @override @@ -86,55 +87,53 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { @override void attach(PipelineOwner owner) { super.attach(owner); - if (_header != null) _header.attach(owner); - if (_child != null) _child.attach(owner); + if (_header != null) _header!.attach(owner); + if (_child != null) _child!.attach(owner); } @override void detach() { super.detach(); - if (_header != null) _header.detach(); - if (_child != null) _child.detach(); + if (_header != null) _header!.detach(); + if (_child != null) _child!.detach(); } @override void redepthChildren() { - if (_header != null) redepthChild(_header); - if (_child != null) redepthChild(_child); + if (_header != null) redepthChild(_header!); + if (_child != null) redepthChild(_child!); } @override void visitChildren(RenderObjectVisitor visitor) { - if (_header != null) visitor(_header); - if (_child != null) visitor(_child); + if (_header != null) visitor(_header!); + if (_child != null) visitor(_child!); } @override List debugDescribeChildren() { List result = []; if (header != null) { - result.add(header.toDiagnosticsNode(name: 'header')); + result.add(header!.toDiagnosticsNode(name: 'header')); } if (child != null) { - result.add(child.toDiagnosticsNode(name: 'child')); + result.add(child!.toDiagnosticsNode(name: 'child')); } return result; } double computeHeaderExtent() { if (header == null) return 0.0; - assert(header.hasSize); - assert(constraints.axis != null); + assert(header!.hasSize); switch (constraints.axis) { case Axis.vertical: - return header.size.height; + return header!.size.height; case Axis.horizontal: - return header.size.width; + return header!.size.width; } - return null; } - double get headerLogicalExtent => overlapsContent ? 0.0 : _headerExtent; + double? get headerLogicalExtent => overlapsContent ? 0.0 : _headerExtent; @override void performLayout() { @@ -148,7 +147,7 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { constraints.axisDirection, constraints.growthDirection); if (header != null) { - header.layout( + header!.layout( BoxValueConstraints( value: _oldState ?? SliverStickyHeaderState(0.0, false), constraints: constraints.asBoxConstraints(), @@ -159,7 +158,7 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { } // Compute the header extent only one time. - double headerExtent = headerLogicalExtent; + double headerExtent = headerLogicalExtent!; final double headerPaintExtent = calculatePaintOffset(constraints, from: 0.0, to: headerExtent); final double headerCacheExtent = @@ -175,7 +174,7 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { hasVisualOverflow: headerExtent > constraints.remainingPaintExtent || constraints.scrollOffset > 0.0); } else { - child.layout( + child!.layout( constraints.copyWith( scrollOffset: math.max(0.0, constraints.scrollOffset - headerExtent), cacheOrigin: math.min(0.0, constraints.cacheOrigin + headerExtent), @@ -187,7 +186,7 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { ), parentUsesSize: true, ); - final SliverGeometry childLayoutGeometry = child.geometry; + final SliverGeometry childLayoutGeometry = child!.geometry!; if (childLayoutGeometry.scrollOffsetCorrection != null) { geometry = SliverGeometry( scrollOffsetCorrection: childLayoutGeometry.scrollOffsetCorrection, @@ -217,37 +216,37 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { hasVisualOverflow: childLayoutGeometry.hasVisualOverflow, ); - final SliverPhysicalParentData childParentData = child.parentData; - assert(constraints.axisDirection != null); - assert(constraints.growthDirection != null); + final SliverPhysicalParentData? childParentData = + child!.parentData as SliverPhysicalParentData?; switch (axisDirection) { case AxisDirection.up: - childParentData.paintOffset = Offset.zero; + childParentData!.paintOffset = Offset.zero; break; case AxisDirection.right: - childParentData.paintOffset = Offset( + childParentData!.paintOffset = Offset( calculatePaintOffset(constraints, from: 0.0, to: headerExtent), 0.0); break; case AxisDirection.down: - childParentData.paintOffset = Offset(0.0, + childParentData!.paintOffset = Offset(0.0, calculatePaintOffset(constraints, from: 0.0, to: headerExtent)); break; case AxisDirection.left: - childParentData.paintOffset = Offset.zero; + childParentData!.paintOffset = Offset.zero; break; } } if (header != null) { - final SliverPhysicalParentData headerParentData = header.parentData; + final SliverPhysicalParentData? headerParentData = + header!.parentData as SliverPhysicalParentData?; final double childScrollExtent = child?.geometry?.scrollExtent ?? 0.0; final double headerPosition = sticky ? math.min( constraints.overlap, childScrollExtent - constraints.scrollOffset - - (overlapsContent ? _headerExtent : 0.0)) + (overlapsContent ? _headerExtent! : 0.0)) : -constraints.scrollOffset; _isPinned = sticky && @@ -256,7 +255,7 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { constraints.viewportMainAxisExtent); final double headerScrollRatio = - ((headerPosition - constraints.overlap).abs() / _headerExtent); + ((headerPosition - constraints.overlap).abs() / _headerExtent!); if (_isPinned && headerScrollRatio <= 1) { controller?.stickyHeaderScrollOffset = constraints.precedingScrollExtent; @@ -271,8 +270,8 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { SliverStickyHeaderState(headerScrollRatioClamped, _isPinned); if (_oldState != state) { _oldState = state; - header.layout( - BoxValueConstraints( + header!.layout( + BoxValueConstraints( value: _oldState, constraints: constraints.asBoxConstraints(), ), @@ -283,18 +282,18 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { switch (axisDirection) { case AxisDirection.up: - headerParentData.paintOffset = Offset( - 0.0, geometry.paintExtent - headerPosition - _headerExtent); + headerParentData!.paintOffset = Offset( + 0.0, geometry!.paintExtent - headerPosition - _headerExtent!); break; case AxisDirection.down: - headerParentData.paintOffset = Offset(0.0, headerPosition); + headerParentData!.paintOffset = Offset(0.0, headerPosition); break; case AxisDirection.left: - headerParentData.paintOffset = Offset( - geometry.paintExtent - headerPosition - _headerExtent, 0.0); + headerParentData!.paintOffset = Offset( + geometry!.paintExtent - headerPosition - _headerExtent!, 0.0); break; case AxisDirection.right: - headerParentData.paintOffset = Offset(headerPosition, 0.0); + headerParentData!.paintOffset = Offset(headerPosition, 0.0); break; } } @@ -302,25 +301,25 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { @override bool hitTestChildren(SliverHitTestResult result, - {@required double mainAxisPosition, @required double crossAxisPosition}) { - assert(geometry.hitTestExtent > 0.0); + {required double mainAxisPosition, required double crossAxisPosition}) { + assert(geometry!.hitTestExtent > 0.0); if (header != null && - mainAxisPosition - constraints.overlap <= _headerExtent) { + mainAxisPosition - constraints.overlap <= _headerExtent!) { return hitTestBoxChild( BoxHitTestResult.wrap(SliverHitTestResult.wrap(result)), - header, + header!, mainAxisPosition: mainAxisPosition - constraints.overlap, crossAxisPosition: crossAxisPosition, ) || (_overlapsContent && child != null && - child.geometry.hitTestExtent > 0.0 && - child.hitTest(result, + child!.geometry!.hitTestExtent > 0.0 && + child!.hitTest(result, mainAxisPosition: mainAxisPosition - childMainAxisPosition(child), crossAxisPosition: crossAxisPosition)); - } else if (child != null && child.geometry.hitTestExtent > 0.0) { - return child.hitTest(result, + } else if (child != null && child!.geometry!.hitTestExtent > 0.0) { + return child!.hitTest(result, mainAxisPosition: mainAxisPosition - childMainAxisPosition(child), crossAxisPosition: crossAxisPosition); } @@ -328,19 +327,19 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { } @override - double childMainAxisPosition(RenderObject child) { + double childMainAxisPosition(RenderObject? child) { if (child == header) return _isPinned ? 0.0 : -(constraints.scrollOffset + constraints.overlap); if (child == this.child) return calculatePaintOffset(constraints, - from: 0.0, to: headerLogicalExtent); - return null; + from: 0.0, to: headerLogicalExtent!); + return 0; } @override - double childScrollOffset(RenderObject child) { + double? childScrollOffset(RenderObject child) { assert(child.parent == this); if (child == this.child) { return _headerExtent; @@ -351,23 +350,25 @@ class RenderSliverStickyHeader extends RenderSliver with RenderSliverHelpers { @override void applyPaintTransform(RenderObject child, Matrix4 transform) { - assert(child != null); - final SliverPhysicalParentData childParentData = child.parentData; + final SliverPhysicalParentData childParentData = + child.parentData as SliverPhysicalParentData; childParentData.applyPaintTransform(transform); } @override void paint(PaintingContext context, Offset offset) { - if (geometry.visible) { - if (child != null && child.geometry.visible) { - final SliverPhysicalParentData childParentData = child.parentData; - context.paintChild(child, offset + childParentData.paintOffset); + if (geometry!.visible) { + if (child != null && child!.geometry!.visible) { + final SliverPhysicalParentData childParentData = + child!.parentData as SliverPhysicalParentData; + context.paintChild(child!, offset + childParentData.paintOffset); } // The header must be drawn over the sliver. if (header != null) { - final SliverPhysicalParentData headerParentData = header.parentData; - context.paintChild(header, offset + headerParentData.paintOffset); + final SliverPhysicalParentData headerParentData = + header!.parentData as SliverPhysicalParentData; + context.paintChild(header!, offset + headerParentData.paintOffset); } } } diff --git a/lib/src/widgets/sliver_sticky_header.dart b/lib/src/widgets/sliver_sticky_header.dart index df2e05c..48d0657 100644 --- a/lib/src/widgets/sliver_sticky_header.dart +++ b/lib/src/widgets/sliver_sticky_header.dart @@ -1,3 +1,4 @@ +import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_sticky_header/src/rendering/sliver_sticky_header.dart'; import 'package:value_layout_builder/value_layout_builder.dart'; @@ -20,7 +21,6 @@ class StickyHeaderController with ChangeNotifier { /// This setter should only be used by flutter_sticky_header package. set stickyHeaderScrollOffset(double value) { - assert(value != null); if (_stickyHeaderScrollOffset != value) { _stickyHeaderScrollOffset = value; notifyListeners(); @@ -38,8 +38,8 @@ class StickyHeaderController with ChangeNotifier { /// widgets. class DefaultStickyHeaderController extends StatefulWidget { const DefaultStickyHeaderController({ - Key key, - @required this.child, + Key? key, + required this.child, }) : super(key: key); /// The widget below this widget in the tree. @@ -56,8 +56,8 @@ class DefaultStickyHeaderController extends StatefulWidget { /// ```dart /// StickyHeaderController controller = DefaultStickyHeaderController.of(context); /// ``` - static StickyHeaderController of(BuildContext context) { - final _StickyHeaderControllerScope scope = context + static StickyHeaderController? of(BuildContext context) { + final _StickyHeaderControllerScope? scope = context .dependOnInheritedWidgetOfExactType<_StickyHeaderControllerScope>(); return scope?.controller; } @@ -69,7 +69,7 @@ class DefaultStickyHeaderController extends StatefulWidget { class _DefaultStickyHeaderControllerState extends State { - StickyHeaderController _controller; + StickyHeaderController? _controller; @override void initState() { @@ -79,7 +79,7 @@ class _DefaultStickyHeaderControllerState @override void dispose() { - _controller.dispose(); + _controller!.dispose(); super.dispose(); } @@ -94,12 +94,12 @@ class _DefaultStickyHeaderControllerState class _StickyHeaderControllerScope extends InheritedWidget { const _StickyHeaderControllerScope({ - Key key, + Key? key, this.controller, - Widget child, + required Widget child, }) : super(key: key, child: child); - final StickyHeaderController controller; + final StickyHeaderController? controller; @override bool updateShouldNotify(_StickyHeaderControllerScope old) { @@ -113,8 +113,7 @@ class SliverStickyHeaderState { const SliverStickyHeaderState( this.scrollPercentage, this.isPinned, - ) : assert(scrollPercentage != null), - assert(isPinned != null); + ); final double scrollPercentage; @@ -150,15 +149,13 @@ class SliverStickyHeader extends RenderObjectWidget { /// If a [StickyHeaderController] is not provided, then the value of /// [DefaultStickyHeaderController.of] will be used. SliverStickyHeader({ - Key key, + Key? key, this.header, this.sliver, this.overlapsContent: false, this.sticky = true, this.controller, - }) : assert(overlapsContent != null), - assert(sticky != null), - super(key: key); + }) : super(key: key); /// Creates a widget that builds the header of a [SliverStickyHeader] /// each time its scroll percentage changes. @@ -168,12 +165,12 @@ class SliverStickyHeader extends RenderObjectWidget { /// If a [StickyHeaderController] is not provided, then the value of /// [DefaultStickyHeaderController.of] will be used. SliverStickyHeader.builder({ - Key key, - SliverStickyHeaderWidgetBuilder builder, - Widget sliver, + Key? key, + required SliverStickyHeaderWidgetBuilder builder, + Widget? sliver, bool overlapsContent: false, bool sticky = true, - StickyHeaderController controller, + StickyHeaderController? controller, }) : this( key: key, header: ValueLayoutBuilder( @@ -187,10 +184,10 @@ class SliverStickyHeader extends RenderObjectWidget { ); /// The header to display before the sliver. - final Widget header; + final Widget? header; /// The sliver to display after the header. - final Widget sliver; + final Widget? sliver; /// Whether the header should be drawn on top of the sliver /// instead of before. @@ -204,7 +201,7 @@ class SliverStickyHeader extends RenderObjectWidget { /// /// If a [StickyHeaderController] is not provided, then the value of [DefaultStickyHeaderController.of] /// will be used. - final StickyHeaderController controller; + final StickyHeaderController? controller; @override RenderSliverStickyHeader createRenderObject(BuildContext context) { @@ -247,16 +244,13 @@ class SliverStickyHeaderBuilder extends StatelessWidget { /// If a [StickyHeaderController] is not provided, then the value of [DefaultStickyHeaderController.of] /// will be used. const SliverStickyHeaderBuilder({ - Key key, - @required this.builder, + Key? key, + required this.builder, this.sliver, this.overlapsContent: false, this.sticky = true, this.controller, - }) : assert(builder != null), - assert(overlapsContent != null), - assert(sticky != null), - super(key: key); + }) : super(key: key); /// Called to build the [SliverStickyHeader]'s header. /// @@ -265,7 +259,7 @@ class SliverStickyHeaderBuilder extends StatelessWidget { final SliverStickyHeaderWidgetBuilder builder; /// The sliver to display after the header. - final Widget sliver; + final Widget? sliver; /// Whether the header should be drawn on top of the sliver /// instead of before. @@ -279,7 +273,7 @@ class SliverStickyHeaderBuilder extends StatelessWidget { /// /// If a [StickyHeaderController] is not provided, then the value of [DefaultStickyHeaderController.of] /// will be used. - final StickyHeaderController controller; + final StickyHeaderController? controller; @override Widget build(BuildContext context) { @@ -301,16 +295,16 @@ class SliverStickyHeaderRenderObjectElement extends RenderObjectElement { : super(widget); @override - SliverStickyHeader get widget => super.widget; + SliverStickyHeader get widget => super.widget as SliverStickyHeader; - Element _header; + Element? _header; - Element _sliver; + Element? _sliver; @override void visitChildren(ElementVisitor visitor) { - if (_header != null) visitor(_header); - if (_sliver != null) visitor(_sliver); + if (_header != null) visitor(_header!); + if (_sliver != null) visitor(_sliver!); } @override @@ -321,7 +315,7 @@ class SliverStickyHeaderRenderObjectElement extends RenderObjectElement { } @override - void mount(Element parent, dynamic newSlot) { + void mount(Element? parent, dynamic newSlot) { super.mount(parent, newSlot); _header = updateChild(_header, widget.header, 0); _sliver = updateChild(_sliver, widget.sliver, 1); @@ -336,21 +330,23 @@ class SliverStickyHeaderRenderObjectElement extends RenderObjectElement { } @override - void insertChildRenderObject(RenderObject child, int slot) { - final RenderSliverStickyHeader renderObject = this.renderObject; - if (slot == 0) renderObject.header = child; - if (slot == 1) renderObject.child = child; + void insertRenderObjectChild(RenderObject child, int? slot) { + final RenderSliverStickyHeader renderObject = + this.renderObject as RenderSliverStickyHeader; + if (slot == 0) renderObject.header = child as RenderBox?; + if (slot == 1) renderObject.child = child as RenderSliver?; assert(renderObject == this.renderObject); } @override - void moveChildRenderObject(RenderObject child, slot) { + void moveRenderObjectChild(RenderObject child, slot, newSlot) { assert(false); } @override - void removeChildRenderObject(RenderObject child) { - final RenderSliverStickyHeader renderObject = this.renderObject; + void removeRenderObjectChild(RenderObject child, slot) { + final RenderSliverStickyHeader renderObject = + this.renderObject as RenderSliverStickyHeader; if (renderObject.header == child) renderObject.header = null; if (renderObject.child == child) renderObject.child = null; assert(renderObject == this.renderObject); diff --git a/pubspec.yaml b/pubspec.yaml index a5e665d..8443fb4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,17 +1,17 @@ name: flutter_sticky_header description: Flutter implementation of sticky headers as a sliver. Use it in a CustomScrollView. -version: 0.5.0 +version: 0.6.0 homepage: https://github.com/letsar/flutter_sticky_header dependencies: flutter: sdk: flutter - value_layout_builder: ^0.2.0 + value_layout_builder: ^0.3.0 dev_dependencies: flutter_test: sdk: flutter environment: - sdk: ">=2.2.0 <3.0.0" - flutter: ">=1.20.0 <2.0.0" + sdk: '>=2.12.0 <3.0.0' + flutter: '>=1.24.0-10.2.pre' diff --git a/test/controller_test.dart b/test/controller_test.dart index fbca4f0..827a979 100644 --- a/test/controller_test.dart +++ b/test/controller_test.dart @@ -5,7 +5,7 @@ import 'package:flutter_sticky_header/flutter_sticky_header.dart'; void main() { setUp(() { - WidgetsBinding.instance.renderView.configuration = + WidgetsBinding.instance!.renderView.configuration = TestViewConfiguration(size: Size(400, 800)); }); @@ -195,8 +195,8 @@ void main() { class _Header extends StatelessWidget { const _Header({ - Key key, - @required this.index, + Key? key, + required this.index, }) : super(key: key); final int index; @@ -213,7 +213,7 @@ class _Header extends StatelessWidget { class _Sliver extends StatelessWidget { const _Sliver({ - Key key, + Key? key, }) : super(key: key); @override @@ -229,7 +229,7 @@ class _Sliver extends StatelessWidget { class _SliverItem extends StatelessWidget { const _SliverItem({ - Key key, + Key? key, }) : super(key: key); @override diff --git a/test/sticky_test.dart b/test/sticky_test.dart index f855154..4300734 100644 --- a/test/sticky_test.dart +++ b/test/sticky_test.dart @@ -5,7 +5,7 @@ import 'package:flutter_sticky_header/flutter_sticky_header.dart'; void main() { setUp(() { - WidgetsBinding.instance.renderView.configuration = + WidgetsBinding.instance!.renderView.configuration = TestViewConfiguration(size: Size(400, 800)); }); @@ -171,8 +171,8 @@ void main() { class _Header extends StatelessWidget { const _Header({ - Key key, - @required this.index, + Key? key, + required this.index, }) : super(key: key); final int index; @@ -189,7 +189,7 @@ class _Header extends StatelessWidget { class _Sliver extends StatelessWidget { const _Sliver({ - Key key, + Key? key, }) : super(key: key); @override @@ -205,7 +205,7 @@ class _Sliver extends StatelessWidget { class _SliverItem extends StatelessWidget { const _SliverItem({ - Key key, + Key? key, }) : super(key: key); @override