title: How to push notification in flutter using FCM
body: <p>I'm trying to push a notification from firebase using FCM by following the code in the youtube. When run the system, I found this error:</p>
  <blockquote>
  <p>[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(error, NotificationChannelGroup doesn't exist, null, java.lang.IllegalArgumentException: NotificationChannelGroup doesn't exist</p>
  </blockquote>
  <p>In the firebase console, the status is complete, but it did not push to the emulator. Anyone can help me what is the problem?</p>
  <p>main.dart code</p>
  <pre><code>import 'package:flutter/material.dart';
  
  import 'package:flutter_localizations/flutter_localizations.dart';
  import 'package:monger_app/WelcomeScreen/login.dart';
  import 'package:monger_app/WelcomeScreen/signup.dart';
  import 'package:monger_app/WelcomeScreen/welcome_screen.dart';
  import 'package:monger_app/localization/demo_localization.dart';
  import 'package:monger_app/page/pushNotification.dart';
  import 'package:monger_app/page/root.dart';
  import 'package:monger_app/theme/colors.dart';
  import 'package:firebase_core/firebase_core.dart';
  import 'package:provider/provider.dart';
  import 'localization/localization_constants.dart';
  
  
  
  void main() async {
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    //FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  
    return runApp(ChangeNotifierProvider(
      child: MyApp(),
      create: (BuildContext context) =&gt; ThemeProvider(isDarkMode: true),
    ));
  }
  
  class MyApp extends StatefulWidget {
  
    static void setLocale(BuildContext context, Locale locale){
      _MyAppState state = context.findAncestorStateOfType&lt;_MyAppState&gt;();
      state.setLocale(locale);
    }
    @override
    _MyAppState createState() =&gt; _MyAppState();
  }
  
  class _MyAppState extends State&lt;MyApp&gt; {
  
    Locale _locale;
  
    void setLocale(Locale locale){
      setState(() {
        _locale = locale;
      });
    }
  
    FirebaseNotifcation firebase;
  
    handleAsync() async {
      await firebase.initialize();
  
      String token = await firebase.getToken();
      print(&quot;Firebase token : $token&quot;);
    }
  
    @override
    void initState() {
      super.initState();
      firebase = FirebaseNotifcation();
      handleAsync();
    }
  
   @override
    void didChangeDependencies() {
      getLocale().then((locale){
        setState(() {
          this._locale = locale;
        });
      });
      super.didChangeDependencies();
    }
  
    @override
    Widget build(BuildContext context) {
      return Consumer&lt;ThemeProvider&gt;(
        builder: (context, themeProvider, child){
          if (_locale == null) {
            return Container(
              child: Center(
                child: CircularProgressIndicator(),
              ),
            );
          } else {
            return MaterialApp(
              theme: themeProvider.getTheme,
              locale: _locale,
              supportedLocales: [
                Locale('en', 'US'),
                Locale('id', 'ID'),
                Locale('zh', 'CN'),
              ],
              localizationsDelegates: [
                DemoLocalization.delegate,
                GlobalMaterialLocalizations.delegate,
                GlobalWidgetsLocalizations.delegate,
                GlobalCupertinoLocalizations.delegate,
              ],
              localeResolutionCallback: (deviceLocale, supportedLocales){
                for (var locale in supportedLocales) {
                  if (locale.languageCode == deviceLocale.languageCode &amp;&amp; locale.countryCode == deviceLocale.countryCode) {
                    return deviceLocale;
                  }
                }
                return supportedLocales.first;
              },
              debugShowCheckedModeBanner: false,
              home:
  
              WelcomeScreen(),
  
              routes: &lt;String,WidgetBuilder&gt;{
  
                &quot;SignIn&quot; : (BuildContext context)=&gt;LoginPage(),
                &quot;SignUp&quot;:(BuildContext context)=&gt;SignUpPage(),
                &quot;start&quot;:(BuildContext context)=&gt;Root(),
                &quot;welcome&quot;:(BuildContext context)=&gt;WelcomeScreen(),
              },
  
            );
          }
        }
      );
    }
  }
  </code></pre>
  <p>puchNotification.dart code</p>
  <pre><code>import 'package:firebase_core/firebase_core.dart';
  import 'package:firebase_messaging/firebase_messaging.dart';
  import 'package:flutter_local_notifications/flutter_local_notifications.dart';
  
  const AndroidNotificationChannel channel = AndroidNotificationChannel(
      'high_importance_channel',
      &quot;High Importance Notifcations&quot;,
      &quot;This channel is used important notification&quot;,
      groupId: &quot;Notification_group&quot;);
  
  final FlutterLocalNotificationsPlugin flutterLocalNotificationplugin =
  FlutterLocalNotificationsPlugin();
  
  Future&lt;void&gt; _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
    await Firebase.initializeApp();
    print(&quot;Handling a background message : ${message.messageId}&quot;);
    print(message.data);
  }
  
  class FirebaseNotifcation {
    initialize() async {
      await Firebase.initializeApp();
      FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  
      await flutterLocalNotificationplugin
          .resolvePlatformSpecificImplementation&lt;
          AndroidFlutterLocalNotificationsPlugin&gt;()
          ?.createNotificationChannel(channel);
      var intializationSettingsAndroid =
      AndroidInitializationSettings('@mipmap/ic_launcher');
      var initializationSettings =
      InitializationSettings(android: intializationSettingsAndroid);
  
      flutterLocalNotificationplugin.initialize(initializationSettings);
      FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
        RemoteNotification notification = message.notification;
        AndroidNotification android = message.notification?.android;
        if (notification != null &amp;&amp; android != null) {
          AndroidNotificationDetails notificationDetails =
          AndroidNotificationDetails(
              channel.id, channel.name, channel.description,
              importance: Importance.max,
              priority: Priority.high,
              groupKey: channel.groupId);
          NotificationDetails notificationDetailsPlatformSpefics =
          NotificationDetails(android: notificationDetails);
          flutterLocalNotificationplugin.show(
              notification.hashCode,
              notification.title,
              notification.body,
              notificationDetailsPlatformSpefics);
        }
  
        List&lt;ActiveNotification&gt; activeNotifications =
        await flutterLocalNotificationplugin
            .resolvePlatformSpecificImplementation&lt;
            AndroidFlutterLocalNotificationsPlugin&gt;()
            ?.getActiveNotifications();
        if (activeNotifications.length &gt; 0) {
          List&lt;String&gt; lines =
          activeNotifications.map((e) =&gt; e.title.toString()).toList();
          InboxStyleInformation inboxStyleInformation = InboxStyleInformation(
              lines,
              contentTitle: &quot;${activeNotifications.length - 1} messages&quot;,
              summaryText: &quot;${activeNotifications.length - 1} messages&quot;);
          AndroidNotificationDetails groupNotificationDetails =
          AndroidNotificationDetails(
              channel.id, channel.name, channel.description,
              styleInformation: inboxStyleInformation,
              setAsGroupSummary: true,
              groupKey: channel.groupId);
  
          NotificationDetails groupNotificationDetailsPlatformSpefics =
          NotificationDetails(android: groupNotificationDetails);
          await flutterLocalNotificationplugin.show(
              0, '', '', groupNotificationDetailsPlatformSpefics);
        }
      });
    }
  
    Future&lt;String&gt; getToken() async {
      String token = await FirebaseMessaging.instance.getToken();
      print(token);
      return token;
    }
  
    subscribeToTopic(String topic) async {
      await FirebaseMessaging.instance.subscribeToTopic(topic);
    }
  }
  </code></pre>
  <p>build.gradle file</p>
  <pre><code>def localProperties = new Properties()
  def localPropertiesFile = rootProject.file('local.properties')
  if (localPropertiesFile.exists()) {
      localPropertiesFile.withReader('UTF-8') { reader -&gt;
          localProperties.load(reader)
      }
  }
  
  def flutterRoot = localProperties.getProperty('flutter.sdk')
  if (flutterRoot == null) {
      throw new GradleException(&quot;Flutter SDK not found. Define location with flutter.sdk in the local.properties file.&quot;)
  }
  
  def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
  if (flutterVersionCode == null) {
      flutterVersionCode = '1'
  }
  
  def flutterVersionName = localProperties.getProperty('flutter.versionName')
  if (flutterVersionName == null) {
      flutterVersionName = '1.0'
  }
  
  apply plugin: 'com.android.application'
  apply plugin: 'com.google.gms.google-services'
  apply plugin: 'kotlin-android'
  apply from: &quot;$flutterRoot/packages/flutter_tools/gradle/flutter.gradle&quot;
  
  android {
      compileSdkVersion 30
  
      sourceSets {
          main.java.srcDirs += 'src/main/kotlin'
      }
  
      defaultConfig {
          // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
          applicationId &quot;com.example.monger_app&quot;
          minSdkVersion 21
          targetSdkVersion 30
          versionCode flutterVersionCode.toInteger()
          versionName flutterVersionName
      }
  
      buildTypes {
          release {
              // TODO: Add your own signing config for the release build.
              // Signing with the debug keys for now, so `flutter run --release` works.
              signingConfig signingConfigs.debug
          }
      }
  }
  
  flutter {
      source '../..'
  }
  
  dependencies {
      implementation &quot;org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version&quot;
      implementation platform('com.google.firebase:firebase-bom:28.0.1')
      implementation &quot;com.google.firebase:firebase-messaging:20.1.0&quot;
  }
  
  apply plugin: 'com.google.gms.google-services'
  </code></pre>
  <p>AndroidManifest.xml</p>
  <pre><code>&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      package=&quot;com.example.monger_app&quot;&gt;
  
     &lt;application
         tools:replace=&quot;android:label&quot;
          android:name=&quot;.Application&quot;
          android:label=&quot;MONGE&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;&gt;
          &lt;activity
              android:name=&quot;.MainActivity&quot;
              android:launchMode=&quot;singleTop&quot;
              android:theme=&quot;@style/LaunchTheme&quot;
              android:configChanges=&quot;orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode&quot;
              android:hardwareAccelerated=&quot;true&quot;
              android:windowSoftInputMode=&quot;adjustResize&quot;&gt;
              &lt;!-- Specifies an Android theme to apply to this Activity as soon as
                   the Android process has started. This theme is visible to the user
                   while the Flutter UI initializes. After that, this theme continues
                   to determine the Window background behind the Flutter UI. --&gt;
              &lt;meta-data
                android:name=&quot;io.flutter.embedding.android.NormalTheme&quot;
                android:resource=&quot;@style/NormalTheme&quot;
                /&gt;
              &lt;!-- Displays an Android View that continues showing the launch screen
                   Drawable until Flutter paints its first frame, then this splash
                   screen fades out. A splash screen is useful to avoid any visual
                   gap between the end of Android's launch screen and the painting of
                   Flutter's first frame. --&gt;
              &lt;meta-data
                android:name=&quot;io.flutter.embedding.android.SplashScreenDrawable&quot;
                android:resource=&quot;@drawable/launch_background&quot;
                /&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;/&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;FLUTTER_NOTIFICATION_CLICK&quot; /&gt;
                  &lt;category android:name=&quot;android.intent.category.DEFAULT&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;!-- Don't delete the meta-data below.
               This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --&gt;
          &lt;meta-data
              android:name=&quot;flutterEmbedding&quot;
              android:value=&quot;2&quot; /&gt;
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/lVjbm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lVjbm.png" alt="Complete Status Firebase" /></a></p>