Skip to content

Commit 3af3a79

Browse files
committed
fix static code analysis issues
1 parent cb5e381 commit 3af3a79

File tree

6 files changed

+40
-31
lines changed

6 files changed

+40
-31
lines changed

lib/widgets/collection_page.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import 'package:package_info_plus/package_info_plus.dart';
1717
import 'package:share_plus/share_plus.dart';
1818

1919
class CollectionPage extends StatefulWidget {
20-
const CollectionPage({Key? key}) : super(key: key);
20+
const CollectionPage({super.key});
2121

2222
@override
2323
CollectionPageState createState() => CollectionPageState();
@@ -62,7 +62,7 @@ class CollectionPageState extends State<CollectionPage> {
6262

6363
if (!kIsWeb && Platform.isAndroid) {
6464
FlutterBackground.hasPermissions.then((hasPermissions) {
65-
if (!hasPermissions) {
65+
if (!hasPermissions && mounted) {
6666
showDialog<String>(
6767
context: context,
6868
builder: (BuildContext context) => AlertDialog(
@@ -230,7 +230,9 @@ class CollectionPageState extends State<CollectionPage> {
230230
},
231231
);
232232
}
233-
await _transitionToTimerPage(context, tea);
233+
if (context.mounted) {
234+
await _transitionToTimerPage(context, tea);
235+
}
234236
},
235237
(tea) => {
236238
showModalBottomSheet(
@@ -255,8 +257,10 @@ class CollectionPageState extends State<CollectionPage> {
255257
(tea) {
256258
PersistenceService.updateTea(tea).then((value) {
257259
setState(() {});
258-
Navigator.of(context).pop();
259-
Navigator.of(context).pop();
260+
if (context.mounted) {
261+
Navigator.of(context).pop();
262+
Navigator.of(context).pop();
263+
}
260264
});
261265
},
262266
(tea) {
@@ -275,8 +279,10 @@ class CollectionPageState extends State<CollectionPage> {
275279
(tea) {
276280
PersistenceService.addTea(tea).then((value) {
277281
setState(() {});
278-
Navigator.of(context).pop();
279-
Navigator.of(context).pop();
282+
if (context.mounted) {
283+
Navigator.of(context).pop();
284+
Navigator.of(context).pop();
285+
}
280286
});
281287
},
282288
(tea) {

lib/widgets/data_restore_dialog.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,18 @@ class DataRestoreDialog extends StatelessWidget {
5656
jsonDecode(textController.text),
5757
);
5858
PersistenceService.restoreFomBackup(backup)
59-
.then((value) => Navigator.of(context).pop())
60-
.onError(
61-
(e, stackTrace) => ScaffoldMessenger.of(
62-
context,
63-
).showSnackBar(SnackBar(content: Text(e.toString()))),
64-
);
59+
.then((value) {
60+
if (context.mounted) {
61+
return Navigator.of(context).pop();
62+
}
63+
})
64+
.onError((e, stackTrace) {
65+
if (context.mounted) {
66+
ScaffoldMessenger.of(
67+
context,
68+
).showSnackBar(SnackBar(content: Text(e.toString())));
69+
}
70+
});
6571
} catch (e) {
6672
ScaffoldMessenger.of(
6773
context,

lib/widgets/notes_page.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:infusion_timer/tea.dart';
99
class NotesPage extends StatefulWidget {
1010
final Tea tea;
1111

12-
const NotesPage({Key? key, required this.tea}) : super(key: key);
12+
const NotesPage({super.key, required this.tea});
1313

1414
@override
1515
NotesPageState createState() => NotesPageState();
@@ -19,7 +19,7 @@ class NotesPageState extends State<NotesPage> {
1919
final _formKey = GlobalKey<FormState>();
2020
bool _hasUnsavedChanges = false;
2121

22-
Future<void> _onPopInvoked(bool didPop) async {
22+
Future<void> _onPopInvoked(bool didPop, dynamic result) async {
2323
// confirm cancelling infusion if going back to collection page
2424
if (didPop) {
2525
return;
@@ -53,12 +53,12 @@ class NotesPageState extends State<NotesPage> {
5353
case 0:
5454
_formKey.currentState!.save();
5555
PersistenceService.updateTea(widget.tea);
56-
if (context.mounted) {
56+
if (mounted) {
5757
Navigator.pop(context);
5858
}
5959
break;
6060
case 1:
61-
if (context.mounted) {
61+
if (mounted) {
6262
Navigator.pop(context);
6363
}
6464
break;
@@ -72,7 +72,7 @@ class NotesPageState extends State<NotesPage> {
7272
Widget build(BuildContext context) {
7373
return PopScope(
7474
canPop: !_hasUnsavedChanges,
75-
onPopInvoked: _onPopInvoked,
75+
onPopInvokedWithResult: _onPopInvoked,
7676
child: Scaffold(
7777
appBar: AppBar(title: const Text("Notes")),
7878
body: Form(

lib/widgets/preferences_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:infusion_timer/widgets/data_backup_dialog.dart';
77
import 'package:infusion_timer/widgets/data_restore_dialog.dart';
88

99
class PreferencesPage extends StatefulWidget {
10-
const PreferencesPage({Key? key}) : super(key: key);
10+
const PreferencesPage({super.key});
1111

1212
@override
1313
PreferencesPageState createState() => PreferencesPageState();

lib/widgets/star_rating_form_field.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ import 'package:flutter/material.dart';
55
class StarRatingFormField extends FormField<int> {
66
StarRatingFormField({
77
super.key,
8-
FormFieldSetter<int>? onSaved,
9-
FormFieldValidator<int>? validator,
10-
int initialValue = 0,
8+
super.onSaved,
9+
super.validator,
10+
int super.initialValue = 0,
1111
AutovalidateMode autovalidate = AutovalidateMode.disabled,
1212
}) : super(
13-
onSaved: onSaved,
14-
validator: validator,
15-
initialValue: initialValue,
1613
autovalidateMode: autovalidate,
1714
builder: (FormFieldState<int> state) {
1815
return Row(

lib/widgets/timer_page.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const String sessionSavePrefix = "session:";
3030
class TimerPage extends StatefulWidget {
3131
final Tea tea;
3232

33-
const TimerPage({Key? key, required this.tea}) : super(key: key);
33+
const TimerPage({super.key, required this.tea});
3434

3535
@override
3636
TimerPageState createState() => TimerPageState();
@@ -253,7 +253,7 @@ class TimerPageState extends State<TimerPage>
253253
}
254254
if (!kIsWeb) {
255255
FlutterVolumeController.getVolume().then((value) {
256-
if (value == 0) {
256+
if (value == 0 && mounted) {
257257
ScaffoldMessenger.of(context).showSnackBar(
258258
const SnackBar(
259259
content: Text("Device is muted and won't ring!"),
@@ -285,7 +285,7 @@ class TimerPageState extends State<TimerPage>
285285
});
286286
}
287287

288-
Future<void> _onPopInvoked(bool didPop) async {
288+
Future<void> _onPopInvoked(bool didPop, dynamic result) async {
289289
// confirm cancelling infusion if going back to collection page
290290
if (didPop) {
291291
return;
@@ -313,7 +313,7 @@ class TimerPageState extends State<TimerPage>
313313
);
314314
},
315315
);
316-
if ((shouldDiscard ?? false) && context.mounted) {
316+
if ((shouldDiscard ?? false) && mounted) {
317317
Navigator.pop(context);
318318
}
319319
}
@@ -344,7 +344,7 @@ class TimerPageState extends State<TimerPage>
344344
return PopScope(
345345
canPop:
346346
_animationController.isCompleted || _animationController.value == 0,
347-
onPopInvoked: _onPopInvoked,
347+
onPopInvokedWithResult: _onPopInvoked,
348348
child: Scaffold(
349349
appBar: AppBar(title: const Text("Tea Timer")),
350350
body: Align(
@@ -423,7 +423,7 @@ class TimerPageState extends State<TimerPage>
423423
return Icons.play_arrow;
424424
}
425425
}()),
426-
color: Colors.white.withOpacity(0.5),
426+
color: Colors.white.withValues(alpha: 0.5),
427427
onPressed: _startPauseNext,
428428
iconSize: progressIndicatorDiameter * 0.65,
429429
),

0 commit comments

Comments
 (0)