Skip to content

Commit

Permalink
[various] Enable use_build_context_synchronously (flutter#6585)
Browse files Browse the repository at this point in the history
Enables the `use_build_context_synchronously` lint, and fixes violations.

Part of flutter/flutter#76229
  • Loading branch information
stuartmorgan committed Jan 25, 2023
1 parent 8bab180 commit 1e5efd1
Show file tree
Hide file tree
Showing 41 changed files with 304 additions and 204 deletions.
2 changes: 1 addition & 1 deletion analysis_options.yaml
Expand Up @@ -241,7 +241,7 @@ linter:
- unnecessary_to_list_in_spreads
- unrelated_type_equality_checks
- unsafe_html
# - use_build_context_synchronously # LOCAL CHANGE - Needs to be enabled and violations fixed.
- use_build_context_synchronously
# - use_colored_box # not yet tested
# - use_decorated_box # not yet tested
# - use_enums # not yet tested
Expand Down
1 change: 1 addition & 0 deletions packages/file_selector/file_selector/CHANGELOG.md
@@ -1,5 +1,6 @@
## NEXT

* Updates example code for `use_build_context_synchronously` lint.
* Updates minimum Flutter version to 3.0.

## 0.9.2+2
Expand Down
Expand Up @@ -22,10 +22,12 @@ class GetDirectoryPage extends StatelessWidget {
// Operation was canceled by the user.
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(directoryPath),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(directoryPath),
);
}
}

@override
Expand Down
Expand Up @@ -29,10 +29,12 @@ class OpenImagePage extends StatelessWidget {
final String fileName = file.name;
final String filePath = file.path;

await showDialog<void>(
context: context,
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
);
}
}

@override
Expand Down
Expand Up @@ -32,10 +32,12 @@ class OpenMultipleImagesPage extends StatelessWidget {
// Operation was canceled by the user.
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) => MultipleImagesDisplay(files),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => MultipleImagesDisplay(files),
);
}
}

@override
Expand Down
Expand Up @@ -32,10 +32,12 @@ class OpenTextPage extends StatelessWidget {
final String fileName = file.name;
final String fileContent = await file.readAsString();

await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(fileName, fileContent),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(fileName, fileContent),
);
}
}

@override
Expand Down
1 change: 1 addition & 0 deletions packages/file_selector/file_selector_ios/CHANGELOG.md
@@ -1,5 +1,6 @@
## NEXT

* Updates example code for `use_build_context_synchronously` lint.
* Updates minimum Flutter version to 3.0.

## 0.5.0+2
Expand Down
Expand Up @@ -29,10 +29,12 @@ class OpenImagePage extends StatelessWidget {
final String fileName = file.name;
final String filePath = file.path;

await showDialog<void>(
context: context,
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
);
}
}

@override
Expand Down
Expand Up @@ -34,10 +34,12 @@ class OpenMultipleImagesPage extends StatelessWidget {
// Operation was canceled by the user.
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) => MultipleImagesDisplay(files),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => MultipleImagesDisplay(files),
);
}
}

@override
Expand Down
Expand Up @@ -26,10 +26,12 @@ class OpenTextPage extends StatelessWidget {
final String fileName = file.name;
final String fileContent = await file.readAsString();

await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(fileName, fileContent),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(fileName, fileContent),
);
}
}

@override
Expand Down
1 change: 1 addition & 0 deletions packages/file_selector/file_selector_linux/CHANGELOG.md
@@ -1,5 +1,6 @@
## NEXT

* Updates example code for `use_build_context_synchronously` lint.
* Updates minimum Flutter version to 3.0.

## 0.9.1
Expand Down
Expand Up @@ -21,10 +21,12 @@ class GetDirectoryPage extends StatelessWidget {
// Operation was canceled by the user.
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(directoryPath),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(directoryPath),
);
}
}

@override
Expand Down
Expand Up @@ -21,10 +21,13 @@ class GetMultipleDirectoriesPage extends StatelessWidget {
// Operation was canceled by the user.
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(directoryPaths.join('\n')),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) =>
TextDisplay(directoryPaths.join('\n')),
);
}
}

@override
Expand Down
Expand Up @@ -28,10 +28,12 @@ class OpenImagePage extends StatelessWidget {
final String fileName = file.name;
final String filePath = file.path;

await showDialog<void>(
context: context,
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
);
}
}

@override
Expand Down
Expand Up @@ -32,10 +32,12 @@ class OpenMultipleImagesPage extends StatelessWidget {
// Operation was canceled by the user.
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) => MultipleImagesDisplay(files),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => MultipleImagesDisplay(files),
);
}
}

@override
Expand Down
Expand Up @@ -25,10 +25,12 @@ class OpenTextPage extends StatelessWidget {
final String fileName = file.name;
final String fileContent = await file.readAsString();

await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(fileName, fileContent),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(fileName, fileContent),
);
}
}

@override
Expand Down
1 change: 1 addition & 0 deletions packages/file_selector/file_selector_macos/CHANGELOG.md
@@ -1,5 +1,6 @@
## NEXT

* Updates example code for `use_build_context_synchronously` lint.
* Updates minimum Flutter version to 3.0.

## 0.9.0+4
Expand Down
Expand Up @@ -21,10 +21,12 @@ class GetDirectoryPage extends StatelessWidget {
// Operation was canceled by the user.
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(directoryPath),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(directoryPath),
);
}
}

@override
Expand Down
Expand Up @@ -28,10 +28,12 @@ class OpenImagePage extends StatelessWidget {
final String fileName = file.name;
final String filePath = file.path;

await showDialog<void>(
context: context,
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
);
}
}

@override
Expand Down
Expand Up @@ -32,10 +32,12 @@ class OpenMultipleImagesPage extends StatelessWidget {
// Operation was canceled by the user.
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) => MultipleImagesDisplay(files),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => MultipleImagesDisplay(files),
);
}
}

@override
Expand Down
Expand Up @@ -25,10 +25,12 @@ class OpenTextPage extends StatelessWidget {
final String fileName = file.name;
final String fileContent = await file.readAsString();

await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(fileName, fileContent),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(fileName, fileContent),
);
}
}

@override
Expand Down
1 change: 1 addition & 0 deletions packages/file_selector/file_selector_windows/CHANGELOG.md
@@ -1,5 +1,6 @@
## NEXT

* Updates example code for `use_build_context_synchronously` lint.
* Updates minimum Flutter version to 3.0.

## 0.9.1+4
Expand Down
Expand Up @@ -21,10 +21,12 @@ class GetDirectoryPage extends StatelessWidget {
// Operation was canceled by the user.
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(directoryPath),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(directoryPath),
);
}
}

@override
Expand Down
Expand Up @@ -28,10 +28,12 @@ class OpenImagePage extends StatelessWidget {
final String fileName = file.name;
final String filePath = file.path;

await showDialog<void>(
context: context,
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => ImageDisplay(fileName, filePath),
);
}
}

@override
Expand Down
Expand Up @@ -32,10 +32,12 @@ class OpenMultipleImagesPage extends StatelessWidget {
// Operation was canceled by the user.
return;
}
await showDialog<void>(
context: context,
builder: (BuildContext context) => MultipleImagesDisplay(files),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => MultipleImagesDisplay(files),
);
}
}

@override
Expand Down
Expand Up @@ -25,10 +25,12 @@ class OpenTextPage extends StatelessWidget {
final String fileName = file.name;
final String fileContent = await file.readAsString();

await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(fileName, fileContent),
);
if (context.mounted) {
await showDialog<void>(
context: context,
builder: (BuildContext context) => TextDisplay(fileName, fileContent),
);
}
}

@override
Expand Down
3 changes: 2 additions & 1 deletion packages/image_picker/image_picker_windows/CHANGELOG.md
@@ -1,5 +1,6 @@
## NEXT
## 0.1.0+4

* Updates example code for `use_build_context_synchronously` lint.
* Updates minimum Flutter version to 3.0.

## 0.1.0+3
Expand Down

0 comments on commit 1e5efd1

Please sign in to comment.