Skip to content

Commit

Permalink
Enable lints library_private_types_in_public_api, `sort_child_prope…
Browse files Browse the repository at this point in the history
…rties_last` and `use_key_in_widget_constructors` (flutter#5428)
  • Loading branch information
asashour authored and mauricioluz committed Jan 26, 2023
1 parent 7dea23f commit d229293
Show file tree
Hide file tree
Showing 229 changed files with 936 additions and 526 deletions.
5 changes: 3 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ linter:
- leading_newlines_in_multiline_strings
- library_names
- library_prefixes
- library_private_types_in_public_api
# - lines_longer_than_80_chars # not required by flutter style
- list_remove_unrelated_type
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
Expand Down Expand Up @@ -197,7 +198,7 @@ linter:
- recursive_getters
# - sized_box_for_whitespace # not yet tested
- slash_for_doc_comments
# - sort_child_properties_last # not yet tested
- sort_child_properties_last
- sort_constructors_first
- sort_unnamed_constructors_first
- test_types_in_equals
Expand Down Expand Up @@ -229,7 +230,7 @@ linter:
- use_full_hex_values_for_flutter_colors
# - use_function_type_syntax_for_parameters # not yet tested
- use_is_even_rather_than_modulo
# - use_key_in_widget_constructors # not yet tested
- use_key_in_widget_constructors
- use_late_for_private_fields_and_variables
- use_raw_strings
- use_rethrow_when_possible
Expand Down
4 changes: 3 additions & 1 deletion packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## NEXT
## 0.9.4+22

* Removes unnecessary imports.
* Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors
lint warnings.

## 0.9.4+21

Expand Down
14 changes: 9 additions & 5 deletions packages/camera/camera/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,22 @@ Here is a small example flutter app displaying a full screen camera preview.
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
late List<CameraDescription> cameras;
late List<CameraDescription> _cameras;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
cameras = await availableCameras();
runApp(CameraApp());
_cameras = await availableCameras();
runApp(const CameraApp());
}
/// CameraApp is the Main Application.
class CameraApp extends StatefulWidget {
/// Default Constructor
const CameraApp({Key? key}) : super(key: key);
@override
_CameraAppState createState() => _CameraAppState();
State<CameraApp> createState() => _CameraAppState();
}
class _CameraAppState extends State<CameraApp> {
Expand All @@ -109,7 +113,7 @@ class _CameraAppState extends State<CameraApp> {
@override
void initState() {
super.initState();
controller = CameraController(cameras[0], ResolutionPreset.max);
controller = CameraController(_cameras[0], ResolutionPreset.max);
controller.initialize().then((_) {
if (!mounted) {
return;
Expand Down
60 changes: 33 additions & 27 deletions packages/camera/camera/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import 'dart:async';
import 'dart:io';

Expand All @@ -13,9 +11,13 @@ import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:video_player/video_player.dart';

/// Camera example home widget.
class CameraExampleHome extends StatefulWidget {
/// Default Constructor
const CameraExampleHome({Key? key}) : super(key: key);

@override
_CameraExampleHomeState createState() {
State<CameraExampleHome> createState() {
return _CameraExampleHomeState();
}
}
Expand All @@ -34,7 +36,7 @@ IconData getCameraLensIcon(CameraLensDirection direction) {
}
}

void logError(String code, String? message) {
void _logError(String code, String? message) {
if (message != null) {
print('Error: $code\nError Message: $message');
} else {
Expand Down Expand Up @@ -134,12 +136,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
children: <Widget>[
Expanded(
child: Container(
child: Padding(
padding: const EdgeInsets.all(1.0),
child: Center(
child: _cameraPreviewWidget(),
),
),
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(
Expand All @@ -150,6 +146,12 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
width: 3.0,
),
),
child: Padding(
padding: const EdgeInsets.all(1.0),
child: Center(
child: _cameraPreviewWidget(),
),
),
),
),
_captureControlRowWidget(),
Expand Down Expand Up @@ -233,6 +235,8 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
Container()
else
SizedBox(
width: 64.0,
height: 64.0,
child: (localVideoController == null)
? (
// The captured image on the web contains a network-accessible URL
Expand All @@ -243,6 +247,8 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
? Image.network(imageFile!.path)
: Image.file(File(imageFile!.path)))
: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.pink)),
child: Center(
child: AspectRatio(
aspectRatio:
Expand All @@ -251,11 +257,7 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
: 1.0,
child: VideoPlayer(localVideoController)),
),
decoration: BoxDecoration(
border: Border.all(color: Colors.pink)),
),
width: 64.0,
height: 64.0,
),
],
),
Expand Down Expand Up @@ -394,7 +396,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
mainAxisSize: MainAxisSize.max,
children: <Widget>[
TextButton(
child: const Text('AUTO'),
style: styleAuto,
onPressed: controller != null
? () =>
Expand All @@ -406,21 +407,22 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
showInSnackBar('Resetting exposure point');
}
},
child: const Text('AUTO'),
),
TextButton(
child: const Text('LOCKED'),
style: styleLocked,
onPressed: controller != null
? () =>
onSetExposureModeButtonPressed(ExposureMode.locked)
: null,
child: const Text('LOCKED'),
),
TextButton(
child: const Text('RESET OFFSET'),
style: styleLocked,
onPressed: controller != null
? () => controller!.setExposureOffset(0.0)
: null,
child: const Text('RESET OFFSET'),
),
],
),
Expand Down Expand Up @@ -479,7 +481,6 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
mainAxisSize: MainAxisSize.max,
children: <Widget>[
TextButton(
child: const Text('AUTO'),
style: styleAuto,
onPressed: controller != null
? () => onSetFocusModeButtonPressed(FocusMode.auto)
Expand All @@ -490,13 +491,14 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
}
showInSnackBar('Resetting focus point');
},
child: const Text('AUTO'),
),
TextButton(
child: const Text('LOCKED'),
style: styleLocked,
onPressed: controller != null
? () => onSetFocusModeButtonPressed(FocusMode.locked)
: null,
child: const Text('LOCKED'),
),
],
),
Expand Down Expand Up @@ -582,13 +584,13 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
onNewCameraSelected(description);
};

if (cameras.isEmpty) {
if (_cameras.isEmpty) {
_ambiguate(SchedulerBinding.instance)?.addPostFrameCallback((_) async {
showInSnackBar('No camera found.');
});
return const Text('None');
} else {
for (final CameraDescription cameraDescription in cameras) {
for (final CameraDescription cameraDescription in _cameras) {
toggles.add(
SizedBox(
width: 90.0,
Expand Down Expand Up @@ -1014,31 +1016,35 @@ class _CameraExampleHomeState extends State<CameraExampleHome>
}

void _showCameraException(CameraException e) {
logError(e.code, e.description);
_logError(e.code, e.description);
showInSnackBar('Error: ${e.code}\n${e.description}');
}
}

/// CameraApp is the Main Application.
class CameraApp extends StatelessWidget {
/// Default Constructor
const CameraApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
return const MaterialApp(
home: CameraExampleHome(),
);
}
}

List<CameraDescription> cameras = <CameraDescription>[];
List<CameraDescription> _cameras = <CameraDescription>[];

Future<void> main() async {
// Fetch the available cameras before initializing the app.
try {
WidgetsFlutterBinding.ensureInitialized();
cameras = await availableCameras();
_cameras = await availableCameras();
} on CameraException catch (e) {
logError(e.code, e.description);
_logError(e.code, e.description);
}
runApp(CameraApp());
runApp(const CameraApp());
}

/// This allows a value of type T or T? to be treated as a value of type T?.
Expand Down
16 changes: 9 additions & 7 deletions packages/camera/camera/example/lib/readme_full_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

// #docregion FullAppExample
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';

late List<CameraDescription> cameras;
late List<CameraDescription> _cameras;

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

cameras = await availableCameras();
runApp(CameraApp());
_cameras = await availableCameras();
runApp(const CameraApp());
}

/// CameraApp is the Main Application.
class CameraApp extends StatefulWidget {
/// Default Constructor
const CameraApp({Key? key}) : super(key: key);

@override
_CameraAppState createState() => _CameraAppState();
State<CameraApp> createState() => _CameraAppState();
}

class _CameraAppState extends State<CameraApp> {
Expand All @@ -28,7 +30,7 @@ class _CameraAppState extends State<CameraApp> {
@override
void initState() {
super.initState();
controller = CameraController(cameras[0], ResolutionPreset.max);
controller = CameraController(_cameras[0], ResolutionPreset.max);
controller.initialize().then((_) {
if (!mounted) {
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/example/test/main_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Test snackbar', (WidgetTester tester) async {
WidgetsFlutterBinding.ensureInitialized();
await tester.pumpWidget(CameraApp());
await tester.pumpWidget(const CameraApp());
await tester.pumpAndSettle();
expect(find.byType(SnackBar), findsOneWidget);
});
Expand Down
3 changes: 2 additions & 1 deletion packages/camera/camera/lib/src/camera_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import 'package:flutter/services.dart';
/// A widget showing a live camera preview.
class CameraPreview extends StatelessWidget {
/// Creates a preview widget for the given camera controller.
const CameraPreview(this.controller, {this.child});
const CameraPreview(this.controller, {Key? key, this.child})
: super(key: key);

/// The controller for the camera that the preview is shown for.
final CameraController controller;
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing
Dart.
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.9.4+21
version: 0.9.4+22

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down
5 changes: 5 additions & 0 deletions packages/camera/camera_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.1+5

* Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors
lint warnings.

## 0.2.1+4

* Migrates from `ui.hash*` to `Object.hash*`.
Expand Down
5 changes: 4 additions & 1 deletion packages/camera/camera_web/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

import 'package:flutter/material.dart';

void main() => runApp(MyApp());
void main() => runApp(const MyApp());

/// App for testing
class MyApp extends StatelessWidget {
/// Default Constructor
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return const Directionality(
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_web
description: A Flutter plugin for getting information about and controlling the camera on Web.
repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.2.1+4
version: 0.2.1+5

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
4 changes: 3 additions & 1 deletion packages/camera/camera_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## NEXT
## 0.1.0+1

* Removes unnecessary imports.
* Fixes library_private_types_in_public_api, sort_child_properties_last and use_key_in_widget_constructors
lint warnings.

## 0.1.0

Expand Down
Loading

0 comments on commit d229293

Please sign in to comment.