-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add textScale(r) value to Flutter context (#1886)
* entrich event contexts app with text scale * read textScale from sentry widget event processor * revert change * revert change * update changelog * update changelog * Use scale method instead of deprecated `textScaleFactor` * fix changelog * fix changelog * use maybeTextScaleFactorOf method * fix changelog * fix changelog * use textScaleFactorOf * fix tests * update doc * Update CHANGELOG.md --------- Co-authored-by: Giancarlo Buenaflor <giancarlo_buenaflor@yahoo.com>
- Loading branch information
Showing
8 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
flutter/lib/src/event_processor/widget_event_processor.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
|
||
import '../../sentry_flutter.dart'; | ||
|
||
class WidgetEventProcessor implements EventProcessor { | ||
@override | ||
FutureOr<SentryEvent?> apply(SentryEvent event, {Hint? hint}) { | ||
if (event is SentryTransaction) { | ||
return event; | ||
} | ||
if (event.exceptions == null && event.throwable == null) { | ||
return event; | ||
} | ||
final context = sentryWidgetGlobalKey.currentContext; | ||
if (context == null) { | ||
return event; | ||
} | ||
|
||
// ignore: deprecated_member_use | ||
final textScale = MediaQuery.textScaleFactorOf(context); | ||
return event.copyWith( | ||
contexts: event.contexts.copyWith( | ||
app: event.contexts.app?.copyWith( | ||
textScale: textScale, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
flutter/test/event_processor/widget_event_processor_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:sentry_flutter/sentry_flutter.dart'; | ||
import 'package:sentry_flutter/src/event_processor/widget_event_processor.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
late Fixture fixture; | ||
|
||
setUp(() { | ||
fixture = Fixture(); | ||
}); | ||
|
||
testWidgets('adds screenshot attachment dart:io', (tester) async { | ||
await tester.runAsync(() async { | ||
final sut = fixture.getSut(); | ||
await tester.pumpWidget( | ||
SentryWidget( | ||
child: Text( | ||
'Catching Pokémon is a snap!', | ||
textDirection: TextDirection.ltr, | ||
), | ||
), | ||
); | ||
|
||
final throwable = Exception(); | ||
SentryEvent? event = SentryEvent(throwable: throwable); | ||
event = event.copyWith( | ||
contexts: event.contexts.copyWith( | ||
app: SentryApp(), | ||
), | ||
); | ||
event = await sut.apply(event); | ||
|
||
expect(event?.contexts.app?.textScale, 1.0); | ||
}); | ||
}); | ||
} | ||
|
||
class Fixture { | ||
WidgetEventProcessor getSut() { | ||
return WidgetEventProcessor(); | ||
} | ||
} |