Skip to content

Commit

Permalink
#20 add test android notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
floodoo committed Jan 22, 2022
1 parent 95b9046 commit f9ce479
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
Binary file added android/app/src/main/res/drawable/app_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions lib/core/service/notification.service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationService {
static final NotificationService _notificationService = NotificationService._internal();
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

NotificationDetails platformChannelSpecifics = const NotificationDetails(
android: AndroidNotificationDetails(
"0",
"Flutter Local Notification",
importance: Importance.defaultImportance,
priority: Priority.defaultPriority,
),
);

factory NotificationService() {
return _notificationService;
}

NotificationService._internal();

Future<void> init() async {
const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('app_icon');

const InitializationSettings initializationSettings =
InitializationSettings(android: initializationSettingsAndroid);

await flutterLocalNotificationsPlugin.initialize(
initializationSettings,
);
}

void sendAndoidNotification({required String title, required String body}) async {
await flutterLocalNotificationsPlugin.show(
0,
title,
body,
platformChannelSpecifics,
payload: 'data',
);
}
}
6 changes: 5 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:untis_phasierung/core/service/notification.service.dart';
import 'package:untis_phasierung/core/service/services.dart';
import 'package:untis_phasierung/ui/screens/settings/settings.screen.dart';
import 'package:untis_phasierung/ui/screens/time_table/time_table.screen.dart';
Expand All @@ -8,8 +10,10 @@ import 'package:untis_phasierung/ui/shared/custom_drawer.dart';
import 'package:logger/logger.dart';
import 'package:untis_phasierung/ui/screens/login/login.screen.dart';

void main() {
Future<void> main() async {
Logger.level = Level.debug;
WidgetsFlutterBinding.ensureInitialized();
await NotificationService().init();
runApp(
const ProviderScope(
child: MyApp(),
Expand Down
10 changes: 9 additions & 1 deletion lib/ui/screens/time_table/time_table.screen.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:liquid_pull_to_refresh/liquid_pull_to_refresh.dart';
import 'package:untis_phasierung/core/api/models/timetable.hour.dart';
import 'package:untis_phasierung/core/api/timetable.dart';
import 'package:untis_phasierung/core/excel/models/mergedtimetable.dart';
import 'package:untis_phasierung/core/service/notification.service.dart';
import 'package:untis_phasierung/core/service/services.dart';
import 'package:untis_phasierung/ui/screens/time_table/widgets/custom_time_table_card.dart';
import 'package:untis_phasierung/ui/screens/time_table/widgets/custom_time_table_day_card.dart';
Expand Down Expand Up @@ -245,7 +247,13 @@ class TimeTableScreen extends ConsumerWidget {
},
icon: const Icon(Icons.today),
tooltip: "Spring zur aktuellen Woche",
)
),
IconButton(
onPressed: () {
NotificationService().sendAndoidNotification(title: "Test", body: "lol");
},
icon: const Icon(Icons.notification_add),
),
],
),
drawer: const CustomDrawer(),
Expand Down
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies:
file_picker: ^4.3.1
flutter:
sdk: flutter
flutter_local_notifications: ^9.2.0
flutter_secure_storage: ^5.0.2
fluttericon: ^2.0.0
google_fonts: ^2.2.0
Expand All @@ -26,9 +27,9 @@ dependencies:
url_launcher: ^6.0.17

dev_dependencies:
flutter_native_splash: ^1.3.3
flutter_launcher_icons: "^0.9.2"
flutter_lints: ^1.0.0
flutter_native_splash: ^1.3.3
flutter_test:
sdk: flutter

Expand All @@ -40,4 +41,4 @@ flutter:
flutter_icons:
android: true
ios: true
image_path: "assets/images/app_icon.png"
image_path: "assets/images/app_icon.png"

0 comments on commit f9ce479

Please sign in to comment.