Skip to content

Commit e34700d

Browse files
committed
Avoid a few non-null assertions
1 parent 2098365 commit e34700d

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

dwds/debug_extension/web/background.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void _registerListeners() {
4545
chrome.windows.onFocusChanged.addListener(
4646
allowInterop((_) async {
4747
final currentTab = await activeTab;
48-
if (currentTab?.id != null) {
49-
await _updateIcon(currentTab!.id);
48+
if (currentTab?.id case final tabId?) {
49+
await _updateIcon(tabId);
5050
}
5151
}),
5252
);

dwds/debug_extension/web/debug_session.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,12 @@ Future<bool> _connectToDwds({
349349
required int dartAppTabId,
350350
required DebugInfo debugInfo,
351351
}) async {
352-
if (debugInfo.extensionUrl == null) {
352+
final extensionUrl = debugInfo.extensionUrl;
353+
if (extensionUrl == null) {
353354
debugWarn('Can\'t connect to DWDS without an extension URL.');
354355
return false;
355356
}
356-
final uri = Uri.parse(debugInfo.extensionUrl!);
357+
final uri = Uri.parse(extensionUrl);
357358
// Start the client connection with DWDS:
358359
final client = uri.isScheme('ws') || uri.isScheme('wss')
359360
? WebSocketClient(WebSocketChannel.connect(uri))

dwds/debug_extension/web/popup.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ Future<void> _launchDevTools(Event _) async {
131131
}
132132

133133
void _copyAppId(Event _) {
134-
if (_appId == null) return;
134+
final appId = _appId;
135+
if (appId == null) return;
135136
final clipboard = window.navigator.clipboard;
136137
if (clipboard == null) return;
137-
clipboard.writeText(_appId!);
138+
clipboard.writeText(appId);
138139
_updateElementVisibility(_copiedSuccessId, visible: true);
139140
}
140141

dwds/debug_extension/web/utils.dart

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,32 +115,18 @@ void setExtensionPopup(PopupDetails details) {
115115
}
116116
}
117117

118-
bool? _isDevMode;
119-
120-
bool get isDevMode {
121-
if (_isDevMode != null) {
122-
return _isDevMode!;
123-
}
118+
final bool isDevMode = () {
124119
final extensionManifest = chrome.runtime.getManifest();
125120
final extensionName = getProperty<String?>(extensionManifest, 'name') ?? '';
126-
final isDevMode = extensionName.contains('DEV');
127-
_isDevMode = isDevMode;
128-
return isDevMode;
129-
}
121+
return extensionName.contains('DEV');
122+
}();
130123

131-
bool? _isMV3;
132-
133-
bool get isMV3 {
134-
if (_isMV3 != null) {
135-
return _isMV3!;
136-
}
124+
final bool isMV3 = () {
137125
final extensionManifest = chrome.runtime.getManifest();
138126
final manifestVersion =
139127
getProperty(extensionManifest, 'manifest_version') ?? 2;
140-
final isMV3 = manifestVersion == 3;
141-
_isMV3 = isMV3;
142-
return isMV3;
143-
}
128+
return manifestVersion == 3;
129+
}();
144130

145131
String addQueryParameters(
146132
String uri, {

0 commit comments

Comments
 (0)