i am working on a store application and after the user places an order, i will like to store that order details in the firebase firestore. the function for carrying out that call after the button is pressed is this
addOrderDetails() {
final user = Provider.of<UserProvider>(context, listen: false);
writeOrderDetailsForUser({
"userId" : user.user.uid,
"description" : "Cash on delivery",
"status" : "pending",
"createdAt": DateTime.now().millisecondsSinceEpoch.toString(),
"totalPrice" : user.userModel.totalCartPrice,
"cart" : user.userModel.cart,
"address" : widget.addressId,
"phone" : user.userModel.phone,
}).whenComplete(() async {
for (CartItemModel cartItem in user.userModel.cart){
bool value = await user.removeFromCart(cartItem: cartItem);
if(value) {
user.reloadUserModel();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Item has been successfully removed from cart"),));
}else {
print(
"item has not been removed from cart please try again"
);
}
}
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"Your order has been successfully created, please we will call you in a few minutes to confirm your order"),));
});
changeScreenReplacement(context, NavigationController());
}
Future writeOrderDetailsForUser(Map<String, dynamic> data) async
{
await EcommerceApp.firestore
.collection(EcommerceApp.collectionOrders)
.document(EcommerceApp.sharedPreferences.getString(EcommerceApp.userUID) + data['createdAt'])
.setData(data);
}
}
However i am getting this error anytime i make the function call
I/flutter (24853): cart items are: Instance of 'CartItemModel'
E/flutter (24853): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Invalid argument: Instance of 'CartItemModel'
E/flutter (24853): #0 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:419:7)
E/flutter (24853): #1 FirestoreMessageCodec.writeValue (package:cloud_firestore_platform_interface/src/method_channel/utils/firestore_message_codec.dart:83:13)
E/flutter (24853): #2 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:409:9)
E/flutter (24853): #3 FirestoreMessageCodec.writeValue (package:cloud_firestore_platform_interface/src/method_channel/utils/firestore_message_codec.dart:83:13)
E/flutter (24853): #4 StandardMessageCodec.writeValue. (package:flutter/src/services/message_codecs.dart:416:9)
E/flutter (24853): #5 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:397:8)
E/flutter (24853): #6 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:414:13)
E/flutter (24853): #7 FirestoreMessageCodec.writeValue (package:cloud_firestore_platform_interface/src/method_channel/utils/firestore_message_codec.dart:83:13)
E/flutter (24853): #8 StandardMessageCodec.writeValue. (package:flutter/src/services/message_codecs.dart:416:9)
E/flutter (24853): #9 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:397:8)
E/flutter (24853): #10 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:414:13)
E/flutter (24853): #11 FirestoreMessageCodec.writeValue (package:cloud_firestore_platform_interface/src/method_channel/utils/firestore_message_codec.dart:83:13)
E/flutter (24853): #12 StandardMethodCodec.encodeMethodCall (package:flutter/src/services/message_codecs.dart:551:18)
E/flutter (24853): #13 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:150:13)
E/flutter (24853): #14 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:331:12)
E/flutter (24853): #15 MethodChannelDocumentReference.setData (package:cloud_firestore_platform_interface/src/method_channel/method_channel_document_reference.dart:28:43)
E/flutter (24853): #16 DocumentReference.setData (package:cloud_firestore/src/document_reference.dart:48:22)
E/flutter (24853): #17 _PaymentPageState.writeOrderDetailsForUser (package:maen/screens/placeOrderPayment.dart:349:10)
E/flutter (24853): #18 _PaymentPageState.addOrderDetails (package:maen/screens/placeOrderPayment.dart:316:5)
E/flutter (24853): #19 _PaymentPageState.build. (package:maen/screens/placeOrderPayment.dart:297:17)
The problem is caused because of this line
"cart" : user.userModel.cart,
Seems like your user.userModel.cart is the List of CartItemModel,
To overcome this you'll have to serialize this and then add to the database, because database doesn't know anything about CartItemModel,
Do something like this:
"cart" : user.userModel.cart.map((e)=>e.toJson()).toList();
In CartItemModel define the toJson function
As the details is less, I assume CartItemModel has fields like id , name and price
Map toJson() => {
'id': id,
'name': name,
'price' : price
};
This should solve your problem
Related
I want to extract data from Firebase Realtime database and convert it to a model. But I am getting this error. I couldn't understand where I went wrong. How can I do it?
firebase_db_services.dart:
final databaseReference = FirebaseDatabase.instance.reference();
Future<List<Folder>> fetchFolders(String userID) async{
var snapshot =await databaseReference.child("users").child(userID).child("folders").once();
var result = await snapshot.value.values as Iterable;
List<Folder> folderList = List();
for(var item in result) {
folderList.add(Folder.fromMap(item));
}
return folderList;
}
folder_model.dart:
Folder.fromMap(Map<dynamic, dynamic> map) {
this.folderName = map['folder_name'];
this.folderColor = Color(map["folder_color"]);
this.folderCreateDate = DateTime.parse(map['folder_create_date'].toString());
this.accounts = List<Account>.from(map["accounts"].map((x) => Account.fromMap(x)));
}
account_model.dart:
Account.fromMap(Map<dynamic, dynamic> map) {
this.accountName = map['account_name'];
this.accountEmail = map['account_mail'];
this.accountPassword = map['account_password'].toString();
this.accountCreateTime = DateTime.parse(map['account_createTime']);
this.favorite = map["favorite"];
}
incoming data:
{sosya_medya: {folder_create_date: 2020-12-04 19:08:46.066142, accounts: {account_password: account_password, account_mail: account_mail, account_name: account_name, account_createTime: 2020-12-04 19:08:46.066142, favorite: false}, folder_color: 4294198070, folder_name: sosyal_medya}}
Error:
E/flutter (32674): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: type '(dynamic) => Account' is not a subtype of type '(dynamic, dynamic) => MapEntry<dynamic, dynamic>' of 'transform'
E/flutter (32674): #0 new Folder.fromMap (package:flutter_save_password/models/folder_model.dart:30:56)
E/flutter (32674): #1 FirestoreDBService.fetchFolders (package:flutter_save_password/services/storage/firebase_db_services.dart:56:29)
E/flutter (32674): <asynchronous suspension>
E/flutter (32674): #2 UserRepository.fetchFolders (package:flutter_save_password/services/repository/user_repository.dart:86:40)
E/flutter (32674): #3 PasswordSaveViewModel.fetchFolders (package:flutter_save_password/view_model/save_password_view_model.dart:59:37)
E/flutter (32674): #4 HomePage.build.<anonymous closure> (package:flutter_save_password/app/pages/home_page.dart:32:18)
E/flutter (32674): #5 Consumer.buildWithChild (package:provider/src/consumer.dart:175:19)
E/flutter (32674): #6 SingleChildStatelessWidget.build (package:nested/nested.dart:260:41)
E/flutter (32674): #7 StatelessElement.build (package:flutter/src/widgets/framework.dart:4701:28)
E/flutter (32674): #8 SingleChildStatelessElement.build (package:nested/nested.dart:280:18)
E/flutter (32674): #9 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4627:15)
E/flutter (32674): #10 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (32674): #11 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
E/flutter (32674): #12 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter (32674): #13 SingleChildWidgetElementMixin.mount (package:nested/nested.dart:223:11)
E/flutter (32674): #14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (32674): #15 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (32674): #16 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (32674): #17 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (32674): #18 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
E/flutter (32674): #19 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter (32674): #20 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (32674): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter (32674): #22 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (32674): #23 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
Edit:
I solved it this way:
if(map["accounts"]!= null){
var mapList = List<Map<dynamic, dynamic>>.from(map["accounts"].values);
for(var currentMap in mapList ){
accounts.add(Account.fromMap(currentMap));
}
}
First, I think the problem as read from the error here is that from this line:
this.accounts = List.from(map["accounts"].map((x) => Account.fromMap(x)));
map["accounts"] is a Map and not a List of Account, this is the reason for this error.
Map<dynamic,dynamic>.map((K,V)=>...)
List<dynamic>.map((x)=>...)
Note here that the map function on Map splits all the key-value pairs so from your code, accounts should be a List of maps where each map contains data for an Account.
I have a query function for data from the database that comes with the id number from the database, then the id is saved in shared_preferences in case the new id that comes from the database is larger than the old id that was in the shared_preferences previously.But after running the code, the following problem comes:
E/flutter (30884): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: Class 'String' has no instance method '<'.
E/flutter (30884): Receiver: ""
E/flutter (30884): Tried calling: <(7)
E/flutter (30884): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (30884): #1 AddCommentsState.getLogin.<anonymous closure> (package:flutter_apptestqeuriy/AddComment.dart:84:46)
E/flutter (30884): #2 State.setState (package:flutter/src/widgets/framework.dart:1240:30)
E/flutter (30884): #3 AddCommentsState.getLogin (package:flutter_apptestqeuriy/AddComment.dart:78:5)
E/flutter (30884): <asynchronous suspension>
E/flutter (30884): #4 AddCommentsState.initState.<anonymous closure> (package:flutter_apptestqeuriy/AddComment.dart:57:9)
E/flutter (30884): #5 interval.function (package:flutter_apptestqeuriy/AddComment.dart:21:9)
E/flutter (30884): #6 _rootRun (dart:async/zone.dart:1182:47)
E/flutter (30884): #7 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (30884): #8 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (30884): #9 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter (30884): #10 _rootRun (dart:async/zone.dart:1190:13)
E/flutter (30884): #11 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (30884): #12 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
E/flutter (30884): #13 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (30884): #14 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter (30884): #15 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter (30884): #16 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (30884):
This is the code used to query from the database:
var user_id;
var my_pre_id;
Future<String> getLogin() async {
var response = await http.get(Uri.encodeFull("http://xxxxxxxxxxx/Application.php"),);
setState(() {
var convertDataToJson = json.decode(response.body);
data = convertDataToJson['result'];
if (data != null) {
user_id = int.parse(data[0]['id']);
my_pre_id = _myPreferences.id;
if (my_pre_id == null || my_pre_id < user_id ){
_myPreferences.id = user_id;
_myPreferences.commit();
// print("tappeeeeedddd $my_pre_id");
}
}
});
}
Does anyone know the cause of the problem?
I think the issue comes from my_pre_id < user_id where my_pre_id is actually a String. You might want to do an int.parse() on it as well or change its type in the class.
Now I'm trying to change DB Shared Pref to SqlLite and I'm testing SqlLite DB.
TodoList Info will stored in SqlLite DB.
So, the model of Todo List is as below.
class TodoModel {
int dateTime;
String todo;
int isDone;
todoModelMap() {
var mapping = Map<String, dynamic>();
mapping['dateTime'] = this.dateTime;
mapping['todo'] = this.todo;
mapping['isDone'] = this.isDone;
return mapping;
}
}
The problem is I tried to store model in todoList Provider File but compiler calls error dateTime is null
addTodoList(DateTime dateTime, TextEditingController eventController) async {
if(eventController.text.isEmpty) { return; }
else {
if (events[dateTime] != null) {
----------------------------------------------------
todoModel.dateTime = dateTime.millisecondsSinceEpoch;
// I used milisecondsSinceEpoch to save DateTime as int.
todoModel.todo = eventController.text;
todoModel.isDone = 0;
var result = await todoService.saveTodo(todoModel);
print(result);
---------------------------------------------------
events[dateTime].add(toMap(eventController));
} else {
events[dateTime] = [toMap(eventController)];
}
eventController.clear();
save();
eventController.clear();
notifyListeners();
}
}
I cannot find why dateTime is null because over here the dateTime as int printed well..
onPressed: (){
print(controller.selectedDay.millisecondsSinceEpoch);
todoListHandler.addTodoList(controller.selectedDay, eventController);
Navigator.pop(context);
},
)
++ I want to know solution of this error
W/System.err(16005): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.ClipData.getItemCount()' on a null object reference
this error occur when the raisedButton is onPressed.
but there is no problem to store data
// Here is my full error code
W/System.err(16005): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.ClipData.getItemCount()' on a null object reference
W/System.err(16005): at android.os.Parcel.readException(Parcel.java:1626)
W/System.err(16005): at android.os.Parcel.readException(Parcel.java:1573)
W/System.err(16005): at android.content.IClipboard$Stub$Proxy.getPrimaryClip(IClipboard.java:197)
W/System.err(16005): at android.content.ClipboardManager.getPrimaryClip(ClipboardManager.java:247)
W/System.err(16005): at io.flutter.plugin.platform.PlatformPlugin.getClipboardData(PlatformPlugin.java:274)
W/System.err(16005): at io.flutter.plugin.platform.PlatformPlugin.access$700(PlatformPlugin.java:24)
W/System.err(16005): at io.flutter.plugin.platform.PlatformPlugin$1.getClipboardData(PlatformPlugin.java:81)
W/System.err(16005): at io.flutter.embedding.engine.systemchannels.PlatformChannel$1.onMethodCall(PlatformChannel.java:141)
W/System.err(16005): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230)
W/System.err(16005): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
W/System.err(16005): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
W/System.err(16005): at android.os.MessageQueue.nativePollOnce(Native Method)
W/System.err(16005): at android.os.MessageQueue.next(MessageQueue.java:323)
W/System.err(16005): at android.os.Looper.loop(Looper.java:143)
W/System.err(16005): at android.app.ActivityThread.main(ActivityThread.java:7225)
W/System.err(16005): at java.lang.reflect.Method.invoke(Native Method)
W/System.err(16005): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
W/System.err(16005): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
D/ViewRootImpl(16005): ViewPostImeInputStage processPointer 0
D/ViewRootImpl(16005): ViewPostImeInputStage processPointer 1
I/flutter (16005): 1601380800000
E/flutter (16005): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The setter 'dateTime=' was called on null.
E/flutter (16005): Receiver: null
E/flutter (16005): Tried calling: dateTime=1601380800000
E/flutter (16005): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (16005): #1 TodoListHandler.addTodoList (package:take_a_note_project/todoList/todoList_handler.dart:57:19)
E/flutter (16005): #2 _TodoListState._showAddDialog.<anonymous closure>.<anonymous closure> (package:take_a_note_project/todoList/todoList.dart:134:33)
E/flutter (16005): #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19)
E/flutter (16005): #4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1098:38)
E/flutter (16005): #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
E/flutter (16005): #6 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11)
E/flutter (16005): #7 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
E/flutter (16005): #8 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:219:7)
E/flutter (16005): #9 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:477:9)
E/flutter (16005): #10 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:78:12)
E/flutter (16005): #11 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:124:9)
E/flutter (16005): #12 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter (16005): #13 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:122:18)
E/flutter (16005): #14 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:108:7)
E/flutter (16005): #15 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:220:19)
E/flutter (16005): #16 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
E/flutter (16005): #17 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7)
E/flutter (16005): #18 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7)
E/flutter (16005): #19 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7)
E/flutter (16005): #20 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (16005): #21 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (16005): #22 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (16005): #23 _invoke1 (dart:ui/hooks.dart:267:10)
E/flutter (16005): #24 _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5)
You have to make the object of TodoModel first because without creating of object it is null and then also you are trying to assign it.
then you can give the value of it.
TodoModel _todoModel=new TodoModel();
_todoModel.dateTime = dateTime.millisecondsSinceEpoch;
_todoModel.todo = eventController.text;
_todoModel.isDone = 0;
var result = await todoService.saveTodo(_todoModel);
For your second error of java.lang.NullPointerException you can refer this https://github.com/flutter/flutter/issues/24757
While trying to show the notifications from flutter_local_notification it throws the following error:
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): Failed to handle method call
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): 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(10962): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:188)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:146)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:688)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:827)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:750)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at android.app.ActivityThread.main(ActivityThread.java:6494)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/MethodChannel#dexterous.com/flutter/local_notifications(10962): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/flutter (10962): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null)
E/flutter (10962): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter (10962): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter (10962): <asynchronous suspension>
E/flutter (10962): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
E/flutter (10962): #3 AndroidFlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:137:21)
E/flutter (10962): #4 FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:136:13)
E/flutter (10962): #5 NotificationPlugin.showNotification (package:pig_salang/models/notification_plugin.dart:94:43)
E/flutter (10962): #6 WelcomeScreen.build.<anonymous closure> (package:pig_salang/screens/welcome_screen.dart:42:36)
E/flutter (10962): #7 WelcomeScreen.build.<anonymous closure> (package:pig_salang/screens/welcome_screen.dart:41:26)
E/flutter (10962): #8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19)
E/flutter (10962): #9 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:862:36)
E/flutter (10962): #10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (10962): #11 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11)
E/flutter (10962): #12 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5)
E/flutter (10962): #13 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:217:7)
E/flutter (10962): #14 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9)
E/flutter (10962): #15 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter (10962): #16 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter (10962): #17 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter (10962): #18 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter (10962): #19 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter (10962): #20 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter (10962): #21 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (10962): #22 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (10962): #23 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (10962): #24 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (10962): #25 _rootRunUnary (dart:async/zone.dart:1196:13)
E/flutter (10962): #26 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (10962): #27 _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter (10962): #28 _invoke1 (dart:ui/hooks.dart:275:10)
E/flutter (10962): #29 _dispatchPointerDataPacket (dart:ui/hooks.dart:184:5)
E/flutter (10962):
As far as I have researched, the similar errors were shown because of the icon. I have added used every possible way to add icons, but it is not throwing the error constantly. Obviously, I rerun the app after each changes, to make sure I don't get the error.
My code looks like:
initializePlatformSpecifics() {
var initializeAndroidSettings = AndroidInitializationSettings('app_icon'); <--- Here
var initializeIOSSettings = IOSInitializationSettings(
requestAlertPermission: false,
requestBadgePermission: true,
requestSoundPermission: true,
onDidReceiveLocalNotification: (id, title, body, payload) async {
ReceivedNotification receivedNotification = ReceivedNotification(
id: id, title: title, body: body, payload: payload);
didReceivedLocalNotificationSubject.add(receivedNotification);
},
);
initializeSettings = InitializationSettings(
initializeAndroidSettings, initializeIOSSettings);
}
I followed the tutorial. The thing is when I try to show the notification, it shows the above traceback.
I made notification icons in Android Studio -> app -> main -> res -> Image Asssets -> Notifications icon, then I made icon with name app_icon which I used to intialize the notification.
As it was not working, I also tried :
var initializeAndroidSettings = AndroidInitializationSettings('#mipmap/ic_launcher');
It also did not work. Any help would be appreciated!!!
'app_icon' was given for reference and it actually depends on where you image file is located, if you are using the default icon in mipmap folder named as ic_launcher for now then try the below code. Do let me know if it helps.
var initializeAndroidSettings
=AndroidInitializationSettings('mipmap/ic_launcher');
I am not getting output on my app and it should have give a output like many question is how to sisplay json data in my flutter app
class AppState extends State<AppName>{
var name ;
var email ;
int cgpa ;
TextEditingController user = new TextEditingController();
String url = 'http://10.42.0.243:8000/students/';
getData(String username) async{
String profile = url+'?search='+username;
var res = await http.get(profile,headers: {"Accept":"application/json"});
print(res.body);
debugPrint(res.body);
var resBody = json.decode(res.body);
name = resBody['sname'].toString();
email = resBody['email'].toString();
cgpa = resBody['cgpa'] ;
debugPrint(name);
setState(() {
print("Success");
});
}
my app screenshot is
JSON Data Screenshot
Error output:
Performing hot reload...
Syncing files to device Moto G 5 Plus...
Reloaded 0 of 576 libraries in 389ms.
E/BpSurfaceComposerClient(28411): Failed to transact (-1)
E/BpSurfaceComposerClient(28411): Failed to transact (-1)
I/flutter (28411): [{"id":1,"sname":"Ashutosh Lokhande","email":"2016bit053#sggs.ac.in","year":"2016","cgpa":7.2}]
I/flutter (28411): [{"id":1,"sname":"Ashutosh Lokhande","email":"2016bit053#sggs.ac.in","year":"2016","cgpa":7.2}]
E/flutter (28411): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
E/flutter (28411): #0 AppState.getData (package:json_flutter/main.dart:28:19)
E/flutter (28411):
E/flutter (28411): #1 AppState.build. (package:json_flutter/main.dart:56:34)
E/flutter (28411): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
E/flutter (28411): #3 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:729:32)
E/flutter (28411): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (28411): #5 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter (28411): #6 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
E/flutter (28411): #7 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)
E/flutter (28411): #8 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
E/flutter (28411): #9 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
E/flutter (28411): #10 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter (28411): #11 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (28411): #12 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (28411): #13 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (28411): #14 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (28411): #15 _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter (28411): #16 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (28411): #17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (28411): #18 _invoke1 (dart:ui/hooks.dart:263:10)
E/flutter (28411): #19 _dispatchPointerDataPacket (dart:ui/hooks.dart:172:5)
E/flutter (28411):