Skip to content

Commit 2ba4e71

Browse files
committed
lint: Directly ignore use_build_context_synchronously, where needed
This workaround recently stopped working: this inverted form of early return no longer persuades the lint rule not to complain when we go on to use `context`. Not sure exactly what change caused that; it happened with a new Flutter version from master/main in recent weeks, presumably due to a new Dart SDK version rolling through there. Since the workaround is no longer effective, just switch to the straightforward early return, and use a lint-ignore comment pointing at the underlying issue that causes the lint rule to complain there: https://github.com/dart-lang/linter/issues/4007 That issue was recently fixed in the linter repo's main branch. The fix rolled yesterday into the Dart SDK: dart-lang/sdk@f09ce66 but that hasn't quite yet rolled through to Flutter. Once it does, we'll be able to cut these.
1 parent 436a3bd commit 2ba4e71

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lib/widgets/clipboard.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ void copyWithPopup({
1919
await Clipboard.setData(data);
2020
final deviceInfo = await DeviceInfoPlugin().deviceInfo;
2121

22-
if (context.mounted) {} // https://github.com/dart-lang/linter/issues/4007
23-
else {
22+
// https://github.com/dart-lang/linter/issues/4007
23+
// ignore: use_build_context_synchronously
24+
if (!context.mounted) {
2425
return;
2526
}
2627

lib/widgets/compose_box.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,9 @@ abstract class _AttachUploadsButton extends StatelessWidget {
306306
return; // Nothing to do (getFiles handles user feedback)
307307
}
308308

309-
if (context.mounted) {} // https://github.com/dart-lang/linter/issues/4007
310-
else {
309+
// https://github.com/dart-lang/linter/issues/4007
310+
// ignore: use_build_context_synchronously
311+
if (!context.mounted) {
311312
return;
312313
}
313314

lib/widgets/login.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ class _AddAccountPageState extends State<AddAccountPage> {
4949

5050
// TODO(#35): show feedback that we're working, while fetching server settings
5151
final serverSettings = await getServerSettings(realmUrl: url);
52-
if (context.mounted) {} // https://github.com/dart-lang/linter/issues/4007
53-
else {
52+
// https://github.com/dart-lang/linter/issues/4007
53+
// ignore: use_build_context_synchronously
54+
if (!context.mounted) {
5455
return;
5556
}
5657

@@ -149,8 +150,9 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
149150

150151
// TODO(server-7): Rely on user_id from fetchApiKey.
151152
final int userId = result.userId ?? await _getUserId(result);
152-
if (context.mounted) {} // https://github.com/dart-lang/linter/issues/4007
153-
else {
153+
// https://github.com/dart-lang/linter/issues/4007
154+
// ignore: use_build_context_synchronously
155+
if (!context.mounted) {
154156
return;
155157
}
156158

@@ -165,8 +167,9 @@ class _EmailPasswordLoginPageState extends State<EmailPasswordLoginPage> {
165167
zulipVersion: widget.serverSettings.zulipVersion,
166168
zulipMergeBase: Value(widget.serverSettings.zulipMergeBase),
167169
));
168-
if (context.mounted) {} // https://github.com/dart-lang/linter/issues/4007
169-
else {
170+
// https://github.com/dart-lang/linter/issues/4007
171+
// ignore: use_build_context_synchronously
172+
if (!context.mounted) {
170173
return;
171174
}
172175

0 commit comments

Comments
 (0)