Skip to content

Commit c031f07

Browse files
committed
Fix lint hints (mostly dart fix --apply)
1 parent db7a300 commit c031f07

File tree

8 files changed

+30
-33
lines changed

8 files changed

+30
-33
lines changed

lib/alarm_actions_screen.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class _AlarmActionsScreenState extends State<AlarmActionsScreen> {
1818
void initState() {
1919
super.initState();
2020
_databaseService = DatabaseService.instance;
21-
21+
2222
final actions = _databaseService.getAllAlarmActions();
2323
log(actions.length.toString());
2424
}
@@ -50,4 +50,4 @@ class _AlarmActionsScreenState extends State<AlarmActionsScreen> {
5050
),
5151
);
5252
}
53-
}
53+
}

lib/alarm_manager_screen.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ class AlarmManagerScreen extends StatelessWidget {
2424
Widget build(BuildContext context) {
2525
return Scaffold(
2626
appBar: AppBar(
27-
title: const Text("Alarm Manager Screen"),
27+
title: const Text('Alarm Manager Screen'),
2828
centerTitle: true,
2929
actions: [
3030
IconButton(
3131
icon: const Icon(Icons.access_alarm),
3232
onPressed: () {
3333
Navigator.push(
3434
context,
35-
MaterialPageRoute(
35+
MaterialPageRoute<AlarmActionsScreen>(
3636
builder: (_) => const AlarmActionsScreen()));
3737
},
3838
)
@@ -43,7 +43,7 @@ class AlarmManagerScreen extends StatelessWidget {
4343
onPressed: () async {
4444
await _requestNotificationPermission(context);
4545
},
46-
child: const Text("Schedule Alarm")),
46+
child: const Text('Schedule Alarm')),
4747
),
4848
);
4949
}

lib/hive/models/alarm_action.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ part 'alarm_action.g.dart';
44

55
@HiveType(typeId: 0) //typeId should be unique for each model
66
class AlarmAction {
7+
AlarmAction(this.actionType, this.timestamp);
8+
79
@HiveField(0)
810
final String actionType;
911
@HiveField(1)
1012
final DateTime timestamp;
11-
12-
AlarmAction(this.actionType, this.timestamp);
1313
}

lib/hive/service/database_service.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import 'dart:developer';
2+
23
import 'package:flutter/foundation.dart';
4+
import 'package:flutter_alarm_manager_poc/hive/models/alarm_action.dart';
35
import 'package:hive_flutter/hive_flutter.dart';
4-
import '../models/alarm_action.dart';
56

67
class DatabaseService {
8+
// Private constructor
9+
DatabaseService._();
10+
711
static const String alarmBoxName = 'alarm_actions';
812
static DatabaseService? _instance;
913
late Box<AlarmAction> _alarmBox;
1014

11-
// Private constructor
12-
DatabaseService._();
13-
1415
// Singleton instance getter
1516
static DatabaseService get instance {
1617
_instance ??= DatabaseService._();
@@ -27,7 +28,7 @@ class DatabaseService {
2728
Hive.registerAdapter(AlarmActionAdapter());
2829
_alarmBox = await Hive.openBox<AlarmAction>(alarmBoxName);
2930
log('Hive initialized and box opened successfully.');
30-
} catch (e) {
31+
} on Exception catch (e) {
3132
log('Failed to initialize Hive or open box: $e');
3233
}
3334
}
@@ -40,20 +41,20 @@ class DatabaseService {
4041
);
4142
log('Stored alarm action: $actionType');
4243

43-
var actions = getAllAlarmActions();
44+
final actions = getAllAlarmActions();
4445
log('Retrieved ${actions.length} alarm actions.');
45-
} catch (e) {
46+
} on Exception catch (e) {
4647
log('Failed to store alarm action: $e');
4748
}
4849
}
4950

5051
// Retrieve all alarm actions from the Hive box
5152
List<AlarmAction> getAllAlarmActions() {
5253
try {
53-
var actions = _alarmBox.values;
54+
final actions = _alarmBox.values;
5455
log('Retrieved ${actions.length} alarm actions.');
5556
return actions.toList();
56-
} catch (e) {
57+
} on Exception catch (e) {
5758
log('Failed to retrieve alarm actions: $e');
5859
return [];
5960
}
@@ -64,7 +65,7 @@ class DatabaseService {
6465
try {
6566
await _alarmBox.clear();
6667
log('All alarm actions cleared.');
67-
} catch (e) {
68+
} on Exception catch (e) {
6869
log('Failed to clear alarm actions: $e');
6970
}
7071
}

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_alarm_manager_poc/alarm_manager_screen.dart';
33
import 'package:flutter_alarm_manager_poc/hive/service/database_service.dart';
4-
import 'utils/alarm_method_channel.dart';
4+
import 'package:flutter_alarm_manager_poc/utils/alarm_method_channel.dart';
55

66
void main() async {
77
WidgetsFlutterBinding.ensureInitialized();

lib/utils/alarm_method_channel.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:flutter/services.dart';
44
import 'package:flutter_alarm_manager_poc/hive/service/database_service.dart';
55

66
class AlarmMethodChannel {
7-
static const name = "Flutter";
7+
static const name = 'Flutter';
88
static const platform = MethodChannel('com.example/alarm_manager');
99

1010
static Future<void> scheduleAlarm() async {
@@ -27,20 +27,18 @@ class AlarmMethodChannel {
2727
log(name: name, 'Alarm was accepted');
2828
// await alarmBox.add(AlarmAction('accept', DateTime.now()));
2929

30-
await DatabaseService.instance.storeAlarmAction("accept");
30+
await DatabaseService.instance.storeAlarmAction('accept');
3131

32-
// Handle alarm accepted
33-
// You can call a function or update state here
34-
break;
32+
// Handle alarm accepted
33+
// You can call a function or update state here
3534
case 'alarmSnoozed':
3635
log(name: name, 'Alarm was snoozed');
3736
// await alarmBox.add(AlarmAction('snooze', DateTime.now()));
3837

39-
await DatabaseService.instance.storeAlarmAction("snooze");
38+
await DatabaseService.instance.storeAlarmAction('snooze');
4039

41-
// Handle alarm snoozed
42-
// You can call a function or update state here
43-
break;
40+
// Handle alarm snoozed
41+
// You can call a function or update state here
4442
default:
4543
log('Unrecognized method ${call.method}');
4644
}

pubspec.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,18 @@ environment:
2828
# the latest version available on pub.dev. To see which dependencies have newer
2929
# versions available, run `flutter pub outdated`.
3030
dependencies:
31-
flutter:
32-
sdk: flutter
33-
34-
3531
# The following adds the Cupertino Icons font to your application.
3632
# Use with the CupertinoIcons class for iOS style icons.
3733
cupertino_icons: ^1.0.8
34+
flutter:
35+
sdk: flutter
3836
hive: ^2.2.3
3937
hive_flutter: ^1.1.0
4038
permission_handler: ^11.3.1
4139

4240

4341
dev_dependencies:
42+
build_runner: ^2.4.12
4443
flutter_test:
4544
sdk: flutter
4645
hive_generator: ^2.0.1

test/widget_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
// tree, read text, and verify that the values of widget properties are correct.
77

88
import 'package:flutter/material.dart';
9-
import 'package:flutter_test/flutter_test.dart';
10-
119
import 'package:flutter_alarm_manager_poc/main.dart';
10+
import 'package:flutter_test/flutter_test.dart';
1211

1312
void main() {
1413
testWidgets('Counter increments smoke test', (WidgetTester tester) async {

0 commit comments

Comments
 (0)