Skip to content

Commit

Permalink
Apply very_good_analysis to example app
Browse files Browse the repository at this point in the history
  • Loading branch information
gdelataillade committed Apr 26, 2024
1 parent a30a015 commit cbacf4d
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 107 deletions.
2 changes: 2 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![style: very good analysis](https://img.shields.io/badge/style-very_good_analysis-B22C89.svg)](https://pub.dev/packages/very_good_analysis)

# alarm_example

Demonstrates how to use the alarm plugin.
Expand Down
29 changes: 2 additions & 27 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

include: package:very_good_analysis/analysis_options.yaml
linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
public_member_api_docs: false
7 changes: 4 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import 'dart:async';

import 'package:alarm/alarm.dart';
import 'package:alarm_example/screens/home.dart';
import 'package:flutter/material.dart';
import 'package:alarm/alarm.dart';
import 'package:flutter/services.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);

await Alarm.init(showDebugLogs: true);
await Alarm.init();

runApp(
MaterialApp(
Expand Down
14 changes: 8 additions & 6 deletions example/lib/screens/edit_alarm.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'dart:io';

import 'package:alarm/alarm.dart';
import 'package:alarm/model/alarm_settings.dart';
import 'package:flutter/material.dart';

class ExampleAlarmEditScreen extends StatefulWidget {
final AlarmSettings? alarmSettings;
const ExampleAlarmEditScreen({super.key, this.alarmSettings});

const ExampleAlarmEditScreen({Key? key, this.alarmSettings})
: super(key: key);
final AlarmSettings? alarmSettings;

@override
State<ExampleAlarmEditScreen> createState() => _ExampleAlarmEditScreenState();
Expand Down Expand Up @@ -68,7 +69,7 @@ class _ExampleAlarmEditScreenState extends State<ExampleAlarmEditScreen> {

if (res != null) {
setState(() {
final DateTime now = DateTime.now();
final now = DateTime.now();
selectedDateTime = now.copyWith(
hour: res.hour,
minute: res.minute,
Expand Down Expand Up @@ -97,6 +98,7 @@ class _ExampleAlarmEditScreenState extends State<ExampleAlarmEditScreen> {
assetAudioPath: assetAudio,
notificationTitle: 'Alarm example',
notificationBody: 'Your alarm ($id) is ringing',
enableNotificationOnKill: Platform.isIOS,
);
return alarmSettings;
}
Expand Down Expand Up @@ -129,7 +131,7 @@ class _ExampleAlarmEditScreenState extends State<ExampleAlarmEditScreen> {
TextButton(
onPressed: () => Navigator.pop(context, false),
child: Text(
"Cancel",
'Cancel',
style: Theme.of(context)
.textTheme
.titleLarge!
Expand All @@ -141,7 +143,7 @@ class _ExampleAlarmEditScreenState extends State<ExampleAlarmEditScreen> {
child: loading
? const CircularProgressIndicator()
: Text(
"Save",
'Save',
style: Theme.of(context)
.textTheme
.titleLarge!
Expand Down
39 changes: 19 additions & 20 deletions example/lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

class ExampleAlarmHomeScreen extends StatefulWidget {
const ExampleAlarmHomeScreen({Key? key}) : super(key: key);
const ExampleAlarmHomeScreen({super.key});

@override
State<ExampleAlarmHomeScreen> createState() => _ExampleAlarmHomeScreenState();
Expand All @@ -29,9 +29,7 @@ class _ExampleAlarmHomeScreenState extends State<ExampleAlarmHomeScreen> {
checkAndroidScheduleExactAlarmPermission();
}
loadAlarms();
subscription ??= Alarm.ringStream.stream.listen(
(alarmSettings) => navigateToRingScreen(alarmSettings),
);
subscription ??= Alarm.ringStream.stream.listen(navigateToRingScreen);
}

void loadAlarms() {
Expand All @@ -44,7 +42,7 @@ class _ExampleAlarmHomeScreenState extends State<ExampleAlarmHomeScreen> {
Future<void> navigateToRingScreen(AlarmSettings alarmSettings) async {
await Navigator.push(
context,
MaterialPageRoute(
MaterialPageRoute<void>(
builder: (context) =>
ExampleAlarmRingScreen(alarmSettings: alarmSettings),
),
Expand All @@ -54,17 +52,18 @@ class _ExampleAlarmHomeScreenState extends State<ExampleAlarmHomeScreen> {

Future<void> navigateToAlarmScreen(AlarmSettings? settings) async {
final res = await showModalBottomSheet<bool?>(
context: context,
isScrollControlled: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
builder: (context) {
return FractionallySizedBox(
heightFactor: 0.75,
child: ExampleAlarmEditScreen(alarmSettings: settings),
);
});
context: context,
isScrollControlled: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
builder: (context) {
return FractionallySizedBox(
heightFactor: 0.75,
child: ExampleAlarmEditScreen(alarmSettings: settings),
);
},
);

if (res != null && res == true) loadAlarms();
}
Expand All @@ -75,7 +74,7 @@ class _ExampleAlarmHomeScreenState extends State<ExampleAlarmHomeScreen> {
alarmPrint('Requesting notification permission...');
final res = await Permission.notification.request();
alarmPrint(
'Notification permission ${res.isGranted ? '' : 'not '}granted.',
'Notification permission ${res.isGranted ? '' : 'not '}granted',
);
}
}
Expand All @@ -86,7 +85,7 @@ class _ExampleAlarmHomeScreenState extends State<ExampleAlarmHomeScreen> {
alarmPrint('Requesting external storage permission...');
final res = await Permission.storage.request();
alarmPrint(
'External storage permission ${res.isGranted ? '' : 'not'} granted.',
'External storage permission ${res.isGranted ? '' : 'not'} granted',
);
}
}
Expand All @@ -98,7 +97,7 @@ class _ExampleAlarmHomeScreenState extends State<ExampleAlarmHomeScreen> {
alarmPrint('Requesting schedule exact alarm permission...');
final res = await Permission.scheduleExactAlarm.request();
alarmPrint(
'Schedule exact alarm permission ${res.isGranted ? '' : 'not'} granted.',
'Schedule exact alarm permission ${res.isGranted ? '' : 'not'} granted',
);
}
}
Expand Down Expand Up @@ -134,7 +133,7 @@ class _ExampleAlarmHomeScreenState extends State<ExampleAlarmHomeScreen> {
)
: Center(
child: Text(
"No alarms set",
'No alarms set',
style: Theme.of(context).textTheme.titleMedium,
),
),
Expand Down
15 changes: 6 additions & 9 deletions example/lib/screens/ring.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import 'package:alarm/model/alarm_settings.dart';
import 'package:flutter/material.dart';

class ExampleAlarmRingScreen extends StatelessWidget {
final AlarmSettings alarmSettings;
const ExampleAlarmRingScreen({required this.alarmSettings, super.key});

const ExampleAlarmRingScreen({Key? key, required this.alarmSettings})
: super(key: key);
final AlarmSettings alarmSettings;

@override
Widget build(BuildContext context) {
Expand All @@ -16,10 +15,10 @@ class ExampleAlarmRingScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
"You alarm (${alarmSettings.id}) is ringing...",
'You alarm (${alarmSettings.id}) is ringing...',
style: Theme.of(context).textTheme.titleLarge,
),
const Text("🔔", style: TextStyle(fontSize: 50)),
const Text('🔔', style: TextStyle(fontSize: 50)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Expand All @@ -34,14 +33,12 @@ class ExampleAlarmRingScreen extends StatelessWidget {
now.day,
now.hour,
now.minute,
0,
0,
).add(const Duration(minutes: 1)),
),
).then((_) => Navigator.pop(context));
},
child: Text(
"Snooze",
'Snooze',
style: Theme.of(context).textTheme.titleLarge,
),
),
Expand All @@ -51,7 +48,7 @@ class ExampleAlarmRingScreen extends StatelessWidget {
.then((_) => Navigator.pop(context));
},
child: Text(
"Stop",
'Stop',
style: Theme.of(context).textTheme.titleLarge,
),
),
Expand Down
21 changes: 13 additions & 8 deletions example/lib/screens/shortcut_button.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import 'dart:io';

import 'package:alarm/alarm.dart';
import 'package:alarm/model/alarm_settings.dart';
import 'package:flutter/material.dart';

class ExampleAlarmHomeShortcutButton extends StatefulWidget {
final void Function() refreshAlarms;
const ExampleAlarmHomeShortcutButton({
required this.refreshAlarms,
super.key,
});

const ExampleAlarmHomeShortcutButton({Key? key, required this.refreshAlarms})
: super(key: key);
final void Function() refreshAlarms;

@override
State<ExampleAlarmHomeShortcutButton> createState() =>
Expand All @@ -18,7 +22,7 @@ class _ExampleAlarmHomeShortcutButtonState
bool showMenu = false;

Future<void> onPressButton(int delayInHours) async {
DateTime dateTime = DateTime.now().add(Duration(hours: delayInHours));
var dateTime = DateTime.now().add(Duration(hours: delayInHours));
double? volume;

if (delayInHours != 0) {
Expand All @@ -36,6 +40,7 @@ class _ExampleAlarmHomeShortcutButtonState
notificationTitle: 'Alarm example',
notificationBody:
'Shortcut button alarm with delay of $delayInHours hours',
enableNotificationOnKill: Platform.isIOS,
);

await Alarm.set(alarmSettings: alarmSettings);
Expand All @@ -55,7 +60,7 @@ class _ExampleAlarmHomeShortcutButtonState
onPressed: () => onPressButton(0),
backgroundColor: Colors.red,
heroTag: null,
child: const Text("RING NOW", textAlign: TextAlign.center),
child: const Text('RING NOW', textAlign: TextAlign.center),
),
),
if (showMenu)
Expand All @@ -64,15 +69,15 @@ class _ExampleAlarmHomeShortcutButtonState
children: [
TextButton(
onPressed: () => onPressButton(24),
child: const Text("+24h"),
child: const Text('+24h'),
),
TextButton(
onPressed: () => onPressButton(36),
child: const Text("+36h"),
child: const Text('+36h'),
),
TextButton(
onPressed: () => onPressButton(48),
child: const Text("+48h"),
child: const Text('+48h'),
),
],
),
Expand Down
12 changes: 6 additions & 6 deletions example/lib/widgets/tile.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import 'package:flutter/material.dart';

class ExampleAlarmTile extends StatelessWidget {
final String title;
final void Function() onPressed;
final void Function()? onDismissed;

const ExampleAlarmTile({
Key? key,
required this.title,
required this.onPressed,
super.key,
this.onDismissed,
}) : super(key: key);
});

final String title;
final void Function() onPressed;
final void Function()? onDismissed;

@override
Widget build(BuildContext context) {
Expand Down
24 changes: 8 additions & 16 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.3.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
url: "https://pub.dev"
source: hosted
version: "2.0.3"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -135,14 +127,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints:
dependency: transitive
description:
name: lints
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -380,6 +364,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
very_good_analysis:
dependency: "direct dev"
description:
name: very_good_analysis
sha256: "9ae7f3a3bd5764fb021b335ca28a34f040cd0ab6eec00a1b213b445dae58a4b8"
url: "https://pub.dev"
source: hosted
version: "5.1.0"
vm_service:
dependency: transitive
description:
Expand Down
Loading

0 comments on commit cbacf4d

Please sign in to comment.