Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Dec 6, 2022
1 parent 88b6194 commit 964eb27
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/min_version_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ jobs:
- uses: subosito/flutter-action@dbf1fa04f4d2e52c33185153d06cdb5443aa189d # pin@v2
with:
flutter-version: '2.0.0'

# Add flutter build web (missing index)
- name: Build
run: |
cd min_version_test
flutter pub get
flutter build ios --no-codesign
flutter build appbundle
flutter build web
47 changes: 47 additions & 0 deletions flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import 'dart:async';
import 'dart:convert';

import 'dart:io' if (dart.library.html) 'dart:html';
import 'package:path_provider/path_provider.dart';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -15,6 +18,7 @@ import 'user_feedback_dialog.dart';
import 'package:dio/dio.dart';
import 'package:sentry_dio/sentry_dio.dart';
import 'package:sentry_logging/sentry_logging.dart';
import 'package:sentry_file/sentry_file.dart';

// ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
const String _exampleDsn =
Expand Down Expand Up @@ -339,6 +343,12 @@ class MainScaffold extends StatelessWidget {
},
child: const Text('Capture User Feedback'),
),
ElevatedButton(
onPressed: () async {
await _manipulateFile();
},
child: const Text('Manipulate file'),
),
ElevatedButton(
onPressed: () async {
await showDialog(
Expand Down Expand Up @@ -663,6 +673,43 @@ Future<void> showDialogWithTextAndImage(BuildContext context) async {
await transaction.finish(status: const SpanStatus.ok());
}

Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();

return directory.path;
}

Future<File> get _localFile async {
final path = await _localPath;
return File('$path/response.txt');
}

Future<void> _manipulateFile() async {
final transaction = Sentry.getSpan() ??
Sentry.startTransaction(
'MyFileExample',
'file',
bindToScope: true,
);

final dio = Dio();
dio.addSentry(captureFailedRequests: true);

try {
final file = await _localFile;
final sentryFile = file.sentryTrace();
if (!await sentryFile.exists()) {
await sentryFile.create();
}
final response = await dio.get<String>('https://flutter.dev/');
await sentryFile.writeAsString(response.data ?? 'no response');

await transaction.finish(status: const SpanStatus.ok());
} catch (exception, _) {
await transaction.finish(status: const SpanStatus.internalError());
}
}

class ThemeProvider extends ChangeNotifier {
ThemeData _theme = ThemeData.light();

Expand Down
2 changes: 2 additions & 0 deletions flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ dependencies:
sentry_flutter:
sentry_dio:
sentry_logging:
sentry_file:
universal_platform: ^1.0.0
feedback: ^2.0.0
provider: ^6.0.0
dio: ^4.0.0
logging: ^1.0.0
package_info_plus: ^3.0.0
path_provider: ^2.0.0

dev_dependencies:
flutter_lints: ^2.0.0
Expand Down
2 changes: 2 additions & 0 deletions flutter/example/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ dependency_overrides:
path: ../../dio
sentry_logging:
path: ../../logging
sentry_file:
path: ../../file

0 comments on commit 964eb27

Please sign in to comment.