chore: linting

This commit is contained in:
Gordon Hayes
2021-10-18 11:42:39 +02:00
parent 28bd688c7a
commit f805419816
14 changed files with 170 additions and 149 deletions
@@ -678,14 +678,16 @@ class _MessageWidgetState extends State<MessageWidget>
? Container(
transform:
Matrix4.translationValues(
widget.reverse ? 12 : -12,
0,
0),
widget.reverse ? 12 : -12,
0,
0,
),
constraints: const BoxConstraints(
maxWidth: 22 * 6.0,
),
child: _buildReactionIndicator(
context),
context,
),
)
: null,
portalAnchor:
@@ -46,9 +46,11 @@ class _RegistryWidgetState extends State<RegistryWidget> {
}
class _InheritedRegistryWidget extends InheritedWidget {
const _InheritedRegistryWidget(
{Key? key, required this.state, required Widget child})
: super(key: key, child: child);
const _InheritedRegistryWidget({
Key? key,
required this.state,
required Widget child,
}) : super(key: key, child: child);
final _RegistryWidgetState state;
@@ -21,10 +21,11 @@ abstract class ItemPositionsListener {
/// Position information for an item in the list.
class ItemPosition {
/// Create an [ItemPosition].
const ItemPosition(
{required this.index,
required this.itemLeadingEdge,
required this.itemTrailingEdge});
const ItemPosition({
required this.index,
required this.itemLeadingEdge,
required this.itemTrailingEdge,
});
/// Index of the item.
final int index;
@@ -52,7 +53,7 @@ class ItemPosition {
@override
int get hashCode =>
31 * (31 * (7 + index.hashCode) + itemLeadingEdge.hashCode) +
31 * (31 * (index.hashCode + 7) + itemLeadingEdge.hashCode) +
itemTrailingEdge.hashCode;
@override
@@ -187,10 +187,11 @@ class _PositionedListState extends State<PositionedList> {
(context, index) => widget.separatorBuilder == null
? _buildItem(widget.positionedIndex - (index + 1))
: _buildSeparatedListElement(
2 * widget.positionedIndex - (index + 1)),
widget.positionedIndex * 2 - (index + 1),
),
childCount: widget.separatorBuilder == null
? widget.positionedIndex
: 2 * widget.positionedIndex,
: widget.positionedIndex * 2,
addSemanticIndexes: false,
findChildIndexCallback: widget.findChildIndexCallback,
addRepaintBoundaries: widget.addRepaintBoundaries,
@@ -206,7 +207,8 @@ class _PositionedListState extends State<PositionedList> {
(context, index) => widget.separatorBuilder == null
? _buildItem(index + widget.positionedIndex)
: _buildSeparatedListElement(
index + 2 * widget.positionedIndex),
index + widget.positionedIndex * 2,
),
childCount: widget.itemCount != 0 ? 1 : 0,
findChildIndexCallback: widget.findChildIndexCallback,
addSemanticIndexes: false,
@@ -224,7 +226,8 @@ class _PositionedListState extends State<PositionedList> {
(context, index) => widget.separatorBuilder == null
? _buildItem(index + widget.positionedIndex + 1)
: _buildSeparatedListElement(
index + 2 * widget.positionedIndex + 1),
index + widget.positionedIndex * 2 + 1,
),
childCount: widget.separatorBuilder == null
? widget.itemCount - widget.positionedIndex - 1
: 2 * (widget.itemCount - widget.positionedIndex - 1),
@@ -270,27 +273,27 @@ class _PositionedListState extends State<PositionedList> {
EdgeInsets get _centerSliverPadding => widget.scrollDirection == Axis.vertical
? widget.reverse
? widget.padding?.copyWith(
top: widget.positionedIndex == widget.itemCount - 1
? widget.padding!.top
: 0,
bottom: widget.positionedIndex == 0
? widget.padding!.bottom
: 0) ??
top: widget.positionedIndex == widget.itemCount - 1
? widget.padding!.top
: 0,
bottom:
widget.positionedIndex == 0 ? widget.padding!.bottom : 0,
) ??
const EdgeInsets.all(0)
: widget.padding?.copyWith(
top: widget.positionedIndex == 0 ? widget.padding!.top : 0,
bottom: widget.positionedIndex == widget.itemCount - 1
? widget.padding!.bottom
: 0) ??
top: widget.positionedIndex == 0 ? widget.padding!.top : 0,
bottom: widget.positionedIndex == widget.itemCount - 1
? widget.padding!.bottom
: 0,
) ??
const EdgeInsets.all(0)
: widget.reverse
? widget.padding?.copyWith(
left: widget.positionedIndex == widget.itemCount - 1
? widget.padding!.left
: 0,
right: widget.positionedIndex == 0
? widget.padding!.right
: 0) ??
left: widget.positionedIndex == widget.itemCount - 1
? widget.padding!.left
: 0,
right: widget.positionedIndex == 0 ? widget.padding!.right : 0,
) ??
const EdgeInsets.all(0)
: widget.padding?.copyWith(
left: widget.positionedIndex == 0 ? widget.padding!.left : 0,
@@ -329,28 +332,30 @@ class _PositionedListState extends State<PositionedList> {
viewport.offset.pixels +
viewport.anchor * viewport.size.height;
positions.add(ItemPosition(
index: key.index,
itemLeadingEdge: itemOffset.round() /
scrollController.position.viewportDimension,
itemTrailingEdge: (itemOffset + box.size.height).round() /
scrollController.position.viewportDimension));
index: key.index,
itemLeadingEdge: itemOffset.round() /
scrollController.position.viewportDimension,
itemTrailingEdge: (itemOffset + box.size.height).round() /
scrollController.position.viewportDimension,
));
} else {
final itemOffset =
box.localToGlobal(Offset.zero, ancestor: viewport).dx;
positions.add(ItemPosition(
index: key.index,
itemLeadingEdge: (widget.reverse
? scrollController.position.viewportDimension -
(itemOffset + box.size.width)
: itemOffset)
.round() /
scrollController.position.viewportDimension,
itemTrailingEdge: (widget.reverse
? scrollController.position.viewportDimension -
itemOffset
: (itemOffset + box.size.width))
.round() /
scrollController.position.viewportDimension));
index: key.index,
itemLeadingEdge: (widget.reverse
? scrollController.position.viewportDimension -
(itemOffset + box.size.width)
: itemOffset)
.round() /
scrollController.position.viewportDimension,
itemTrailingEdge: (widget.reverse
? scrollController.position.viewportDimension -
itemOffset
: (itemOffset + box.size.width))
.round() /
scrollController.position.viewportDimension,
));
}
}
widget.itemPositionsNotifier?.itemPositions.value = positions;
@@ -315,20 +315,14 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
}
if (widget.itemCount == 0) {
setState(() {
primary.target = 0;
secondary.target = 0;
});
primary.target = 0;
secondary.target = 0;
} else {
if (primary.target > widget.itemCount - 1) {
setState(() {
primary.target = widget.itemCount - 1;
});
primary.target = widget.itemCount - 1;
}
if (secondary.target > widget.itemCount - 1) {
setState(() {
secondary.target = widget.itemCount - 1;
});
secondary.target = widget.itemCount - 1;
}
}
}
@@ -465,19 +459,21 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
required List<double> opacityAnimationWeights,
}) async {
final direction = index > primary.target ? 1 : -1;
final itemPosition = primary.itemPositionsNotifier.itemPositions.value
.firstWhereOrNull(
(ItemPosition itemPosition) => itemPosition.index == index);
final itemPosition =
primary.itemPositionsNotifier.itemPositions.value.firstWhereOrNull(
(ItemPosition itemPosition) => itemPosition.index == index,
);
if (itemPosition != null) {
// Scroll directly.
final localScrollAmount = itemPosition.itemLeadingEdge *
primary.scrollController.position.viewportDimension;
await primary.scrollController.animateTo(
primary.scrollController.offset +
localScrollAmount -
alignment * primary.scrollController.position.viewportDimension,
duration: duration,
curve: curve);
primary.scrollController.offset +
localScrollAmount -
alignment * primary.scrollController.position.viewportDimension,
duration: duration,
curve: curve,
);
} else {
final scrollAmount = _screenScrollCount *
primary.scrollController.position.viewportDimension;
@@ -488,7 +484,8 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
startAnimationCallback = () {};
opacity.parent = _opacityAnimation(opacityAnimationWeights).animate(
AnimationController(vsync: this, duration: duration)..forward());
AnimationController(vsync: this, duration: duration)..forward(),
);
secondary.scrollController.jumpTo(-direction *
(_screenScrollCount *
primary.scrollController.position.viewportDimension -
@@ -496,9 +493,10 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
secondary.scrollController.position.viewportDimension));
startCompleter.complete(primary.scrollController.animateTo(
primary.scrollController.offset + direction * scrollAmount,
duration: duration,
curve: curve));
primary.scrollController.offset + direction * scrollAmount,
duration: duration,
curve: curve,
));
endCompleter.complete(secondary.scrollController
.animateTo(0, duration: duration, curve: curve));
});
@@ -548,14 +546,17 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
const endOpacity = 1.0;
return TweenSequence<double>(<TweenSequenceItem<double>>[
TweenSequenceItem<double>(
tween: ConstantTween<double>(startOpacity),
weight: opacityAnimationWeights[0]),
tween: ConstantTween<double>(startOpacity),
weight: opacityAnimationWeights[0],
),
TweenSequenceItem<double>(
tween: Tween<double>(begin: startOpacity, end: endOpacity),
weight: opacityAnimationWeights[1]),
tween: Tween<double>(begin: startOpacity, end: endOpacity),
weight: opacityAnimationWeights[1],
),
TweenSequenceItem<double>(
tween: ConstantTween<double>(endOpacity),
weight: opacityAnimationWeights[2]),
tween: ConstantTween<double>(endOpacity),
weight: opacityAnimationWeights[2],
),
]);
}
@@ -565,11 +566,10 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
position.itemLeadingEdge < 1 && position.itemTrailingEdge > 0);
if (itemPositions.isNotEmpty) {
PageStorage.of(context)!.writeState(
context,
itemPositions.reduce((value, element) =>
value.itemLeadingEdge < element.itemLeadingEdge
? value
: element));
context,
itemPositions.reduce((value, element) =>
value.itemLeadingEdge < element.itemLeadingEdge ? value : element),
);
}
widget.itemPositionsNotifier?.itemPositions.value = itemPositions;
}
@@ -29,13 +29,14 @@ class UnboundedViewport extends Viewport {
List<Widget> slivers = const <Widget>[],
}) : _anchor = anchor,
super(
key: key,
axisDirection: axisDirection,
crossAxisDirection: crossAxisDirection,
offset: offset,
center: center,
cacheExtent: cacheExtent,
slivers: slivers);
key: key,
axisDirection: axisDirection,
crossAxisDirection: crossAxisDirection,
offset: offset,
center: center,
cacheExtent: cacheExtent,
slivers: slivers,
);
// [Viewport] enforces constraints on [Viewport.anchor], so we need our own
// version.
@@ -76,12 +77,13 @@ class UnboundedRenderViewport extends RenderViewport {
double? cacheExtent,
}) : _anchor = anchor,
super(
axisDirection: axisDirection,
crossAxisDirection: crossAxisDirection,
offset: offset,
center: center,
cacheExtent: cacheExtent,
children: children);
axisDirection: axisDirection,
crossAxisDirection: crossAxisDirection,
offset: offset,
center: center,
cacheExtent: cacheExtent,
children: children,
);
static const int _maxLayoutCycles = 10;
@@ -179,8 +181,11 @@ class UnboundedRenderViewport extends RenderViewport {
double correction;
var count = 0;
do {
correction = _attemptLayout(mainAxisExtent, crossAxisExtent,
offset.pixels + centerOffsetAdjustment);
correction = _attemptLayout(
mainAxisExtent,
crossAxisExtent,
offset.pixels + centerOffsetAdjustment,
);
if (correction != 0.0) {
offset.correctBy(correction);
} else {
@@ -200,29 +205,33 @@ class UnboundedRenderViewport extends RenderViewport {
if (count >= _maxLayoutCycles) {
assert(count != 1, 'count not equal to 1');
throw FlutterError(
'A RenderViewport exceeded its maximum number of layout cycles.\n'
'RenderViewport render objects, during layout, can retry if either their '
'slivers or their ViewportOffset decide that the offset should be corrected '
'to take into account information collected during that layout.\n'
'In the case of this RenderViewport object, however, this happened $count '
'times and still there was no consensus on the scroll offset. This usually '
'indicates a bug. Specifically, it means that one of the following three '
'problems is being experienced by the RenderViewport object:\n'
' * One of the RenderSliver children or the ViewportOffset have a bug such'
' that they always think that they need to correct the offset regardless.\n'
' * Some combination of the RenderSliver children and the ViewportOffset'
' have a bad interaction such that one applies a correction then another'
' applies a reverse correction, leading to an infinite loop of corrections.\n'
' * There is a pathological case that would eventually resolve, but it is'
' so complicated that it cannot be resolved in any reasonable number of'
' layout passes.');
'A RenderViewport exceeded its maximum number of layout cycles.\n'
'RenderViewport render objects, during layout, can retry if either their '
'slivers or their ViewportOffset decide that the offset should be corrected '
'to take into account information collected during that layout.\n'
'In the case of this RenderViewport object, however, this happened $count '
'times and still there was no consensus on the scroll offset. This usually '
'indicates a bug. Specifically, it means that one of the following three '
'problems is being experienced by the RenderViewport object:\n'
' * One of the RenderSliver children or the ViewportOffset have a bug such'
' that they always think that they need to correct the offset regardless.\n'
' * Some combination of the RenderSliver children and the ViewportOffset'
' have a bad interaction such that one applies a correction then another'
' applies a reverse correction, leading to an infinite loop of corrections.\n'
' * There is a pathological case that would eventually resolve, but it is'
' so complicated that it cannot be resolved in any reasonable number of'
' layout passes.',
);
}
return true;
}(), 'count needs to be bigger than _maxLayoutCycles');
}
double _attemptLayout(
double mainAxisExtent, double crossAxisExtent, double correctedOffset) {
double mainAxisExtent,
double crossAxisExtent,
double correctedOffset,
) {
assert(!mainAxisExtent.isNaN, 'assert mainAxisExtent.isNaN');
assert(mainAxisExtent >= 0.0, 'assert mainAxisExtent >= 0.0');
assert(crossAxisExtent.isFinite, 'assert crossAxisExtent.isFinite');
@@ -301,7 +310,9 @@ class UnboundedRenderViewport extends RenderViewport {
@override
void updateOutOfBandData(
GrowthDirection growthDirection, SliverGeometry childLayoutGeometry) {
GrowthDirection growthDirection,
SliverGeometry childLayoutGeometry,
) {
switch (growthDirection) {
case GrowthDirection.forward:
_maxScrollExtent += childLayoutGeometry.scrollExtent;