Last active
May 17, 2022 07:44
-
-
Save aliyazdi75/bd3b9928d6a5fbba36f1a9eb5f00f3e7 to your computer and use it in GitHub Desktop.
sentry_flutter: ^6.5.1 and feedback: ^2.5.0
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
import 'dart:async'; | |
import 'package:feedback/feedback.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:sentry_flutter/sentry_flutter.dart'; | |
Future<void> main() async { | |
final navigatorKey = GlobalKey<NavigatorState>(); | |
final appRunner = MyApp(navigatorKey: navigatorKey); | |
FlutterError.onError = (FlutterErrorDetails details) async { | |
if (navigatorKey.currentContext != null) { | |
BetterFeedback.of(navigatorKey.currentContext!) | |
.show((UserFeedback feedback) async { | |
final eventId = await Sentry.captureException( | |
details.exception, | |
stackTrace: details.stack, | |
withScope: (scope) { | |
scope.addAttachment(SentryAttachment.fromUint8List( | |
feedback.screenshot, | |
'screenshot.png', | |
contentType: 'image/png', | |
)); | |
}, | |
); | |
await Sentry.captureUserFeedback(SentryUserFeedback( | |
eventId: eventId, | |
name: 'Sample Name', | |
email: 'Sample Email', | |
comments: feedback.text, | |
)); | |
}); | |
} else { | |
await Sentry.captureException( | |
details.exception, | |
stackTrace: details.stack, | |
); | |
} | |
}; | |
await SentryFlutter.init( | |
(options) => { | |
options | |
..dsn = 'SentryDsn', | |
}, | |
); | |
runApp(BetterFeedback(child: appRunner)); | |
} | |
class MyApp extends StatelessWidget { | |
final GlobalKey<NavigatorState>? navigatorKey; | |
const MyApp({ | |
Key? key, | |
required this.navigatorKey, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
navigatorKey: navigatorKey, | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String? title; | |
const MyHomePage({ | |
Key? key, | |
this.title, | |
}) : super(key: key); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
int _counter = 0; | |
void _incrementCounter() { | |
setState(() { | |
_counter++; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
if (widget.title == null) { | |
throw 'Title is null'; | |
} | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title!), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
const Text( | |
'You have pushed the button this many times:', | |
), | |
Text( | |
'$_counter', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
], | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: _incrementCounter, | |
tooltip: 'Increment', | |
child: const Icon(Icons.add), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment