Skip to content

Commit

Permalink
Add flutter_local_notifications module, NotiManager
Browse files Browse the repository at this point in the history
  • Loading branch information
djkim committed Jul 31, 2019
1 parent b453224 commit 59f2d2d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Binary file added android/app/src/main/res/drawable/app_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions lib/base/noti_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotiManager {
FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin;

NotiManager._privateConstructor() {
init();
}

void init() {
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
// If you have skipped STEP 3 then change app_icon to @mipmap/ic_launcher
var initializationSettingsAndroid =
new AndroidInitializationSettings('app_icon');
var initializationSettingsIOS = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
_flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
_flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: null);
}

static final NotiManager instance = NotiManager._privateConstructor();

void showAlert(String message) async {
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'CHANNEL_FOR_DEBUG', 'Debug', 'Notification for debug',
playSound: false, importance: Importance.Max, priority: Priority.High);
var iOSPlatformChannelSpecifics =
new IOSNotificationDetails(presentSound: false);
var platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await _flutterLocalNotificationsPlugin.show(
message.hashCode,
'Debug!!',
message,
platformChannelSpecifics,
payload: message,
);
}
}
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';

import 'base/debug_utils.dart';
import 'base/noti_manager.dart';
import 'generated/i18n.dart';
import 'settings.dart';

Expand Down Expand Up @@ -40,6 +41,9 @@ class _MyHomePageState extends State<MyHomePage> {

Log.d("main", "floating button pressed: counter = $_counter");

NotiManager.instance
.showAlert("floating button pressed: counter = $_counter");

setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
Expand Down
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ dependencies:
# logging
fimber:

# notification
flutter_local_notifications:

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down

0 comments on commit 59f2d2d

Please sign in to comment.