Skip to content

[scrollable_positioned_list] migrate pedantic to flutter lint #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions packages/scrollable_positioned_list/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: package:lints/recommended.yaml
analyzer:
language:
strict-casts: true
strict-raw-types: true
16 changes: 16 additions & 0 deletions packages/scrollable_positioned_list/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# example

A new Flutter project.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
13 changes: 7 additions & 6 deletions packages/scrollable_positioned_list/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

Expand All @@ -11,8 +12,6 @@ const minItemHeight = 20.0;
const maxItemHeight = 150.0;
const scrollDuration = Duration(seconds: 2);

const randomMax = 1 << 32;

void main() {
runApp(ScrollablePositionedListExample());
}
Expand Down Expand Up @@ -46,7 +45,7 @@ class ScrollablePositionedListPage extends StatefulWidget {
const ScrollablePositionedListPage({Key? key}) : super(key: key);

@override
_ScrollablePositionedListPageState createState() =>
State<ScrollablePositionedListPage> createState() =>
_ScrollablePositionedListPageState();
}

Expand All @@ -69,14 +68,16 @@ class _ScrollablePositionedListPageState
void initState() {
super.initState();
final heightGenerator = Random(328902348);
final colorGenerator = Random(42490823);
itemHeights = List<double>.generate(
numberOfItems,
(int _) =>
heightGenerator.nextDouble() * (maxItemHeight - minItemHeight) +
minItemHeight);
itemColors = List<Color>.generate(numberOfItems,
(int _) => Color(colorGenerator.nextInt(randomMax)).withOpacity(1));
itemColors = List<Color>.generate(
numberOfItems,
(int _) => Color(
(Random().nextDouble() * 0xFFFFFF).toInt() << 0,
).withOpacity(1.0));
}

@override
Expand Down
3 changes: 2 additions & 1 deletion packages/scrollable_positioned_list/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ publish_to: 'none'

environment:
sdk: '>=2.12.0-0 <3.0.0'
flutter: '>=1.13.8'
flutter: '>=2.12.0'

dependencies:
flutter:
Expand All @@ -15,3 +15,4 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
lints: ^2.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class _RegisteredElement extends ProxyElement {
@override
void mount(Element? parent, dynamic newSlot) {
super.mount(parent, newSlot);
final _inheritedRegistryWidget =
final inheritedRegistryWidget =
dependOnInheritedWidgetOfExactType<_InheritedRegistryWidget>()!;
_registryWidgetState = _inheritedRegistryWidget.state;
_registryWidgetState = inheritedRegistryWidget.state;
_registryWidgetState.registeredElements.add(this);
_registryWidgetState.widget.elementNotifier?.value =
_registryWidgetState.registeredElements;
Expand All @@ -78,9 +78,9 @@ class _RegisteredElement extends ProxyElement {
@override
void didChangeDependencies() {
super.didChangeDependencies();
final _inheritedRegistryWidget =
final inheritedRegistryWidget =
dependOnInheritedWidgetOfExactType<_InheritedRegistryWidget>()!;
_registryWidgetState = _inheritedRegistryWidget.state;
_registryWidgetState = inheritedRegistryWidget.state;
_registryWidgetState.registeredElements.add(this);
_registryWidgetState.widget.elementNotifier?.value =
_registryWidgetState.registeredElements;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ItemPosition {
@override
bool operator ==(dynamic other) {
if (other.runtimeType != runtimeType) return false;
final ItemPosition otherPosition = other;
final ItemPosition otherPosition = other as ItemPosition;
return otherPosition.index == index &&
otherPosition.itemLeadingEdge == itemLeadingEdge &&
otherPosition.itemTrailingEdge == itemTrailingEdge;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class PositionedList extends StatefulWidget {
this.addSemanticIndexes = true,
this.addRepaintBoundaries = true,
this.addAutomaticKeepAlives = true,
}) : assert(itemCount != null),
assert(itemBuilder != null),
assert((positionedIndex == 0) || (positionedIndex < itemCount)),
}) : assert((positionedIndex == 0) || (positionedIndex < itemCount)),
super(key: key);

/// Number of items the [itemBuilder] can produce.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ class ScrollablePositionedList extends StatefulWidget {
this.addAutomaticKeepAlives = true,
this.addRepaintBoundaries = true,
this.minCacheExtent,
}) : assert(itemCount != null),
assert(itemBuilder != null),
itemPositionsNotifier = itemPositionsListener as ItemPositionsNotifier?,
}) : itemPositionsNotifier = itemPositionsListener as ItemPositionsNotifier?,
separatorBuilder = null,
super(key: key);

Expand All @@ -78,9 +76,7 @@ class ScrollablePositionedList extends StatefulWidget {
this.addAutomaticKeepAlives = true,
this.addRepaintBoundaries = true,
this.minCacheExtent,
}) : assert(itemCount != null),
assert(itemBuilder != null),
assert(separatorBuilder != null),
}) : assert(separatorBuilder != null),
itemPositionsNotifier = itemPositionsListener as ItemPositionsNotifier?,
super(key: key);

Expand Down Expand Up @@ -270,12 +266,13 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>

bool _isTransitioning = false;

var _animationController;
late AnimationController _animationController;

@override
void initState() {
super.initState();
ItemPosition? initialPosition = PageStorage.of(context)!.readState(context);
ItemPosition? initialPosition =
PageStorage.of(context).readState(context) as ItemPosition?;
primary.target = initialPosition?.index ?? widget.initialScrollIndex;
primary.alignment =
initialPosition?.itemLeadingEdge ?? widget.initialAlignment;
Expand All @@ -285,6 +282,7 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
widget.itemScrollController?._attach(this);
primary.itemPositionsNotifier.itemPositions.addListener(_updatePositions);
secondary.itemPositionsNotifier.itemPositions.addListener(_updatePositions);
_animationController = AnimationController(vsync: this);
}

@override
Expand All @@ -299,7 +297,7 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
.removeListener(_updatePositions);
secondary.itemPositionsNotifier.itemPositions
.removeListener(_updatePositions);
_animationController?.dispose();
_animationController.dispose();
super.dispose();
}

Expand Down Expand Up @@ -487,7 +485,7 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
startAnimationCallback = () {
SchedulerBinding.instance.addPostFrameCallback((_) {
startAnimationCallback = () {};
_animationController?.dispose();
_animationController.dispose();
_animationController =
AnimationController(vsync: this, duration: duration)..forward();
opacity.parent = _opacityAnimation(opacityAnimationWeights)
Expand Down Expand Up @@ -568,7 +566,7 @@ class _ScrollablePositionedListState extends State<ScrollablePositionedList>
.where((ItemPosition position) =>
position.itemLeadingEdge < 1 && position.itemTrailingEdge > 0);
if (itemPositions.isNotEmpty) {
PageStorage.of(context)!.writeState(
PageStorage.of(context).writeState(
context,
itemPositions.reduce((value, element) =>
value.itemLeadingEdge < element.itemLeadingEdge
Expand Down
7 changes: 2 additions & 5 deletions packages/scrollable_positioned_list/lib/src/viewport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ class UnboundedRenderViewport extends RenderViewport {

@override
set anchor(double value) {
assert(value != null);
if (value == _anchor) return;
_anchor = value;
markNeedsLayout();
Expand All @@ -124,8 +123,6 @@ class UnboundedRenderViewport extends RenderViewport {

@override
Rect describeSemanticsClip(RenderSliver? child) {
assert(axis != null);

if (_calculatedCacheExtent == null) {
return semanticBounds;
}
Expand Down Expand Up @@ -178,7 +175,6 @@ class UnboundedRenderViewport extends RenderViewport {
double correction;
var count = 0;
do {
assert(offset.pixels != null);
correction = _attemptLayout(mainAxisExtent, crossAxisExtent,
offset.pixels + centerOffsetAdjustment);
if (correction != 0.0) {
Expand All @@ -189,8 +185,9 @@ class UnboundedRenderViewport extends RenderViewport {
final bottom = _maxScrollExtent - mainAxisExtent * (1.0 - anchor);
final maxScrollOffset = math.max(math.min(0.0, top), bottom);
final minScrollOffset = math.min(top, maxScrollOffset);
if (offset.applyContentDimensions(minScrollOffset, maxScrollOffset))
if (offset.applyContentDimensions(minScrollOffset, maxScrollOffset)) {
break;
}
// *** End of difference from [RenderViewport].
}
count += 1;
Expand Down
16 changes: 5 additions & 11 deletions packages/scrollable_positioned_list/lib/src/wrapping.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,10 @@ abstract class CustomViewport extends MultiChildRenderObjectWidget {
this.cacheExtentStyle = CacheExtentStyle.pixel,
this.clipBehavior = Clip.hardEdge,
List<Widget> slivers = const <Widget>[],
}) : assert(offset != null),
assert(slivers != null),
assert(center == null ||
}) : assert(center == null ||
slivers.where((Widget child) => child.key == center).length == 1),
assert(cacheExtentStyle != null),
assert(cacheExtentStyle != CacheExtentStyle.viewport ||
cacheExtent != null),
assert(clipBehavior != null),
super(key: key, children: slivers);

/// The direction in which the [offset]'s [ViewportOffset.pixels] increases.
Expand Down Expand Up @@ -497,7 +493,6 @@ abstract class CustomViewport extends MultiChildRenderObjectWidget {
/// otherwise, the default cross axis direction is downwards.
static AxisDirection getDefaultCrossAxisDirection(
BuildContext context, AxisDirection axisDirection) {
assert(axisDirection != null);
switch (axisDirection) {
case AxisDirection.up:
assert(debugCheckHasDirectionality(
Expand Down Expand Up @@ -528,7 +523,7 @@ abstract class CustomViewport extends MultiChildRenderObjectWidget {
CustomRenderViewport createRenderObject(BuildContext context);

@override
_ViewportElement createElement() => _ViewportElement(this);
MultiChildRenderObjectElement createElement() => _ViewportElement(this);

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
Expand Down Expand Up @@ -662,11 +657,9 @@ abstract class CustomRenderViewport
double? cacheExtent,
CacheExtentStyle cacheExtentStyle = CacheExtentStyle.pixel,
Clip clipBehavior = Clip.hardEdge,
}) : assert(anchor != null),
assert(anchor >= 0.0 && anchor <= 1.0),
}) : assert(anchor >= 0.0 && anchor <= 1.0),
assert(cacheExtentStyle != CacheExtentStyle.viewport ||
cacheExtent != null),
assert(clipBehavior != null),
_center = center,
super(
axisDirection: axisDirection,
Expand Down Expand Up @@ -719,8 +712,9 @@ abstract class CustomRenderViewport

@override
void setupParentData(RenderObject child) {
if (child.parentData is! CustomSliverPhysicalContainerParentData)
if (child.parentData is! CustomSliverPhysicalContainerParentData) {
child.parentData = CustomSliverPhysicalContainerParentData();
}
}

/// The relative position of the zero scroll offset.
Expand Down
3 changes: 1 addition & 2 deletions packages/scrollable_positioned_list/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ version: 0.3.5
description: >
A list with helper methods to programmatically scroll to an item.
homepage: https://github.com/google/flutter.widgets/tree/master/packages/scrollable_positioned_list

environment:
sdk: '>=2.12.0 <3.0.0'
flutter: '>=2.12.0'
Expand All @@ -14,6 +13,6 @@ dependencies:
collection: ^1.15.0

dev_dependencies:
pedantic: ^1.10.0-0
flutter_test:
sdk: flutter
lints: ^2.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pedantic/pedantic.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

const screenHeight = 400.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void main() {

testWidgets('Does not crash when updated offscreen',
(WidgetTester tester) async {
late var setState;
late StateSetter setState;
bool updated = false;

// There's 0 relayout boundaries in this subtree.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pedantic/pedantic.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

const screenHeight = 400.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pedantic/pedantic.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import 'package:scrollable_positioned_list/src/scroll_view.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pedantic/pedantic.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
import 'package:scrollable_positioned_list/src/scroll_view.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pedantic/pedantic.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

const screenHeight = 400.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pedantic/pedantic.dart';
import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

const screenHeight = 400.0;
Expand Down