Created
September 11, 2025 11:44
-
-
Save bizz84/d3d010f95236d37fd29348c5712065fe to your computer and use it in GitHub Desktop.
Sample project for dio.addSentry() issue on Flutter web
This file contains hidden or 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
import 'dart:developer'; | |
import 'package:dio/dio.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:sentry_dio/sentry_dio.dart'; | |
import 'package:sentry_flutter/sentry_flutter.dart'; | |
const String kSentryDsn = String.fromEnvironment('SENTRY_DSN'); | |
const _gistTemplateUrl = | |
'https://gist.githubusercontent.com/bizz84/5c2ee79cd103bd43ce97b4d7fcfed103/raw/app_release_template.json'; | |
/// An API client class for fetching the JSON template from a GitHub gist | |
class GistClient { | |
const GistClient({required this.dio}); | |
final Dio dio; | |
/// Fetch the JSON template from the Gist URL defined above | |
// * No serialization is done here as the parsing happens when loading the | |
// * data in the database | |
Future<String> fetchJsonTemplate() async { | |
final response = await dio.get(_gistTemplateUrl); | |
return response.data; | |
} | |
} | |
void main() async { | |
WidgetsFlutterBinding.ensureInitialized(); | |
await SentryFlutter.init((options) { | |
options.dsn = kSentryDsn; | |
// Use the beforeSend callback to filter which events are sent | |
options.beforeSend = (SentryEvent event, Hint hint) async { | |
// If there was no response, it means that a connection error occurred | |
// Do not log this to Sentry | |
final exception = event.throwable; | |
if (exception is DioException && exception.response == null) { | |
return null; | |
} | |
// For all other events, return the event as is | |
return event; | |
}; | |
}); | |
final dio = Dio(); | |
dio.addSentry(); | |
final gistClient = GistClient(dio: dio); | |
try { | |
final jsonString = await gistClient.fetchJsonTemplate(); | |
log(jsonString); | |
runApp(MainApp(string: jsonString)); | |
} catch (e) { | |
log(e.toString()); | |
runApp(MainApp(string: e.toString())); | |
} | |
} | |
class MainApp extends StatelessWidget { | |
const MainApp({super.key, required this.string}); | |
final String string; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold(body: Center(child: Text(string))), | |
); | |
} | |
} |
This file contains hidden or 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
name: sentry9_web_error | |
description: "A new Flutter project." | |
publish_to: 'none' | |
version: 0.1.0 | |
environment: | |
sdk: ^3.9.2 | |
dependencies: | |
flutter: | |
sdk: flutter | |
dio: ^5.9.0 | |
sentry_flutter: ^9.6.0 | |
sentry_dio: ^9.6.0 | |
dev_dependencies: | |
flutter_test: | |
sdk: flutter | |
flutter_lints: ^5.0.0 | |
flutter: | |
uses-material-design: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment