Skip to content

Instantly share code, notes, and snippets.

import 'package:direct_reply_notification/data-service.dart';
import 'package:direct_reply_notification/flutter-method-channel.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
FlutterMethodChannel.instance.configureChannel();
}
class MyApp extends StatelessWidget {
import 'dart:async';
class DataService {
StreamController<String> ideaController;
static final DataService instance = DataService._init();
DataService._init() {
ideaController = StreamController();
}
import 'package:direct_reply_notification/data-service.dart';
import 'package:flutter/services.dart';
class FlutterMethodChannel {
static const channelName = 'channel';
MethodChannel methodChannel;
static final FlutterMethodChannel instance = FlutterMethodChannel._init();
FlutterMethodChannel._init();
@vreamer
vreamer / NotificationReceiver.kt
Created August 26, 2020 08:15
Invoke method channel
package com.example.direct_reply_notification
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.core.app.RemoteInput
class NotificationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
@vreamer
vreamer / NativeMethodChannel.kt
Created August 26, 2020 08:12
Show new idea
package com.example.direct_reply_notification
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
object NativeMethodChannel {
private const val CHANNEL_NAME = "channel"
private lateinit var methodChannel: MethodChannel
fun configureChannel(flutterEngine: FlutterEngine) {
@vreamer
vreamer / main.dart
Created August 26, 2020 08:07
Configure channel
import 'package:direct_reply_notification/flutter-method-channel.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
FlutterMethodChannel.instance.configureChannel(); // configure method channel
}
@vreamer
vreamer / flutter-method-channel.dart
Created August 26, 2020 08:05
Configure method channel
import 'package:flutter/services.dart';
class FlutterMethodChannel {
static const channelName = 'channel'; // this channel name needs to match the one in Native method channel
MethodChannel methodChannel;
static final FlutterMethodChannel instance = FlutterMethodChannel._init();
FlutterMethodChannel._init();
void configureChannel() {
@vreamer
vreamer / MainActivity.kt
Created August 26, 2020 08:02
Configure flutter engine
package com.example.direct_reply_notification
import android.os.Bundle
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
NativeMethodChannel.configureChannel(flutterEngine)
@vreamer
vreamer / NativeMethodChannel.kt
Created August 26, 2020 07:59
Configure Method Channel
package com.example.direct_reply_notification
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
object NativeMethodChannel {
private const val CHANNEL_NAME = "channel"
private lateinit var methodChannel: MethodChannel
fun configureChannel(flutterEngine: FlutterEngine) {
@vreamer
vreamer / AndroidManifest.xml
Created August 25, 2020 05:34
Register Notification Receiver
</activity>
<!-- add the line below to register receiver -->
<receiver android:name=".NotificationReceiver"/>
</application>