mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
enable lint prefer_void_to_null (#23174)
* enable lint prefer_void_to_null * replace last Null by void
This commit is contained in:
parent
7a63fac0a2
commit
936dea28da
@ -100,7 +100,7 @@ and access native features and SDKs on Android and iOS.
|
|||||||
Accessing platform features is easy. Here is a snippet from our <a href="https://github.com/flutter/flutter/tree/master/examples/platform_channel">interop example</a>:
|
Accessing platform features is easy. Here is a snippet from our <a href="https://github.com/flutter/flutter/tree/master/examples/platform_channel">interop example</a>:
|
||||||
|
|
||||||
```dart
|
```dart
|
||||||
Future<Null> getBatteryLevel() async {
|
Future<void> getBatteryLevel() async {
|
||||||
var batteryLevel = 'unknown';
|
var batteryLevel = 'unknown';
|
||||||
try {
|
try {
|
||||||
int result = await methodChannel.invokeMethod('getBatteryLevel');
|
int result = await methodChannel.invokeMethod('getBatteryLevel');
|
||||||
|
@ -136,7 +136,7 @@ linter:
|
|||||||
- prefer_iterable_whereType
|
- prefer_iterable_whereType
|
||||||
- prefer_single_quotes
|
- prefer_single_quotes
|
||||||
- prefer_typing_uninitialized_variables
|
- prefer_typing_uninitialized_variables
|
||||||
# - prefer_void_to_null # not yet tested
|
- prefer_void_to_null
|
||||||
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
|
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
|
||||||
- recursive_getters
|
- recursive_getters
|
||||||
- slash_for_doc_comments
|
- slash_for_doc_comments
|
||||||
|
@ -327,7 +327,7 @@ void processBlock(Line line, List<String> block, List<Section> sections) {
|
|||||||
sections.add(Section(line, 'dynamic expression$_expressionId = ', block.toList(), ';'));
|
sections.add(Section(line, 'dynamic expression$_expressionId = ', block.toList(), ';'));
|
||||||
} else if (block.first.startsWith('await ')) {
|
} else if (block.first.startsWith('await ')) {
|
||||||
_expressionId += 1;
|
_expressionId += 1;
|
||||||
sections.add(Section(line, 'Future<Null> expression$_expressionId() async { ', block.toList(), ' }'));
|
sections.add(Section(line, 'Future<void> expression$_expressionId() async { ', block.toList(), ' }'));
|
||||||
} else if (block.first.startsWith('class ') || block.first.startsWith('enum ')) {
|
} else if (block.first.startsWith('class ') || block.first.startsWith('enum ')) {
|
||||||
sections.add(Section(line, null, block.toList(), null));
|
sections.add(Section(line, null, block.toList(), null));
|
||||||
} else if ((block.first.startsWith('_') || block.first.startsWith('final ')) && block.first.contains(' = ')) {
|
} else if ((block.first.startsWith('_') || block.first.startsWith('final ')) && block.first.contains(' = ')) {
|
||||||
|
@ -176,7 +176,7 @@ enum AnimationBehavior {
|
|||||||
/// controllers using Dart's asynchronous syntax for awaiting [Future] objects:
|
/// controllers using Dart's asynchronous syntax for awaiting [Future] objects:
|
||||||
///
|
///
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// Future<Null> fadeOutAndUpdateState() async {
|
/// Future<void> fadeOutAndUpdateState() async {
|
||||||
/// try {
|
/// try {
|
||||||
/// await fadeAnimationController.forward().orCancel;
|
/// await fadeAnimationController.forward().orCancel;
|
||||||
/// await sizeAnimationController.forward().orCancel;
|
/// await sizeAnimationController.forward().orCancel;
|
||||||
|
@ -45,7 +45,7 @@ import 'bottom_tab_bar.dart';
|
|||||||
/// child: const Text('Next page'),
|
/// child: const Text('Next page'),
|
||||||
/// onPressed: () {
|
/// onPressed: () {
|
||||||
/// Navigator.of(context).push(
|
/// Navigator.of(context).push(
|
||||||
/// CupertinoPageRoute<Null>(
|
/// CupertinoPageRoute<void>(
|
||||||
/// builder: (BuildContext context) {
|
/// builder: (BuildContext context) {
|
||||||
/// return CupertinoPageScaffold(
|
/// return CupertinoPageScaffold(
|
||||||
/// navigationBar: CupertinoNavigationBar(
|
/// navigationBar: CupertinoNavigationBar(
|
||||||
|
@ -178,7 +178,7 @@ abstract class BindingBase {
|
|||||||
assert(callback != null);
|
assert(callback != null);
|
||||||
_lockCount += 1;
|
_lockCount += 1;
|
||||||
final Future<void> future = callback();
|
final Future<void> future = callback();
|
||||||
assert(future != null, 'The lockEvents() callback returned null; it should return a Future<Null> that completes when the lock is to expire.');
|
assert(future != null, 'The lockEvents() callback returned null; it should return a Future<void> that completes when the lock is to expire.');
|
||||||
future.whenComplete(() {
|
future.whenComplete(() {
|
||||||
_lockCount -= 1;
|
_lockCount -= 1;
|
||||||
if (!locked) {
|
if (!locked) {
|
||||||
|
@ -121,8 +121,8 @@ class Dialog extends StatelessWidget {
|
|||||||
/// and returns a [Future] that completes when the dialog is dismissed.
|
/// and returns a [Future] that completes when the dialog is dismissed.
|
||||||
///
|
///
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// Future<Null> _neverSatisfied() async {
|
/// Future<void> _neverSatisfied() async {
|
||||||
/// return showDialog<Null>(
|
/// return showDialog<void>(
|
||||||
/// context: context,
|
/// context: context,
|
||||||
/// barrierDismissible: false, // user must tap button!
|
/// barrierDismissible: false, // user must tap button!
|
||||||
/// builder: (BuildContext context) {
|
/// builder: (BuildContext context) {
|
||||||
@ -390,7 +390,7 @@ class SimpleDialogOption extends StatelessWidget {
|
|||||||
/// that doesn't mention every value in the enum.
|
/// that doesn't mention every value in the enum.
|
||||||
///
|
///
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// Future<Null> _askedToLead() async {
|
/// Future<void> _askedToLead() async {
|
||||||
/// switch (await showDialog<Department>(
|
/// switch (await showDialog<Department>(
|
||||||
/// context: context,
|
/// context: context,
|
||||||
/// builder: (BuildContext context) {
|
/// builder: (BuildContext context) {
|
||||||
|
@ -93,6 +93,7 @@ abstract class PopupMenuEntry<T> extends StatefulWidget {
|
|||||||
/// * [showMenu], a method to dynamically show a popup menu at a given location.
|
/// * [showMenu], a method to dynamically show a popup menu at a given location.
|
||||||
/// * [PopupMenuButton], an [IconButton] that automatically shows a menu when
|
/// * [PopupMenuButton], an [IconButton] that automatically shows a menu when
|
||||||
/// it is tapped.
|
/// it is tapped.
|
||||||
|
// ignore: prefer_void_to_null, https://github.com/dart-lang/sdk/issues/34416
|
||||||
class PopupMenuDivider extends PopupMenuEntry<Null> {
|
class PopupMenuDivider extends PopupMenuEntry<Null> {
|
||||||
/// Creates a horizontal divider for a popup menu.
|
/// Creates a horizontal divider for a popup menu.
|
||||||
///
|
///
|
||||||
@ -106,6 +107,7 @@ class PopupMenuDivider extends PopupMenuEntry<Null> {
|
|||||||
final double height;
|
final double height;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
// ignore: prefer_void_to_null, https://github.com/dart-lang/sdk/issues/34416
|
||||||
bool represents(Null value) => false;
|
bool represents(Null value) => false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1076,14 +1076,13 @@ abstract class State<T extends StatefulWidget> extends Diagnosticable {
|
|||||||
/// the increment is wrapped in the `setState`:
|
/// the increment is wrapped in the `setState`:
|
||||||
///
|
///
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// Future<Null> _incrementCounter() async {
|
/// Future<void> _incrementCounter() async {
|
||||||
/// setState(() {
|
/// setState(() {
|
||||||
/// _counter++;
|
/// _counter++;
|
||||||
/// });
|
/// });
|
||||||
/// Directory directory = await getApplicationDocumentsDirectory();
|
/// Directory directory = await getApplicationDocumentsDirectory();
|
||||||
/// final String dirName = directory.path;
|
/// final String dirName = directory.path;
|
||||||
/// await File('$dir/counter.txt').writeAsString('$_counter');
|
/// await File('$dir/counter.txt').writeAsString('$_counter');
|
||||||
/// return null;
|
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -14,7 +14,7 @@ import 'framework.dart';
|
|||||||
|
|
||||||
// Examples can assume:
|
// Examples can assume:
|
||||||
// class Intl { static String message(String s, { String name, String locale }) => ''; }
|
// class Intl { static String message(String s, { String name, String locale }) => ''; }
|
||||||
// Future<Null> initializeMessages(String locale) => null;
|
// Future<void> initializeMessages(String locale) => null;
|
||||||
|
|
||||||
// Used by loadAll() to record LocalizationsDelegate.load() futures we're
|
// Used by loadAll() to record LocalizationsDelegate.load() futures we're
|
||||||
// waiting for.
|
// waiting for.
|
||||||
@ -308,7 +308,7 @@ class _LocalizationsScope extends InheritedWidget {
|
|||||||
///
|
///
|
||||||
/// static Future<MyLocalizations> load(Locale locale) {
|
/// static Future<MyLocalizations> load(Locale locale) {
|
||||||
/// return initializeMessages(locale.toString())
|
/// return initializeMessages(locale.toString())
|
||||||
/// .then((Null _) {
|
/// .then((void _) {
|
||||||
/// return MyLocalizations(locale);
|
/// return MyLocalizations(locale);
|
||||||
/// });
|
/// });
|
||||||
/// }
|
/// }
|
||||||
|
@ -334,7 +334,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<Null> longPress(Duration timeout) async {
|
Future<void> longPress(Duration timeout) async {
|
||||||
final TestGesture gesture = await tester.startGesture(const Offset(400.0, 50.0));
|
final TestGesture gesture = await tester.startGesture(const Offset(400.0, 50.0));
|
||||||
await tester.pump(timeout);
|
await tester.pump(timeout);
|
||||||
await gesture.up();
|
await gesture.up();
|
||||||
|
@ -40,7 +40,7 @@ class _AsyncScope {
|
|||||||
/// in a call to TestAsyncUtils.guard(), as follows:
|
/// in a call to TestAsyncUtils.guard(), as follows:
|
||||||
///
|
///
|
||||||
/// ```dart
|
/// ```dart
|
||||||
/// Future<Null> myTestFunction() => TestAsyncUtils.guard(() async {
|
/// Future<void> myTestFunction() => TestAsyncUtils.guard(() async {
|
||||||
/// // ...
|
/// // ...
|
||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
|
Loading…
Reference in New Issue
Block a user