Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set id as a string #304

Closed
MirzayevFarid opened this issue Sep 1, 2019 · 5 comments
Closed

set id as a string #304

MirzayevFarid opened this issue Sep 1, 2019 · 5 comments

Comments

@MirzayevFarid
Copy link

I am developing a to-do list program. I want to set alarm id as the id of task from Firestore. Task id in Firestore is string with the mix of nums and letters. I tried to set id as a string but I got error in below:

E/MethodChannel#dexterous.com/flutter/local_notifications(32579): Failed to handle method call
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at com.dexterous.flutterlocalnotifications.models.NotificationDetails.from(NotificationDetails.java:152)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.extractNotificationDetails(FlutterLocalNotificationsPlugin.java:727)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.schedule(FlutterLocalNotificationsPlugin.java:680)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:624)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:643)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at android.app.ActivityThread.main(ActivityThread.java:6944)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
E/MethodChannel#dexterous.com/flutter/local_notifications(32579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
E/flutter (32579): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, java.lang.String cannot be cast to java.lang.Integer, null)
E/flutter (32579): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter (32579): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33)
E/flutter (32579):
E/flutter (32579): #2 FlutterLocalNotificationsPlugin.schedule (package:flutter_local_notifications/src/flutter_local_notifications.dart:149:20)
E/flutter (32579):
E/flutter (32579): #3 _newTaskState._scheduleNotification (package:done/screens/newTask.dart:233:43)
E/flutter (32579):
E/flutter (32579): #4 _newTaskState.build.. (package:done/screens/newTask.dart:169:25)
E/flutter (32579): #5 _rootRun (dart:async/zone.dart:1120:38)
E/flutter (32579): #6 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (32579): #7 _FutureListener.handleWhenComplete (dart:async/future_impl.dart:150:18)
E/flutter (32579): #8 Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:609:39)
E/flutter (32579): #9 Future._propagateToListeners (dart:async/future_impl.dart:665:37)
E/flutter (32579): #10 Future._complete (dart:async/future_impl.dart:473:7)
E/flutter (32579): #11 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
E/flutter (32579): #12 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:28:18)
E/flutter (32579): #13 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:294:13)
E/flutter (32579): #14 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart)
E/flutter (32579):
E/flutter (32579): #15 DocumentReference.setData (package:cloud_firestore/src/document_reference.dart:51:30)
E/flutter (32579): #16 _newTaskState.build. (package:done/screens/newTask.dart:165:28)
E/flutter (32579): #17 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14)
E/flutter (32579): #18 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:711:32)
E/flutter (32579): #19 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (32579): #20 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter (32579): #21 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:312:7)
E/flutter (32579): #22 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (32579): #23 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
E/flutter (32579): #24 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (32579): #25 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (32579): #26 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (32579): #27 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (32579): #28 _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter (32579): #29 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (32579): #30 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (32579): #31 _invoke1 (dart:ui/hooks.dart:250:10)
E/flutter (32579): #32 _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5)
E/flutter (32579):
V/InputMethodManager(32579): Starting input: tba=android.view.inputmethod.EditorInfo@d0a81cd nm : faridmirzayev.com.done ic=null
I/InputMethodManager(32579): startInputInner - mService.startInputOrWindowGainedFocus
D/SurfaceView(32579): BG show() Surface(name=Background for - SurfaceView - faridmirzayev.com.done/faridmirzayev.com.done.MainActivity@b8781f7@0) io.flutter.view.FlutterView{b8781f7 VFE...... .F....I. 0,0-1080,1920}
D/SurfaceView(32579): surfaceDestroyed 1 io.flutter.view.FlutterView{b8781f7 VFE...... .F....I. 0,0-1080,1920}
I/zygote64(32579): Do partial code cache collection, code=248KB, data=163KB
I/zygote64(32579): After code cache collection, code=248KB, data=163KB
I/zygote64(32579): Increasing code cache capacity to 1024KB

@MaikuB
Copy link
Owner

MaikuB commented Sep 1, 2019

Not sure how you've bypassed the type checking on the Dart side but that's happening as only integer ids are supported. You'll need to implement your own logic to create the integer IDs

@MirzayevFarid
Copy link
Author

I also get error when I run program on iOS

*** First throw call stack:
(
0 CoreFoundation 0x0000000114a988db __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000011403bac5 objc_exception_throw + 48
2 CoreFoundation 0x0000000114ab6c94 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000114a9d623 forwarding + 1443
4 CoreFoundation 0x0000000114a9f418 _CF_forwarding_prep_0 + 120
5 Runner 0x000000010f36282c -[FlutterLocalNotificationsPlugin showUserNotification:] + 2940
6 Runner 0x000000010f360c45 -[FlutterLocalNotificationsPlugin showNotification:result:] + 4645
7 Runner 0x000000010f36151e -[FlutterLocalNotificationsPlugin handleMetho<…>

@MirzayevFarid
Copy link
Author

MirzayevFarid commented Sep 1, 2019

///// I get id In here as string
Future _scheduleNotification( pickedTime, String task, String category, id) async { print('id:::::::::::::::::::::::::::::::::::::::::::::::::::$id'); var scheduledNotificationDateTime = pickedTime; var vibrationPattern = Int64List(4); vibrationPattern[0] =0;`
vibrationPattern[1] = 1000;
vibrationPattern[2] = 5000;
vibrationPattern[3] = 2000;

var androidPlatformChannelSpecifics = AndroidNotificationDetails(
    'your other channel id',
    'your other channel name',
    'your other channel description',
    icon: 'secondary_icon',
    sound: 'slow_spring_board',
    largeIcon: 'sample_large_icon',
    largeIconBitmapSource: BitmapSource.Drawable,
    vibrationPattern: vibrationPattern,
    enableLights: true,
    color: const Color.fromARGB(255, 255, 0, 0),
    ledColor: const Color.fromARGB(255, 255, 0, 0),
    ledOnMs: 1000,
    ledOffMs: 500);
var iOSPlatformChannelSpecifics =
    IOSNotificationDetails(sound: "slow_spring_board.aiff");
var platformChannelSpecifics = NotificationDetails(
    androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);

///////// In here when I .schedule I enter id
await flutterLocalNotificationsPlugin.schedule(id, category, task,
scheduledNotificationDateTime, platformChannelSpecifics);
}`

@MirzayevFarid
Copy link
Author

Also in flutterLocalNotificationsPlugin.schedule I changed code to this:

Future<void> schedule(String id, String title, String body, DateTime scheduledDate, NotificationDetails notificationDetails, {String payload, bool androidAllowWhileIdle = false}) async { var serializedPlatformSpecifics = _retrievePlatformSpecificNotificationDetails(notificationDetails); if (_platform.isAndroid) { serializedPlatformSpecifics['allowWhileIdle'] = androidAllowWhileIdle; } await _channel.invokeMethod('schedule', <String, dynamic>{ 'id': id, 'title': title, 'body': body, 'millisecondsSinceEpoch': scheduledDate.millisecondsSinceEpoch, 'platformSpecifics': serializedPlatformSpecifics, 'payload': payload ?? '' }); }

@MaikuB
Copy link
Owner

MaikuB commented Sep 1, 2019

As stated previously, the plugin only supports integer IDs. If you're making modifications to the plugin then that's up to you to maintain and fix

@MaikuB MaikuB closed this as completed Sep 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants