Skip to content
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

[various] Remove unnecessary null checks #4060

Merged
merged 9 commits into from
May 22, 2023
Prev Previous commit
Next Next commit
Fix warnings
  • Loading branch information
stuartmorgan committed May 22, 2023
commit a5074878319f51596ec6e130427ad24b9ab62311
6 changes: 2 additions & 4 deletions packages/camera/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
child: Center(
child: AspectRatio(
aspectRatio:
localVideoController.value.size != null
? localVideoController.value.aspectRatio
: 1.0,
localVideoController.value.aspectRatio,
child: VideoPlayer(localVideoController)),
),
),
Expand Down Expand Up @@ -1000,7 +998,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
: VideoPlayerController.file(File(videoFile!.path));

videoPlayerListener = () {
if (videoController != null && videoController!.value.size != null) {
if (videoController != null) {
// Refreshing the state to update video player with the correct ratio.
if (mounted) {
setState(() {});
Expand Down
6 changes: 2 additions & 4 deletions packages/camera/camera_android/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
child: Center(
child: AspectRatio(
aspectRatio:
localVideoController.value.size != null
? localVideoController.value.aspectRatio
: 1.0,
localVideoController.value.aspectRatio,
child: VideoPlayer(localVideoController)),
),
),
Expand Down Expand Up @@ -1008,7 +1006,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
: VideoPlayerController.file(File(videoFile!.path));

videoPlayerListener = () {
if (videoController != null && videoController!.value.size != null) {
if (videoController != null) {
// Refreshing the state to update video player with the correct ratio.
if (mounted) {
setState(() {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
child: Center(
child: AspectRatio(
aspectRatio:
localVideoController.value.size != null
? localVideoController.value.aspectRatio
: 1.0,
localVideoController.value.aspectRatio,
child: VideoPlayer(localVideoController)),
),
),
Expand Down Expand Up @@ -985,7 +983,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
: VideoPlayerController.file(File(videoFile!.path));

videoPlayerListener = () {
if (videoController != null && videoController!.value.size != null) {
if (videoController != null) {
// Refreshing the state to update video player with the correct ratio.
if (mounted) {
setState(() {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ class SystemServicesFlutterApiImpl implements SystemServicesFlutterApi {
void onDeviceOrientationChanged(String orientation) {
final DeviceOrientation deviceOrientation =
deserializeDeviceOrientation(orientation);
if (deviceOrientation == null) {
return;
}
SystemServices.deviceOrientationChangedStreamController
.add(DeviceOrientationChangedEvent(deviceOrientation));
}
Expand Down
6 changes: 2 additions & 4 deletions packages/camera/camera_avfoundation/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
child: Center(
child: AspectRatio(
aspectRatio:
localVideoController.value.size != null
? localVideoController.value.aspectRatio
: 1.0,
localVideoController.value.aspectRatio,
child: VideoPlayer(localVideoController)),
),
),
Expand Down Expand Up @@ -1008,7 +1006,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
: VideoPlayerController.file(File(videoFile!.path));

videoPlayerListener = () {
if (videoController != null && videoController!.value.size != null) {
if (videoController != null) {
// Refreshing the state to update video player with the correct ratio.
if (mounted) {
setState(() {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class CameraEvent {
/// Build a Camera Event, that relates a `cameraId`.
///
/// The `cameraId` is the ID of the camera that triggered the event.
const CameraEvent(this.cameraId) : assert(cameraId != null);
const CameraEvent(this.cameraId);

/// The ID of the Camera this event is associated to.
final int cameraId;
Expand Down
4 changes: 1 addition & 3 deletions packages/camera/camera_web/lib/src/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,7 @@ class Camera {
_onVideoRecordingErrorSubscription =
mediaRecorder!.onError.listen((html.Event event) {
final html.ErrorEvent error = event as html.ErrorEvent;
if (error != null) {
videoRecordingErrorController.add(error);
}
videoRecordingErrorController.add(error);
});

if (maxVideoDuration != null) {
Expand Down
18 changes: 9 additions & 9 deletions packages/dynamic_layouts/lib/src/staggered_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class SliverGridStaggeredTileLayout extends DynamicSliverGridLayout {
required this.crossAxisSpacing,
required this.childCrossAxisExtent,
required this.scrollDirection,
}) : assert(crossAxisCount != null && crossAxisCount > 0),
assert(crossAxisSpacing != null && crossAxisSpacing >= 0),
assert(childCrossAxisExtent != null && childCrossAxisExtent >= 0);
}) : assert(crossAxisCount > 0),
assert(crossAxisSpacing >= 0),
assert(childCrossAxisExtent >= 0);

/// The number of children in the cross axis.
final int crossAxisCount;
Expand Down Expand Up @@ -200,9 +200,9 @@ class DynamicSliverGridDelegateWithFixedCrossAxisCount
required super.crossAxisCount,
super.mainAxisSpacing = 0.0,
super.crossAxisSpacing = 0.0,
}) : assert(crossAxisCount != null && crossAxisCount > 0),
assert(mainAxisSpacing != null && mainAxisSpacing >= 0),
assert(crossAxisSpacing != null && crossAxisSpacing >= 0);
}) : assert(crossAxisCount > 0),
assert(mainAxisSpacing >= 0),
assert(crossAxisSpacing >= 0);

bool _debugAssertIsValid() {
assert(crossAxisCount > 0);
Expand Down Expand Up @@ -283,9 +283,9 @@ class DynamicSliverGridDelegateWithMaxCrossAxisExtent
required super.maxCrossAxisExtent,
super.mainAxisSpacing = 0.0,
super.crossAxisSpacing = 0.0,
}) : assert(maxCrossAxisExtent != null && maxCrossAxisExtent > 0),
assert(mainAxisSpacing != null && mainAxisSpacing >= 0),
assert(crossAxisSpacing != null && crossAxisSpacing >= 0);
}) : assert(maxCrossAxisExtent > 0),
assert(mainAxisSpacing >= 0),
assert(crossAxisSpacing >= 0);

bool _debugAssertIsValid(double crossAxisExtent) {
assert(crossAxisExtent > 0.0);
Expand Down
19 changes: 9 additions & 10 deletions packages/dynamic_layouts/lib/src/wrap_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ class SliverGridWrappingTileLayout extends DynamicSliverGridLayout {
required this.childCrossAxisExtent,
required this.crossAxisExtent,
required this.scrollDirection,
}) : assert(mainAxisSpacing != null && mainAxisSpacing >= 0),
assert(crossAxisSpacing != null && crossAxisSpacing >= 0),
assert(childMainAxisExtent != null && childMainAxisExtent >= 0),
assert(childCrossAxisExtent != null && childCrossAxisExtent >= 0),
assert(crossAxisExtent != null && crossAxisExtent >= 0),
assert(scrollDirection != null &&
(scrollDirection == Axis.horizontal ||
scrollDirection == Axis.vertical));
}) : assert(mainAxisSpacing >= 0),
assert(crossAxisSpacing >= 0),
assert(childMainAxisExtent >= 0),
assert(childCrossAxisExtent >= 0),
assert(crossAxisExtent >= 0),
assert(scrollDirection == Axis.horizontal ||
scrollDirection == Axis.vertical);

/// The direction in which the layout should be built.
final Axis scrollDirection;
Expand Down Expand Up @@ -216,8 +215,8 @@ class SliverGridDelegateWithWrapping extends SliverGridDelegate {
this.crossAxisSpacing = 0.0,
this.childCrossAxisExtent = double.infinity,
this.childMainAxisExtent = double.infinity,
}) : assert(mainAxisSpacing != null && mainAxisSpacing >= 0),
assert(crossAxisSpacing != null && crossAxisSpacing >= 0);
}) : assert(mainAxisSpacing >= 0),
assert(crossAxisSpacing >= 0);

/// The number of pixels from the leading edge of one tile to the trailing
/// edge of the same tile in the main axis.
Expand Down
3 changes: 0 additions & 3 deletions packages/flutter_markdown/test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ class TestAssetBundle extends CachingAssetBundle {
io.File('${rootDirectory.path}/test/assets/images/logo.png');

final ByteData asset = ByteData.view(file.readAsBytesSync().buffer);
if (asset == null) {
throw FlutterError('Unable to load asset: $key');
}
return asset;
} else {
throw ArgumentError('Unknown asset key: $key');
Expand Down
6 changes: 2 additions & 4 deletions packages/flutter_migrate/lib/src/base/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,6 @@ class BufferLogger extends Logger {
String? progressId,
int progressIndicatorPadding = kDefaultStatusPadding,
}) {
assert(progressIndicatorPadding != null);
printStatus(message);
return SilentStatus(
stopwatch: _stopwatchFactory.createStopwatch(),
Expand Down Expand Up @@ -983,7 +982,6 @@ class AnonymousSpinnerStatus extends Status {

void _callback(Timer timer) {
assert(this.timer == timer);
assert(timer != null);
assert(timer.isActive);
_writeToStdOut(_backspaceChar * _lastAnimationFrameLength);
ticks += 1;
Expand Down Expand Up @@ -1147,7 +1145,7 @@ String wrapText(
int? indent,
}) {
assert(columnWidth >= 0);
if (text == null || text.isEmpty) {
if (text.isEmpty) {
return '';
}
indent ??= 0;
Expand Down Expand Up @@ -1231,7 +1229,7 @@ List<String> _wrapTextAsLines(
required int columnWidth,
required bool shouldWrap,
}) {
if (text == null || text.isEmpty) {
if (text.isEmpty) {
return <String>[''];
}
assert(start >= 0);
Expand Down
3 changes: 1 addition & 2 deletions packages/flutter_migrate/lib/src/base/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class FlutterProjectFactory {
/// Returns a [FlutterProject] view of the given directory or a ToolExit error,
/// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
FlutterProject fromDirectory(Directory directory) {
assert(directory != null);
return projects.putIfAbsent(directory.path, () {
return FlutterProject(directory);
});
Expand All @@ -36,7 +35,7 @@ class FlutterProjectFactory {

/// Represents the contents of a Flutter project at the specified [directory].
class FlutterProject {
FlutterProject(this.directory) : assert(directory != null);
FlutterProject(this.directory);

/// Returns a [FlutterProject] view of the current directory or a ToolExit error,
/// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
Expand Down
4 changes: 1 addition & 3 deletions packages/flutter_migrate/lib/src/base/terminal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ class AnsiTerminal implements Terminal {

@override
String bolden(String message) {
assert(message != null);
if (!supportsColor || message.isEmpty) {
return message;
}
Expand All @@ -256,8 +255,7 @@ class AnsiTerminal implements Terminal {

@override
String color(String message, TerminalColor color) {
assert(message != null);
if (!supportsColor || color == null || message.isEmpty) {
if (!supportsColor || message.isEmpty) {
return message;
}
final StringBuffer buffer = StringBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,6 @@ class FlutterProjectMetadata {
/// needs to be able to write the .migrate_config file into legacy apps.
void writeFile({File? outputFile}) {
outputFile = outputFile ?? file;
if (outputFile == null) {
// In-memory FlutterProjectMetadata instances requires an output file to
// be passed or specified in the constructor.
throw const FileSystemException(
'No outputFile specified to write .metadata to. Initialize with a file or provide one when writing.');
}
outputFile
..createSync(recursive: true)
..writeAsStringSync(toString(), flush: true);
Expand Down
2 changes: 0 additions & 2 deletions packages/flutter_migrate/test/src/fakes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class MemoryStdout extends MemoryIOSink implements io.Stdout {
@override
bool get hasTerminal => _hasTerminal;
set hasTerminal(bool value) {
assert(value != null);
_hasTerminal = value;
}

Expand All @@ -139,7 +138,6 @@ class MemoryStdout extends MemoryIOSink implements io.Stdout {
@override
bool get supportsAnsiEscapes => _supportsAnsiEscapes;
set supportsAnsiEscapes(bool value) {
assert(value != null);
_supportsAnsiEscapes = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ class MigrateProject extends Project {
}) async {
this.dir = dir;
_appPath = dir.path;
if (androidLocalProperties != null) {
writeFile(fileSystem.path.join(dir.path, 'android', 'local.properties'),
androidLocalProperties);
}
writeFile(fileSystem.path.join(dir.path, 'android', 'local.properties'),
androidLocalProperties);
final Directory tempDir = createResolvedTempDirectorySync('cipd_dest.');
final Directory depotToolsDir =
createResolvedTempDirectorySync('depot_tools.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class GoogleMapController {
CameraPosition initialCameraPosition,
_GoogleMapState googleMapState,
) async {
assert(id != null);
await GoogleMapsFlutterPlatform.instance.init(id);
return GoogleMapController._(
googleMapState,
Expand Down Expand Up @@ -100,7 +99,6 @@ class GoogleMapController {
///
/// The returned [Future] completes after listeners have been notified.
Future<void> _updateMarkers(MarkerUpdates markerUpdates) {
assert(markerUpdates != null);
return GoogleMapsFlutterPlatform.instance
.updateMarkers(markerUpdates, mapId: mapId);
}
Expand All @@ -112,7 +110,6 @@ class GoogleMapController {
///
/// The returned [Future] completes after listeners have been notified.
Future<void> _updatePolygons(PolygonUpdates polygonUpdates) {
assert(polygonUpdates != null);
return GoogleMapsFlutterPlatform.instance
.updatePolygons(polygonUpdates, mapId: mapId);
}
Expand All @@ -124,7 +121,6 @@ class GoogleMapController {
///
/// The returned [Future] completes after listeners have been notified.
Future<void> _updatePolylines(PolylineUpdates polylineUpdates) {
assert(polylineUpdates != null);
return GoogleMapsFlutterPlatform.instance
.updatePolylines(polylineUpdates, mapId: mapId);
}
Expand All @@ -136,7 +132,6 @@ class GoogleMapController {
///
/// The returned [Future] completes after listeners have been notified.
Future<void> _updateCircles(CircleUpdates circleUpdates) {
assert(circleUpdates != null);
return GoogleMapsFlutterPlatform.instance
.updateCircles(circleUpdates, mapId: mapId);
}
Expand All @@ -160,7 +155,6 @@ class GoogleMapController {
/// in-memory cache of tiles. If you want to cache tiles for longer, you
/// should implement an on-disk cache.
Future<void> clearTileCache(TileOverlayId tileOverlayId) async {
assert(tileOverlayId != null);
return GoogleMapsFlutterPlatform.instance
.clearTileCache(tileOverlayId, mapId: mapId);
}
Expand Down Expand Up @@ -234,7 +228,6 @@ class GoogleMapController {
/// * [hideMarkerInfoWindow] to hide the Info Window.
/// * [isMarkerInfoWindowShown] to check if the Info Window is showing.
Future<void> showMarkerInfoWindow(MarkerId markerId) {
assert(markerId != null);
return GoogleMapsFlutterPlatform.instance
.showMarkerInfoWindow(markerId, mapId: mapId);
}
Expand All @@ -248,7 +241,6 @@ class GoogleMapController {
/// * [showMarkerInfoWindow] to show the Info Window.
/// * [isMarkerInfoWindowShown] to check if the Info Window is showing.
Future<void> hideMarkerInfoWindow(MarkerId markerId) {
assert(markerId != null);
return GoogleMapsFlutterPlatform.instance
.hideMarkerInfoWindow(markerId, mapId: mapId);
}
Expand All @@ -262,7 +254,6 @@ class GoogleMapController {
/// * [showMarkerInfoWindow] to show the Info Window.
/// * [hideMarkerInfoWindow] to hide the Info Window.
Future<bool> isMarkerInfoWindowShown(MarkerId markerId) {
assert(markerId != null);
return GoogleMapsFlutterPlatform.instance
.isMarkerInfoWindowShown(markerId, mapId: mapId);
}
Expand Down
Loading