Unverified Commit b09c70a9 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Fix mounted checks (#137778)

Fixes in preparation for https://dart-review.googlesource.com/c/sdk/+/330561.

The change referenced above tightens the `use_build_context_synchronously` to ensure that `mounted` is checked on the appropriate `BuildContext` or `State`. This change fixes up the flutter/flutter in preparation of this new enforcement.
parent f15f2313
...@@ -175,7 +175,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> { ...@@ -175,7 +175,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
Future<void> saveRecordedEvents(ByteData data, BuildContext context) async { Future<void> saveRecordedEvents(ByteData data, BuildContext context) async {
if (await channel.invokeMethod<bool>('getStoragePermission') ?? false) { if (await channel.invokeMethod<bool>('getStoragePermission') ?? false) {
if (mounted) { if (context.mounted) {
showMessage(context, 'External storage permissions are required to save events'); showMessage(context, 'External storage permissions are required to save events');
} }
return; return;
...@@ -185,12 +185,12 @@ class MotionEventsBodyState extends State<MotionEventsBody> { ...@@ -185,12 +185,12 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
// This test only runs on Android so we can assume path separator is '/'. // This test only runs on Android so we can assume path separator is '/'.
final File file = File('${outDir?.path}/$kEventsFileName'); final File file = File('${outDir?.path}/$kEventsFileName');
await file.writeAsBytes(data.buffer.asUint8List(0, data.lengthInBytes), flush: true); await file.writeAsBytes(data.buffer.asUint8List(0, data.lengthInBytes), flush: true);
if (!mounted) { if (!context.mounted) {
return; return;
} }
showMessage(context, 'Saved original events to ${file.path}'); showMessage(context, 'Saved original events to ${file.path}');
} catch (e) { } catch (e) {
if (!mounted) { if (!context.mounted) {
return; return;
} }
showMessage(context, 'Failed saving $e'); showMessage(context, 'Failed saving $e');
......
...@@ -80,7 +80,7 @@ class _TabbedComponentDemoScaffoldState extends State<TabbedComponentDemoScaffol ...@@ -80,7 +80,7 @@ class _TabbedComponentDemoScaffoldState extends State<TabbedComponentDemoScaffol
final Uri uri = Uri.parse(url); final Uri uri = Uri.parse(url);
if (await canLaunchUrl(uri)) { if (await canLaunchUrl(uri)) {
await launchUrl(uri); await launchUrl(uri);
} else if (mounted) { } else if (context.mounted) {
showDialog<void>( showDialog<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
......
...@@ -157,7 +157,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> { ...@@ -157,7 +157,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
Future<void> saveRecordedEvents(ByteData data, BuildContext context) async { Future<void> saveRecordedEvents(ByteData data, BuildContext context) async {
if (await channel.invokeMethod<bool>('getStoragePermission') != true) { if (await channel.invokeMethod<bool>('getStoragePermission') != true) {
if (mounted) { if (context.mounted) {
showMessage(context, 'External storage permissions are required to save events'); showMessage(context, 'External storage permissions are required to save events');
} }
return; return;
...@@ -167,12 +167,12 @@ class MotionEventsBodyState extends State<MotionEventsBody> { ...@@ -167,12 +167,12 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
// This test only runs on Android so we can assume path separator is '/'. // This test only runs on Android so we can assume path separator is '/'.
final File file = File('${outDir.path}/$kEventsFileName'); final File file = File('${outDir.path}/$kEventsFileName');
await file.writeAsBytes(data.buffer.asUint8List(0, data.lengthInBytes), flush: true); await file.writeAsBytes(data.buffer.asUint8List(0, data.lengthInBytes), flush: true);
if (!mounted) { if (!context.mounted) {
return; return;
} }
showMessage(context, 'Saved original events to ${file.path}'); showMessage(context, 'Saved original events to ${file.path}');
} catch (e) { } catch (e) {
if (!mounted) { if (!context.mounted) {
return; return;
} }
showMessage(context, 'Failed saving $e'); showMessage(context, 'Failed saving $e');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment