Prefer void to null (#22977)

* Future<void> main

* Future<void>.delayed

* prefer_void_to_Null

* address review comments
This commit is contained in:
Alexandre Ardhuin
2018-10-16 22:03:06 +02:00
committed by GitHub
parent 5efe095895
commit 0fb84e96c7
139 changed files with 373 additions and 385 deletions

View File

@@ -26,7 +26,7 @@ void main() {
for (String path in paths) {
await driver.waitUntilNoTransientCallbacks();
// TBD: when #11021 has been resolved, this shouldn't be necessary.
await new Future<Null>.delayed(const Duration(milliseconds: 500));
await new Future<void>.delayed(const Duration(milliseconds: 500));
final List<int> pixels = await driver.screenshot();
final File file = new File(path);
await file.writeAsBytes(pixels);

View File

@@ -22,12 +22,12 @@ void main() {
}
}
Future<Null> scrollUpOneEntry() async {
Future<void> scrollUpOneEntry() async {
await tester.dragFrom(const Offset(200.0, 200.0), const Offset(0.0, -88.00));
await tester.pumpAndSettle();
}
Future<Null> tapEntry(String title) async {
Future<void> tapEntry(String title) async {
await tester.tap(find.text(title));
await tester.pumpAndSettle();
}

View File

@@ -351,7 +351,7 @@ class _DemoBottomAppBar extends StatelessWidget {
IconButton(
icon: const Icon(Icons.menu),
onPressed: () {
showModalBottomSheet<Null>(
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) => const _DemoDrawer(),
);

View File

@@ -64,7 +64,7 @@ class _DateTimePicker extends StatelessWidget {
final ValueChanged<DateTime> selectDate;
final ValueChanged<TimeOfDay> selectTime;
Future<Null> _selectDate(BuildContext context) async {
Future<void> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
@@ -75,7 +75,7 @@ class _DateTimePicker extends StatelessWidget {
selectDate(picked);
}
Future<Null> _selectTime(BuildContext context) async {
Future<void> _selectTime(BuildContext context) async {
final TimeOfDay picked = await showTimePicker(
context: context,
initialTime: selectedTime

View File

@@ -180,7 +180,7 @@ class DialogDemoState extends State<DialogDemo> {
context: context,
initialTime: _selectedTime
)
.then<Null>((TimeOfDay value) {
.then<void>((TimeOfDay value) {
if (value != null && value != _selectedTime) {
_selectedTime = value;
_scaffoldKey.currentState.showSnackBar(SnackBar(

View File

@@ -49,7 +49,7 @@ class DateTimeItem extends StatelessWidget {
firstDate: date.subtract(const Duration(days: 30)),
lastDate: date.add(const Duration(days: 30))
)
.then<Null>((DateTime value) {
.then<void>((DateTime value) {
if (value != null)
onChanged(DateTime(value.year, value.month, value.day, time.hour, time.minute));
});
@@ -76,7 +76,7 @@ class DateTimeItem extends StatelessWidget {
context: context,
initialTime: time
)
.then<Null>((TimeOfDay value) {
.then<void>((TimeOfDay value) {
if (value != null)
onChanged(DateTime(date.year, date.month, date.day, value.hour, value.minute));
});

View File

@@ -32,7 +32,7 @@ class ListDemo extends StatefulWidget {
class _ListDemoState extends State<ListDemo> {
static final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
PersistentBottomSheetController<Null> _bottomSheet;
PersistentBottomSheetController<void> _bottomSheet;
_MaterialListType _itemType = _MaterialListType.threeLine;
bool _dense = false;
bool _showAvatars = true;
@@ -51,7 +51,7 @@ class _ListDemoState extends State<ListDemo> {
}
void _showConfigurationSheet() {
final PersistentBottomSheetController<Null> bottomSheet = scaffoldKey.currentState.showBottomSheet((BuildContext bottomSheetContext) {
final PersistentBottomSheetController<void> bottomSheet = scaffoldKey.currentState.showBottomSheet<void>((BuildContext bottomSheetContext) {
return Container(
decoration: const BoxDecoration(
border: Border(top: BorderSide(color: Colors.black26)),

View File

@@ -26,10 +26,10 @@ class OverscrollDemoState extends State<OverscrollDemo> {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'
];
Future<Null> _handleRefresh() {
final Completer<Null> completer = Completer<Null>();
Timer(const Duration(seconds: 3), () { completer.complete(null); });
return completer.future.then<Null>((_) {
Future<void> _handleRefresh() {
final Completer<void> completer = Completer<void>();
Timer(const Duration(seconds: 3), () { completer.complete(); });
return completer.future.then<void>((_) {
_scaffoldKey.currentState?.showSnackBar(SnackBar(
content: const Text('Refresh complete'),
action: SnackBarAction(

View File

@@ -28,7 +28,7 @@ class _PersistentBottomSheetDemoState extends State<PersistentBottomSheetDemo> {
setState(() { // disable the button
_showBottomSheetCallback = null;
});
_scaffoldKey.currentState.showBottomSheet<Null>((BuildContext context) {
_scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) {
final ThemeData themeData = Theme.of(context);
return Container(
decoration: BoxDecoration(

View File

@@ -39,7 +39,7 @@ class _ListItem {
class _ListDemoState extends State<ReorderableListDemo> {
static final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
PersistentBottomSheetController<Null> _bottomSheet;
PersistentBottomSheetController<void> _bottomSheet;
_ReorderableListType _itemType = _ReorderableListType.threeLine;
bool _reverseSort = false;
final List<_ListItem> _items = <String>[
@@ -58,7 +58,7 @@ class _ListDemoState extends State<ReorderableListDemo> {
void _showConfigurationSheet() {
setState(() {
_bottomSheet = scaffoldKey.currentState.showBottomSheet((BuildContext bottomSheetContext) {
_bottomSheet = scaffoldKey.currentState.showBottomSheet<void>((BuildContext bottomSheetContext) {
return DecoratedBox(
decoration: const BoxDecoration(
border: Border(top: BorderSide(color: Colors.black26)),

View File

@@ -69,7 +69,7 @@ class _TabsFabDemoState extends State<TabsFabDemo> with SingleTickerProviderStat
}
void _showExplanatoryText() {
_scaffoldKey.currentState.showBottomSheet<Null>((BuildContext context) {
_scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) {
return Container(
decoration: BoxDecoration(
border: Border(top: BorderSide(color: Theme.of(context).dividerColor))

View File

@@ -362,7 +362,7 @@ class _ShrineHomeState extends State<ShrineHome> {
static final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>(debugLabel: 'Shrine Home');
static final _ShrineGridDelegate gridDelegate = _ShrineGridDelegate();
Future<Null> _showOrderPage(Product product) async {
Future<void> _showOrderPage(Product product) async {
final Order order = _shoppingCart[product] ?? Order(product: product);
final Order completedOrder = await Navigator.push(context, ShrineOrderRoute(
order: order,

View File

@@ -66,7 +66,7 @@ class VideoCard extends StatelessWidget {
pageBuilder: fullScreenRoutePageBuilder,
);
route.completed.then((void result) {
route.completed.then((void value) {
controller.setVolume(0.0);
});
@@ -272,7 +272,7 @@ class ConnectivityOverlay extends StatefulWidget {
});
final Widget child;
final Completer<Null> connectedCompleter;
final Completer<void> connectedCompleter;
final GlobalKey<ScaffoldState> scaffoldKey;
@override
@@ -362,14 +362,14 @@ class _VideoDemoState extends State<VideoDemo>
);
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
final Completer<Null> connectedCompleter = Completer<Null>();
final Completer<void> connectedCompleter = Completer<void>();
bool isSupported = true;
@override
void initState() {
super.initState();
Future<Null> initController(VideoPlayerController controller) async {
Future<void> initController(VideoPlayerController controller) async {
controller.setLooping(true);
controller.setVolume(0.0);
controller.play();

View File

@@ -138,7 +138,7 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
@override
void didChangeDependencies() {
getExampleCode(widget.exampleCodeTag, DefaultAssetBundle.of(context)).then<Null>((String code) {
getExampleCode(widget.exampleCodeTag, DefaultAssetBundle.of(context)).then<void>((String code) {
if (mounted) {
setState(() {
_exampleCode = code ?? 'Example code not found';

View File

@@ -17,7 +17,7 @@ Future<String> getExampleCode(String tag, AssetBundle bundle) async {
return _exampleCode[tag];
}
Future<Null> _parseExampleCode(AssetBundle bundle) async {
Future<void> _parseExampleCode(AssetBundle bundle) async {
final String code = await bundle.loadString('lib/gallery/example_code.dart') ??
'// lib/gallery/example_code.dart not found\n';
_exampleCode = <String, String>{};

View File

@@ -39,7 +39,7 @@ const List<String> _kSkippedDemoTitles = <String>[
'Video',
];
Future<Null> main() async {
Future<void> main() async {
try {
// Verify that _kUnsynchronizedDemos and _kSkippedDemos identify
// demos that actually exist.
@@ -89,8 +89,8 @@ class _LiveWidgetController extends LiveWidgetController {
bool frameSync = true;
/// Waits until at the end of a frame the provided [condition] is [true].
Future<Null> _waitUntilFrame(bool condition(), [Completer<Null> completer]) {
completer ??= Completer<Null>();
Future<void> _waitUntilFrame(bool condition(), [Completer<void> completer]) {
completer ??= Completer<void>();
if (!condition()) {
SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) {
_waitUntilFrame(condition, completer);
@@ -112,11 +112,11 @@ class _LiveWidgetController extends LiveWidgetController {
}
@override
Future<Null> tap(Finder finder, { int pointer }) async {
Future<void> tap(Finder finder, { int pointer }) async {
await super.tap(await _waitForElement(finder), pointer: pointer);
}
Future<Null> scrollIntoView(Finder finder, {double alignment}) async {
Future<void> scrollIntoView(Finder finder, {double alignment}) async {
final Finder target = await _waitForElement(finder);
await Scrollable.ensureVisible(target.evaluate().single, duration: const Duration(milliseconds: 100), alignment: alignment);
}

View File

@@ -46,7 +46,7 @@ void verifyToStringOutput(String name, String route, String testString) {
}
}
Future<Null> smokeDemo(WidgetTester tester, GalleryDemo demo) async {
Future<void> smokeDemo(WidgetTester tester, GalleryDemo demo) async {
// Don't use pumpUntilNoTransientCallbacks in this function, because some of
// the smoketests have infinitely-running animations (e.g. the progress
// indicators demo).
@@ -94,7 +94,7 @@ Future<Null> smokeDemo(WidgetTester tester, GalleryDemo demo) async {
await tester.pump(const Duration(milliseconds: 400)); // Wait until it has finished.
}
Future<Null> smokeOptionsPage(WidgetTester tester) async {
Future<void> smokeOptionsPage(WidgetTester tester) async {
final Finder showOptionsPageButton = find.byTooltip('Toggle options page');
// Show the options page
@@ -133,7 +133,7 @@ Future<Null> smokeOptionsPage(WidgetTester tester) async {
await tester.pumpAndSettle();
}
Future<Null> smokeGallery(WidgetTester tester) async {
Future<void> smokeGallery(WidgetTester tester) async {
bool sendFeedbackButtonPressed = false;
await tester.pumpWidget(

View File

@@ -31,13 +31,13 @@ void main() {
// Scroll down
for (int i = 0; i < 5; i++) {
await driver.scroll(demoList, 0.0, -300.0, const Duration(milliseconds: 300));
await Future<Null>.delayed(const Duration(milliseconds: 500));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
// Scroll up
for (int i = 0; i < 5; i++) {
await driver.scroll(demoList, 0.0, 300.0, const Duration(milliseconds: 300));
await Future<Null>.delayed(const Duration(milliseconds: 500));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
});

View File

@@ -55,7 +55,7 @@ List<String> _allDemos = <String>[];
/// Extracts event data from [events] recorded by timeline, validates it, turns
/// it into a histogram, and saves to a JSON file.
Future<Null> saveDurationsHistogram(List<Map<String, dynamic>> events, String outputPath) async {
Future<void> saveDurationsHistogram(List<Map<String, dynamic>> events, String outputPath) async {
final Map<String, List<int>> durations = <String, List<int>>{};
Map<String, dynamic> startEvent;
@@ -121,7 +121,7 @@ Future<Null> saveDurationsHistogram(List<Map<String, dynamic>> events, String ou
/// Scrolls each demo menu item into view, launches it, then returns to the
/// home screen twice.
Future<Null> runDemos(List<String> demos, FlutterDriver driver) async {
Future<void> runDemos(List<String> demos, FlutterDriver driver) async {
final SerializableFinder demoList = find.byValueKey('GalleryDemoList');
String currentDemoCategory;

View File

@@ -30,7 +30,7 @@ class LifecycleObserver extends WidgetsBindingObserver {
Future<void> main() async {
runApp(const GalleryApp());
await endOfAnimation();
await Future<Null>.delayed(const Duration(milliseconds: 50));
await Future<void>.delayed(const Duration(milliseconds: 50));
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
WidgetsBinding.instance.addObserver(LifecycleObserver());
}

View File

@@ -36,7 +36,7 @@ Future<void> main() async {
),
));
await SchedulerBinding.instance.endOfFrame;
await Future<Null>.delayed(const Duration(milliseconds: 50));
await Future<void>.delayed(const Duration(milliseconds: 50));
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
await ready.future;
@@ -55,12 +55,12 @@ Future<void> main() async {
debugPrint('Navigating...');
await controller.tap(find.text('Material'));
await Future<Null>.delayed(const Duration(milliseconds: 150));
await Future<void>.delayed(const Duration(milliseconds: 150));
final Finder demoList = find.byKey(const Key('GalleryDemoList'));
final Finder demoItem = find.text('Text fields');
do {
await controller.drag(demoList, const Offset(0.0, -300.0));
await Future<Null>.delayed(const Duration(milliseconds: 20));
await Future<void>.delayed(const Duration(milliseconds: 20));
} while (!demoItem.precache());
// Ensure that the center of the "Text fields" item is visible

View File

@@ -136,12 +136,12 @@ class CalculationManager {
// isolates do not have access to the root bundle. However, the loading
// process is asynchronous, so the UI will not block while the file is
// loaded.
rootBundle.loadString('services/data.json').then<Null>((String data) {
rootBundle.loadString('services/data.json').then<void>((String data) {
if (isRunning) {
final CalculationMessage message = CalculationMessage(data, _receivePort.sendPort);
// Spawn an isolate to JSON-parse the file contents. The JSON parsing
// is synchronous, so if done in the main isolate, the UI would block.
Isolate.spawn<CalculationMessage>(_calculate, message).then<Null>((Isolate isolate) {
Isolate.spawn<CalculationMessage>(_calculate, message).then<void>((Isolate isolate) {
if (!isRunning) {
isolate.kill(priority: Isolate.immediate);
} else {

View File

@@ -16,7 +16,7 @@ void main() {
final Finder finder = find.byType(GestureDemo);
MaterialColor getSwatch() => tester.state<GestureDemoState>(finder).swatch;
Future<Null> tap() async {
Future<void> tap() async {
final Offset topLeft = tester.getTopLeft(finder);
await tester.tapAt(tester.getSize(finder).center(topLeft));
await tester.pump(const Duration(seconds: 1));

View File

@@ -21,7 +21,7 @@ class _PlatformChannelState extends State<PlatformChannel> {
String _batteryLevel = 'Battery level: unknown.';
String _chargingStatus = 'Battery status: unknown.';
Future<Null> _getBatteryLevel() async {
Future<void> _getBatteryLevel() async {
String batteryLevel;
try {
final int result = await methodChannel.invokeMethod('getBatteryLevel');

View File

@@ -21,7 +21,7 @@ class _PlatformChannelState extends State<PlatformChannel> {
String _batteryLevel = 'Battery level: unknown.';
String _chargingStatus = 'Battery status: unknown.';
Future<Null> _getBatteryLevel() async {
Future<void> _getBatteryLevel() async {
String batteryLevel;
try {
final int result = await methodChannel.invokeMethod('getBatteryLevel');

View File

@@ -45,7 +45,7 @@ class _MyHomePageState extends State<MyHomePage> {
});
}
Future<Null> _launchPlatformCount() async {
Future<void> _launchPlatformCount() async {
final int platformCounter =
await _methodChannel.invokeMethod('switchView', _counter);
setState(() {

View File

@@ -77,7 +77,7 @@ class StockData extends ChangeNotifier {
static bool actuallyFetchData = true;
void _fetchNextChunk() {
_httpClient.get(_urlToFetch(_nextChunk++)).then<Null>((http.Response response) {
_httpClient.get(_urlToFetch(_nextChunk++)).then<void>((http.Response response) {
final String json = response.body;
if (json == null) {
debugPrint('Failed to load stock data chunk ${_nextChunk - 1}');

View File

@@ -263,7 +263,7 @@ class StockHomeState extends State<StockHome> {
Navigator.pushNamed(context, '/stock:${stock.symbol}');
},
onShow: (Stock stock) {
_scaffoldKey.currentState.showBottomSheet<Null>((BuildContext context) => StockSymbolBottomSheet(stock: stock));
_scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) => StockSymbolBottomSheet(stock: stock));
},
);
}

View File

@@ -29,13 +29,13 @@ void main() {
// Scroll down
for (int i = 0; i < 5; i++) {
await driver.scroll(stockList, 0.0, -300.0, const Duration(milliseconds: 300));
await Future<Null>.delayed(const Duration(milliseconds: 500));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
// Scroll up
for (int i = 0; i < 5; i++) {
await driver.scroll(stockList, 0.0, 300.0, const Duration(milliseconds: 300));
await Future<Null>.delayed(const Duration(milliseconds: 500));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
});