Skip to content

chore(crashlytics): update example app #17426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
id "com.google.gms.google-services" version "4.3.15" apply false
id "com.google.firebase.crashlytics" version "2.8.1" apply false
// END: FlutterFire Configuration
id "org.jetbrains.kotlin.android" version "1.9.22" apply false
id "org.jetbrains.kotlin.android" version "2.1.21" apply false
}

include ":app"
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> {
late Future<void> _initializeFlutterFireFuture;
bool _crashlyticsEnabled = true;

Future<void> _testAsyncErrorOnInit() async {
Future<void>.delayed(const Duration(seconds: 2), () {
Expand All @@ -73,11 +74,14 @@ class _MyAppState extends State<MyApp> {
if (_kTestingCrashlytics) {
// Force enable crashlytics collection enabled if we're testing it.
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
_crashlyticsEnabled = true;
} else {
// Else only enable it in non-debug builds.
// You could additionally extend this to allow users to opt-in.
const enabled = !kDebugMode;
await FirebaseCrashlytics.instance
.setCrashlyticsCollectionEnabled(!kDebugMode);
.setCrashlyticsCollectionEnabled(enabled);
_crashlyticsEnabled = enabled;
}

if (_kShouldTestAsyncErrorOnInit) {
Expand Down Expand Up @@ -111,6 +115,24 @@ class _MyAppState extends State<MyApp> {
return Center(
child: Column(
children: <Widget>[
ElevatedButton(
onPressed: () async {
final newValue = !_crashlyticsEnabled;
await FirebaseCrashlytics.instance
.setCrashlyticsCollectionEnabled(newValue);
setState(() {
_crashlyticsEnabled = newValue;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Crashlytics reporting has been ${newValue ? 'enabled' : 'disabled'}.'),
duration: const Duration(seconds: 3),
));
},
child: Text(_crashlyticsEnabled
? 'Disable Crashlytics'
: 'Enable Crashlytics'),
),
ElevatedButton(
onPressed: () {
FirebaseCrashlytics.instance
Expand Down
Loading