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
@@ -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);
@@ -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();
}
@@ -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(),
);
@@ -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
@@ -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(
@@ -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));
});
@@ -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)),
@@ -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(
@@ -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(
@@ -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)),
@@ -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))
@@ -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,
@@ -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();
@@ -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';
@@ -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>{};
@@ -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);
}
@@ -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(
@@ -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));
}
});
@@ -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;
@@ -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());
}

Some files were not shown because too many files have changed in this diff Show More