• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Flutter 게시판 +버튼 눌러도 알림이 뜨지 않습니다

+버튼 눌러도 알림이 뜨지 않습니다

4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 글쓴이
  • #44167

    김다연
    참가자
    D/EGL_emulation( 7828): app_time_stats: avg=737.61ms min=8.55ms max=15888.29ms count=22
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): Failed to handle method call
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:326)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:233)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1031)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1372)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1241)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at android.os.Handler.handleCallback(Handler.java:938)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at android.os.Looper.loopOnce(Looper.java:201)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at android.os.Looper.loop(Looper.java:288)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at android.app.ActivityThread.main(ActivityThread.java:7839)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at java.lang.reflect.Method.invoke(Native Method)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    E/MethodChannel#dexterous.com/flutter/local_notifications( 7828): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
    E/flutter ( 7828): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
    E/flutter ( 7828): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:326)
    E/flutter ( 7828): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:233)
    E/flutter ( 7828): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1031)
    E/flutter ( 7828): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1372)
    E/flutter ( 7828): 	at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1241)
    E/flutter ( 7828): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
    E/flutter ( 7828): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
    E/flutter ( 7828): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
    E/flutter ( 7828): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
    E/flutter ( 7828): 	at android.os.Handler.handleCallback(Handler.java:938)
    E/flutter ( 7828): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    E/flutter ( 7828): 	at android.os.Looper.loopOnce(Looper.java:201)
    E/flutter ( 7828): 	at android.os.Looper.loop(Looper.java:288)
    E/flutter ( 7828): 	at android.app.ActivityThread.main(ActivityThread.java:7839)
    E/flutter ( 7828): 	at java.lang.reflect.Method.invoke(Native Method)
    E/flutter ( 7828): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    E/flutter ( 7828): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
    E/flutter ( 7828): )
    E/flutter ( 7828): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
    E/flutter ( 7828): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
    E/flutter ( 7828): <asynchronous suspension>
    E/flutter ( 7828): #2      FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:215:7)
    E/flutter ( 7828): <asynchronous suspension>
    E/flutter ( 7828): 
    
    현재 인스타강의를 듣고있는데요 floatingButton을 눌러도 notification이 위에 안뜨고 저런 오류문장이 뜹니다ㅜ
    에뮬레이터 저장공간이 부족한가 싶어서 용량을 4096으로 늘려줘도 안되네요
    
    코딩애플님이 쓰신 코드를 사용했습니다 참고로 덧붙입니다..!ㅠ
    
    
    
    class MyApp extends StatefulWidget {
      const MyApp({Key? key}) : super(key: key);
      @override
      State<MyApp> createState() => _MyAppState();
    }
    class _MyAppState extends State<MyApp> {
      var tab = 0; //state에 tab의 현재상태 저장 '홈' 이렇게 한글로 저장해도 상관x
      var data = [];
      //선택한 이미지를 위젯에 보여주기
      var userImage;
      var userContent;
      saveData() async {
        var storage = await SharedPreferences.getInstance(); //저장공간 오픈
        var map = {'age': 20};
        storage.setString('map', jsonEncode(map));
        var result = storage.getString('map') ?? '없는데요';
        print(jsonDecode(result)['age']);
      }
      addMyData() {
        var myData = {
          'id': data.length, //유니크한 번호 부여가능
          'image': userImage,
          'likes': 5,
          'date': 'July 25',
          'content': userContent,
          'liked': false,
          'user': 'Dayeon',
        };
        setState(() {
          data.insert(0, myData);
        });
      }
      setUserContent(a) {
        setState(() {
          userContent = a;
        });
      }
      addData(a) {
        setState(() {
          data.add(a);
        });
      }
      getData() async {
        var result = await http
            .get(Uri.parse('https://codingapple1.github.io/app/data.json'));
        var result2 = jsonDecode(result.body);
        setState(() {
          data = result2;
        });
      }
      @override
      void initState() {
        super.initState();
        initNotification();
        saveData();
        getData();
      }
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          floatingActionButton: FloatingActionButton(
            child: Text('+'),
            onPressed: () {
              showNotification();
            },
          ),
    
     
    #44176

    codingapple
    키 마스터
    notification 파일에 오타가 있거나 그럴 수 있습니다
    #44190

    김다연
    참가자
    복사붙여넣기 해서 오류는 없을 것 같습니다
    
    
    import 'package:flutter/material.dart';
    import 'package:flutter_local_notifications/flutter_local_notifications.dart';
    import 'package:timezone/data/latest_all.dart' as tz;
    import 'package:timezone/timezone.dart' as tz;
    final notifications = FlutterLocalNotificationsPlugin();
    //1. 앱로드시 실행할 기본설정
    initNotification(context) async {
    //안드로이드용 아이콘파일 이름
      var androidSetting = AndroidInitializationSettings('app_icon');
    //ios에서 앱 로드시 유저에게 권한요청하려면
      var iosSetting = IOSInitializationSettings(
        requestAlertPermission: true,
        requestBadgePermission: true,
        requestSoundPermission: true,
      );
      var initializationSettings =
          InitializationSettings(android: androidSetting, iOS: iosSetting);
      await notifications.initialize(initializationSettings,
    //알림 누를때 함수실행하고 싶으면//onSelectNotification: 함수명추가
          onSelectNotification: (payload) {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => Text('새로운페이지'),
          ),
        );
      });
    }
    showNotification() async {
      var androidDetails = AndroidNotificationDetails(
        '유니크한 알림 채널 ID',
        '알림종류 설명',
        priority: Priority.high,
        importance: Importance.max,
        color: Color.fromARGB(255, 255, 0, 0),
      );
      var iosDetails = IOSNotificationDetails(
        presentAlert: true,
        presentBadge: true,
        presentSound: true,
      );
      // 알림 id, 제목, 내용 맘대로 채우기
      notifications.show(1, '제목1', '내용1',
          NotificationDetails(android: androidDetails, iOS: iosDetails));
    }
    showNotification2() async {
      tz.initializeTimeZones(); //얘 써야 시간관련 함수 끌수있음
      var androidDetails = const AndroidNotificationDetails(
        '유니크한 알림 ID',
        '알림종류 설명',
        priority: Priority.high,
        importance: Importance.max,
        color: Color.fromARGB(255, 255, 0, 0),
      );
      var iosDetails = const IOSNotificationDetails(
        presentAlert: true,
        presentBadge: true,
        presentSound: true,
      );
      notifications.zonedSchedule(2, '제목2', '내용2', makeDate(8, 30, 0),
          NotificationDetails(android: androidDetails, iOS: iosDetails),
          androidAllowWhileIdle: true,
          uiLocalNotificationDateInterpretation:
              UILocalNotificationDateInterpretation.absoluteTime,
          matchDateTimeComponents: DateTimeComponents.time);
    }
    makeDate(hour, min, sec) {
      var now = tz.TZDateTime.now(tz.local);
      var when =
          tz.TZDateTime(tz.local, now.year, now.month, now.day, hour, min, sec);
      if (when.isBefore(now)) {
        return when.add(Duration(days: 1));
      } else {
        return when;
      }
    }
    
    #44271

    codingapple
    키 마스터
    app_icon 파일도 이름맞게 잘넣어뒀나요
4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠