Skip to content

Commit 6968108

Browse files
chore(firebase_crashlytics): fix lint issues
1 parent 40c5b90 commit 6968108

File tree

16 files changed

+215
-194
lines changed

16 files changed

+215
-194
lines changed

packages/firebase_crashlytics/firebase_crashlytics/example/lib/main.dart

Lines changed: 103 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@ import 'package:flutter/material.dart';
1414

1515
// Toggle this to cause an async error to be thrown during initialization
1616
// and to test that runZonedGuarded() catches the error
17-
final _kShouldTestAsyncErrorOnInit = false;
17+
const _kShouldTestAsyncErrorOnInit = false;
1818

1919
// Toggle this for testing Crashlytics in your app locally.
20-
final _kTestingCrashlytics = true;
20+
const _kTestingCrashlytics = true;
2121

22-
main() {
22+
void main() {
2323
WidgetsFlutterBinding.ensureInitialized();
2424
runZonedGuarded(() {
2525
runApp(MyApp());
2626
}, (error, stackTrace) {
27-
print('runZonedGuarded: Caught error in my root zone.');
2827
FirebaseCrashlytics.instance.recordError(error, stackTrace);
2928
});
3029
}
3130

3231
// ignore: public_member_api_docs
3332
class MyApp extends StatefulWidget {
33+
// ignore: public_member_api_docs
34+
MyApp({Key key}) : super(key: key);
3435
@override
3536
_MyAppState createState() => _MyAppState();
3637
}
@@ -41,6 +42,7 @@ class _MyAppState extends State<MyApp> {
4142
Future<void> _testAsyncErrorOnInit() async {
4243
Future<void>.delayed(const Duration(seconds: 2), () {
4344
final List<int> list = <int>[];
45+
// ignore: avoid_print
4446
print(list[100]);
4547
});
4648
}
@@ -100,103 +102,115 @@ class _MyAppState extends State<MyApp> {
100102
child: Column(
101103
children: <Widget>[
102104
RaisedButton(
103-
child: const Text('Key'),
104-
onPressed: () {
105-
FirebaseCrashlytics.instance
106-
.setCustomKey('example', 'flutterfire');
107-
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
108-
content: Text(
109-
'Custom Key "example: flutterfire" has been set \n'
110-
'Key will appear in Firebase Console once app has crashed and reopened'),
111-
duration: Duration(seconds: 5),
112-
));
113-
}),
105+
onPressed: () {
106+
FirebaseCrashlytics.instance
107+
.setCustomKey('example', 'flutterfire');
108+
ScaffoldMessenger.of(context)
109+
.showSnackBar(const SnackBar(
110+
content: Text(
111+
'Custom Key "example: flutterfire" has been set \n'
112+
'Key will appear in Firebase Console once app has crashed and reopened'),
113+
duration: Duration(seconds: 5),
114+
));
115+
},
116+
child: const Text('Key'),
117+
),
114118
RaisedButton(
115-
child: const Text('Log'),
116-
onPressed: () {
117-
FirebaseCrashlytics.instance
118-
.log('This is a log example');
119-
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
120-
content: Text(
121-
'The message "This is a log example" has been logged \n'
122-
'Message will appear in Firebase Console once app has crashed and reopened'),
123-
duration: Duration(seconds: 5),
124-
));
125-
}),
119+
onPressed: () {
120+
FirebaseCrashlytics.instance
121+
.log('This is a log example');
122+
ScaffoldMessenger.of(context)
123+
.showSnackBar(const SnackBar(
124+
content: Text(
125+
'The message "This is a log example" has been logged \n'
126+
'Message will appear in Firebase Console once app has crashed and reopened'),
127+
duration: Duration(seconds: 5),
128+
));
129+
},
130+
child: const Text('Log'),
131+
),
126132
RaisedButton(
127-
child: const Text('Crash'),
128-
onPressed: () async {
129-
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
130-
content: Text('App will crash is 5 seconds \n'
131-
'Please reopen to send data to Crashlytics'),
132-
duration: Duration(seconds: 5),
133-
));
134-
135-
// Delay crash for 5 seconds
136-
sleep(const Duration(seconds: 5));
137-
138-
// Use FirebaseCrashlytics to throw an error. Use this for
139-
// confirmation that errors are being correctly reported.
140-
FirebaseCrashlytics.instance.crash();
141-
}),
133+
onPressed: () async {
134+
ScaffoldMessenger.of(context)
135+
.showSnackBar(const SnackBar(
136+
content: Text('App will crash is 5 seconds \n'
137+
'Please reopen to send data to Crashlytics'),
138+
duration: Duration(seconds: 5),
139+
));
140+
141+
// Delay crash for 5 seconds
142+
sleep(const Duration(seconds: 5));
143+
144+
// Use FirebaseCrashlytics to throw an error. Use this for
145+
// confirmation that errors are being correctly reported.
146+
FirebaseCrashlytics.instance.crash();
147+
},
148+
child: const Text('Crash'),
149+
),
142150
RaisedButton(
143-
child: const Text('Throw Error'),
144-
onPressed: () {
145-
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
146-
content: Text('Thrown error has been caught \n'
147-
'Please crash and reopen to send data to Crashlytics'),
148-
duration: Duration(seconds: 5),
149-
));
150-
151-
// Example of thrown error, it will be caught and sent to
152-
// Crashlytics.
153-
throw StateError('Uncaught error thrown by app');
154-
}),
151+
onPressed: () {
152+
ScaffoldMessenger.of(context)
153+
.showSnackBar(const SnackBar(
154+
content: Text('Thrown error has been caught \n'
155+
'Please crash and reopen to send data to Crashlytics'),
156+
duration: Duration(seconds: 5),
157+
));
158+
159+
// Example of thrown error, it will be caught and sent to
160+
// Crashlytics.
161+
throw StateError('Uncaught error thrown by app');
162+
},
163+
child: const Text('Throw Error'),
164+
),
155165
RaisedButton(
156-
child: const Text('Async out of bounds'),
157-
onPressed: () {
158-
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
159-
content: Text(
160-
'Uncaught Exception that is handled by second parameter of runZonedGuarded \n'
166+
onPressed: () {
167+
ScaffoldMessenger.of(context)
168+
.showSnackBar(const SnackBar(
169+
content: Text(
170+
'Uncaught Exception that is handled by second parameter of runZonedGuarded \n'
171+
'Please crash and reopen to send data to Crashlytics'),
172+
duration: Duration(seconds: 5),
173+
));
174+
175+
// Example of an exception that does not get caught
176+
// by `FlutterError.onError` but is caught by
177+
// `runZonedGuarded`.
178+
runZonedGuarded(() {
179+
Future<void>.delayed(const Duration(seconds: 2),
180+
() {
181+
final List<int> list = <int>[];
182+
// ignore: avoid_print
183+
print(list[100]);
184+
});
185+
}, FirebaseCrashlytics.instance.recordError);
186+
},
187+
child: const Text('Async out of bounds'),
188+
),
189+
RaisedButton(
190+
onPressed: () async {
191+
try {
192+
ScaffoldMessenger.of(context)
193+
.showSnackBar(const SnackBar(
194+
content: Text('Recorded Error \n'
161195
'Please crash and reopen to send data to Crashlytics'),
162196
duration: Duration(seconds: 5),
163197
));
164-
165-
// Example of an exception that does not get caught
166-
// by `FlutterError.onError` but is caught by
167-
// `runZonedGuarded`.
168-
runZonedGuarded(() {
169-
Future<void>.delayed(const Duration(seconds: 2),
170-
() {
171-
final List<int> list = <int>[];
172-
print(list[100]);
173-
});
174-
}, FirebaseCrashlytics.instance.recordError);
175-
}),
176-
RaisedButton(
177-
child: const Text('Record Error'),
178-
onPressed: () async {
179-
try {
180-
ScaffoldMessenger.of(context)
181-
.showSnackBar(SnackBar(
182-
content: Text('Recorded Error \n'
183-
'Please crash and reopen to send data to Crashlytics'),
184-
duration: Duration(seconds: 5),
185-
));
186-
throw 'error_example';
187-
} catch (e, s) {
188-
// "reason" will append the word "thrown" in the
189-
// Crashlytics console.
190-
await FirebaseCrashlytics.instance
191-
.recordError(e, s, reason: 'as an example');
192-
}
193-
}),
198+
throw Error();
199+
} catch (e, s) {
200+
// "reason" will append the word "thrown" in the
201+
// Crashlytics console.
202+
await FirebaseCrashlytics.instance
203+
.recordError(e, s, reason: 'as an example');
204+
}
205+
},
206+
child: const Text('Record Error'),
207+
),
194208
],
195209
),
196210
);
197211
break;
198212
default:
199-
return Center(child: Text('Loading'));
213+
return const Center(child: Text('Loading'));
200214
}
201215
},
202216
),

packages/firebase_crashlytics/firebase_crashlytics/example/pubspec.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@ environment:
77
flutter: ">=1.12.13+hotfix.5 <2.0.0"
88

99
dependencies:
10-
flutter:
11-
sdk: flutter
12-
firebase_crashlytics:
13-
path: ../
1410
firebase_core:
1511
path: ../../../firebase_core/firebase_core
16-
17-
dependency_overrides:
18-
firebase_crashlytics_platform_interface:
19-
path: ../../firebase_crashlytics_platform_interface
2012
firebase_crashlytics:
2113
path: ../
14+
flutter:
15+
sdk: flutter
16+
17+
dependency_overrides:
2218
firebase_core:
2319
path: ../../../firebase_core/firebase_core
2420
firebase_core_platform_interface:
2521
path: ../../../firebase_core/firebase_core_platform_interface
22+
firebase_crashlytics:
23+
path: ../
24+
firebase_crashlytics_platform_interface:
25+
path: ../../firebase_crashlytics_platform_interface
2626
quiver: ">=3.0.0-nullsafety.2 <4.0.0"
2727

2828
dev_dependencies:
29-
pedantic: ^1.8.0
3029
drive: 0.0.1-6.0.pre
30+
e2e: ^0.6.1
3131
flutter_driver:
3232
sdk: flutter
33+
pedantic: ^1.8.0
3334
test: any
34-
e2e: ^0.6.1
3535

3636
flutter:
3737
uses-material-design: true

packages/firebase_crashlytics/firebase_crashlytics/example/test_driver/firebase_crashlytics_e2e.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ void testsMain() {
2424
await crashlytics.setCrashlyticsCollectionEnabled(true);
2525
try {
2626
await crashlytics.checkForUnsentReports();
27-
fail("Error did not throw");
27+
fail('Error did not throw');
2828
} catch (e) {
29-
print(e);
29+
// Do nothing. test will fail.
3030
}
3131
});
3232

packages/firebase_crashlytics/firebase_crashlytics/lib/src/firebase_crashlytics.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ part of firebase_crashlytics;
1010
///
1111
/// You can get an instance by calling [FirebaseCrashlytics.instance].
1212
class FirebaseCrashlytics extends FirebasePluginPlatform {
13+
FirebaseCrashlytics._({this.app})
14+
: super(app.name, 'plugins.flutter.io/firebase_crashlytics');
15+
1316
/// Cached instance of [FirebaseCrashlytics];
1417
static /*late*/ FirebaseCrashlytics _instance;
1518

@@ -26,9 +29,6 @@ class FirebaseCrashlytics extends FirebasePluginPlatform {
2629
/// The [FirebaseApp] for this current [FirebaseCrashlytics] instance.
2730
FirebaseApp app;
2831

29-
FirebaseCrashlytics._({this.app})
30-
: super(app.name, 'plugins.flutter.io/firebase_crashlytics');
31-
3232
/// Returns an instance using the default [FirebaseApp].
3333
static FirebaseCrashlytics get instance {
3434
return _instance ??= FirebaseCrashlytics._(app: Firebase.app());
@@ -87,29 +87,34 @@ class FirebaseCrashlytics extends FirebasePluginPlatform {
8787
: (StringBuffer()..writeAll(information, '\n')).toString();
8888

8989
if (printDetails) {
90+
// ignore: avoid_print
9091
print('----------------FIREBASE CRASHLYTICS----------------');
9192

9293
// If available, give a reason to the exception.
9394
if (reason != null) {
95+
// ignore: avoid_print
9496
print('The following exception was thrown $reason:');
9597
}
9698

9799
// Need to print the exception to explain why the exception was thrown.
100+
// ignore: avoid_print
98101
print(exception);
99102

100103
// Print information provided by the Flutter framework about the exception.
104+
// ignore: avoid_print
101105
if (_information.isNotEmpty) print('\n$_information');
102106

103107
// Not using Trace.format here to stick to the default stack trace format
104108
// that Flutter developers are used to seeing.
109+
// ignore: avoid_print
105110
if (stack != null) print('\n$stack');
111+
// ignore: avoid_print
106112
print('----------------------------------------------------');
107113
}
108114

109115
// The stack trace can be null. To avoid the following exception:
110116
// Invalid argument(s): Cannot create a Trace from null.
111117
// We can check for null and provide an empty stack trace.
112-
stack ??= StackTrace.current ?? StackTrace.fromString('');
113118

114119
// Report error.
115120
final List<String> stackTraceLines =

0 commit comments

Comments
 (0)