Skip to content

Commit 21562c5

Browse files
authored
Enums use its name instead of non exhaustive switches (#1506)
1 parent 7e30648 commit 21562c5

9 files changed

+9
-77
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fixes
6+
7+
- Enums use its name instead of non exhaustive switches ([##1506](https://github.com/getsentry/sentry-dart/pull/#1506))
8+
59
### Enhancements
610

711
- Add http fields to `span.data` ([#1497](https://github.com/getsentry/sentry-dart/pull/1497))

dart/lib/src/protocol/sentry_device.dart

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,14 @@ class SentryDevice {
221221

222222
/// Produces a [Map] that can be serialized to JSON.
223223
Map<String, dynamic> toJson() {
224-
String? orientation;
225-
226-
switch (this.orientation) {
227-
case SentryOrientation.portrait:
228-
orientation = 'portait';
229-
break;
230-
case SentryOrientation.landscape:
231-
orientation = 'landscape';
232-
break;
233-
case null:
234-
orientation = null;
235-
break;
236-
}
237224
return <String, dynamic>{
238225
if (name != null) 'name': name,
239226
if (family != null) 'family': family,
240227
if (model != null) 'model': model,
241228
if (modelId != null) 'model_id': modelId,
242229
if (arch != null) 'arch': arch,
243230
if (batteryLevel != null) 'battery_level': batteryLevel,
244-
if (orientation != null) 'orientation': orientation,
231+
if (orientation != null) 'orientation': orientation!.name,
245232
if (manufacturer != null) 'manufacturer': manufacturer,
246233
if (brand != null) 'brand': brand,
247234
if (screenWidthPixels != null) 'screen_width_pixels': screenWidthPixels,

dart/lib/src/protocol/sentry_transaction.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class SentryTransaction extends SentryEvent {
6969
);
7070

7171
this.transactionInfo = transactionInfo ??
72-
SentryTransactionInfo(_tracer.transactionNameSource.toStringValue());
72+
SentryTransactionInfo(_tracer.transactionNameSource.name);
7373
}
7474

7575
@override

dart/lib/src/protocol/sentry_transaction_name_source.dart

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,3 @@ enum SentryTransactionNameSource {
1717
/// Name of a background task
1818
task,
1919
}
20-
21-
extension SentryTransactionNameSourceExtension on SentryTransactionNameSource {
22-
String toStringValue() {
23-
switch (this) {
24-
case SentryTransactionNameSource.custom:
25-
return 'custom';
26-
case SentryTransactionNameSource.url:
27-
return 'url';
28-
case SentryTransactionNameSource.route:
29-
return 'route';
30-
case SentryTransactionNameSource.view:
31-
return 'view';
32-
case SentryTransactionNameSource.component:
33-
return 'component';
34-
case SentryTransactionNameSource.task:
35-
return 'task';
36-
}
37-
}
38-
}

flutter/lib/src/event_processor/flutter_enricher_event_processor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class FlutterEnricherEventProcessor implements EventProcessor {
143143
// Also always fails in tests.
144144
// See https://github.com/flutter/flutter/issues/83919
145145
// 'window_is_visible': _window.viewConfiguration.visible,
146-
'renderer': _options.rendererWrapper.getRendererAsString()
146+
'renderer': _options.rendererWrapper.getRenderer().name,
147147
};
148148
}
149149

flutter/lib/src/event_processor/screenshot_event_processor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ScreenshotEventProcessor implements EventProcessor {
3434
if (renderer != FlutterRenderer.skia &&
3535
renderer != FlutterRenderer.canvasKit) {
3636
_options.logger(SentryLevel.debug,
37-
'Cannot take screenshot with ${_options.rendererWrapper.getRendererAsString()} renderer.');
37+
'Cannot take screenshot with ${_options.rendererWrapper.getRenderer().name} renderer.');
3838
return event;
3939
}
4040

flutter/lib/src/renderer/renderer.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,6 @@ class RendererWrapper {
99
FlutterRenderer getRenderer() {
1010
return implementation.getRenderer();
1111
}
12-
13-
String getRendererAsString() {
14-
switch (getRenderer()) {
15-
case FlutterRenderer.skia:
16-
return 'Skia';
17-
case FlutterRenderer.canvasKit:
18-
return 'CanvasKit';
19-
case FlutterRenderer.html:
20-
return 'HTML';
21-
case FlutterRenderer.unknown:
22-
return 'Unknown';
23-
}
24-
}
2512
}
2613

2714
enum FlutterRenderer {

flutter/lib/src/widgets_binding_observer.dart

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SentryWidgetsBindingObserver with WidgetsBindingObserver {
7171
category: 'app.lifecycle',
7272
type: 'navigation',
7373
data: <String, String>{
74-
'state': _lifecycleToString(state),
74+
'state': state.name,
7575
},
7676
// ignore: invalid_use_of_internal_member
7777
timestamp: _options.clock(),
@@ -180,19 +180,6 @@ class SentryWidgetsBindingObserver with WidgetsBindingObserver {
180180
));
181181
}
182182

183-
static String _lifecycleToString(AppLifecycleState state) {
184-
switch (state) {
185-
case AppLifecycleState.resumed:
186-
return 'resumed';
187-
case AppLifecycleState.inactive:
188-
return 'inactive';
189-
case AppLifecycleState.paused:
190-
return 'paused';
191-
case AppLifecycleState.detached:
192-
return 'detached';
193-
}
194-
}
195-
196183
/*
197184
These are also methods of `WidgetsBindingObserver` but are currently not
198185
implemented because I'm not sure what to do with them. See the reasoning

flutter/test/mocks.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -354,20 +354,6 @@ class MockRendererWrapper implements RendererWrapper {
354354
FlutterRenderer getRenderer() {
355355
return _renderer;
356356
}
357-
358-
@override
359-
String getRendererAsString() {
360-
switch (getRenderer()) {
361-
case FlutterRenderer.skia:
362-
return 'Skia';
363-
case FlutterRenderer.canvasKit:
364-
return 'CanvasKit';
365-
case FlutterRenderer.html:
366-
return 'HTML';
367-
case FlutterRenderer.unknown:
368-
return 'Unknown';
369-
}
370-
}
371357
}
372358

373359
class TestBindingWrapper implements BindingWrapper {

0 commit comments

Comments
 (0)