i am trying to display the image that I am getting as a response from API.
below is the code for displaying the image -:
String ProfilePic;
CircleAvatar(
radius: 80,
backgroundImage:
ProfilePic != null ?
NetworkImage('$ProfilePic'):
// AssetImage('$ProfilePic') :
AssetImage('assets/favicon.png'),
),
As a response, I am getting this data from API -: I/flutter ( 4230): pexels-lisa-1107717.jpg
and when I use it I get following error -:
======== Exception caught by image resource service ================================================
The following ArgumentError was thrown resolving an image codec:
Invalid argument(s): No host specified in URI file:///null
When the exception was thrown, this was the stack:
#0 _HttpClient._openUrl (dart:_http/http_impl.dart:2662:9)
#1 _HttpClient.getUrl (dart:_http/http_impl.dart:2573:48)
#2 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:89:59)
#3 NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:50:14)
#4 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:505:13)
#5 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:380:22)
#6 ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:503:83)
#7 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:333:9)
#8 ImageProvider._createErrorHandlerAndKey.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:464:26)
#9 SynchronousFuture.then (package:flutter/src/foundation/synchronous_future.dart:41:35)
#10 ImageProvider._createErrorHandlerAndKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:461:11)
#14 ImageProvider._createErrorHandlerAndKey (package:flutter/src/painting/image_provider.dart:453:16)
#15 ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:330:5)
#16 DecorationImagePainter.paint (package:flutter/src/painting/decoration_image.dart:258:55)
#17 _BoxDecorationPainter._paintBackgroundImage (package:flutter/src/painting/box_decoration.dart:465:20)
#18 _BoxDecorationPainter.paint (package:flutter/src/painting/box_decoration.dart:483:5)
#19 RenderDecoratedBox.paint (package:flutter/src/rendering/proxy_box.dart:2162:17)
#20 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2409:7)
#21 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:189:13)
#22 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#23 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2409:7)
#24 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:189:13)
#25 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2794:15)
#26 RenderStack.paintStack (package:flutter/src/rendering/stack.dart:629:5)
#27 RenderStack.paint (package:flutter/src/rendering/stack.dart:645:7)
#28 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2409:7)
#29 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:189:13)
#30 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#31 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2409:7)
#32 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:189:13)
#33 RenderShiftedBox.paint (package:flutter/src/rendering/shifted_box.dart:79:15)
#34 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2409:7)
#35 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:189:13)
#36 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2794:15)
#37 RenderFlex.paint (package:flutter/src/rendering/flex.dart:1078:7)
#38 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2409:7)
#39 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:189:13)
#40 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2794:15)
#41 RenderFlex.paint (package:flutter/src/rendering/flex.dart:1078:7)
#42 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2409:7)
#43 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:189:13)
#44 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#45 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2409:7)
#46 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:189:13)
#47 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2794:15)
#48 RenderFlex.paint (package:flutter/src/rendering/flex.dart:1078:7)
#49 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2409:7)
#50 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:189:13)
#51 _RenderSingleChildViewport.paint.paintContents (package:flutter/src/widgets/single_child_scroll_view.dart:619:17)
#52 PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:398:12)
#53 PaintingContext.pushClipRect (package:flutter/src/rendering/object.dart:454:7)
#54 _RenderSingleChildViewport.paint (package:flutter/src/widgets/single_child_scroll_view.dart:623:40)
#55 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2409:7)
#56 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#57 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#58 PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:979:29)
#59 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:455:19)
#60 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:13)
#61 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
#62 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)
#63 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)
#64 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#68 _invoke (dart:ui/hooks.dart:166:10)
#69 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#70 _drawFrame (dart:ui/hooks.dart:129:31)
(elided 6 frames from dart:async)
Image provider: NetworkImage("null", scale: 1.0)
Image key: NetworkImage("null", scale: 1.0)
====================================================================================================
i have used network image but still, I am not able to display the image. i have tried other solutions too but nothing seems to work.
can anyone help me with displaying this?
Your check is wrong it should be this way
ProfilePic != null ? NetworkImage('$ProfilePic'):AssetImage('assets/favicon.png'),
Related
I am trying to retrieve some information along with images from my backend in my flutter app. The backend is with spring boot and I am getting this error Connection refused (OS Error: Connection refused, errno = 111), address = localhost, port = 56766. The backend is hosted locally.
This error is mainly from the image because if I remove the image from my DataModel class, other information is returned successfully without the error.
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:vacation_tour_app/model/data_model.dart';
class DataServices{
String baseUrl = 'http://192.168.43.5:8080/';
Future<List<DataModel>>getInfo() async {
var apiUrl = 'tourist/getAll';
http.Response res = await http.get(Uri.parse(baseUrl+apiUrl));
try{
if(res.statusCode==200){
List<dynamic> list = json.decode(res.body);
return list.map((e) => DataModel.fromJson(e)).toList();
}else{
return <DataModel>[];
}
}catch(e){
print(e);
return <DataModel>[];
}
}
}
class DataModel{
String name;
String description;
String image;
int price;
int people;
int stars;
String location;
DataModel({
required this.price,
required this.name,
required this.description,
required this.image,
required this.location,
required this.people,
required this.stars
});
factory DataModel.fromJson(Map<String,dynamic>json){
return DataModel(
price: json["price"],
name: json["name"],
description: json["description"],
image: json["image"],
location: json["location"],
people: json["people"],
stars: json["stars"]);
}
}
error from the logcat
======== Exception caught by image resource service ================================================
The following SocketException was thrown resolving an image codec:
Connection refused (OS Error: Connection refused, errno = 111), address = localhost, port = 56884
When the exception was thrown, this was the stack:
#0 _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:682:35)
#1 _RawSocket.startConnect (dart:io-patch/socket_patch.dart:1817:26)
#2 RawSocket.startConnect (dart:io-patch/socket_patch.dart:27:23)
#3 Socket._startConnect (dart:io-patch/socket_patch.dart:2038:22)
#4 Socket.startConnect (dart:io/socket.dart:792:21)
#5 _ConnectionTarget.connect (dart:_http/http_impl.dart:2440:18)
#6 _HttpClient._getConnection.connect (dart:_http/http_impl.dart:2834:12)
#7 _HttpClient._getConnection (dart:_http/http_impl.dart:2839:12)
#8 _HttpClient._openUrl (dart:_http/http_impl.dart:2698:12)
#9 _HttpClient.getUrl (dart:_http/http_impl.dart:2575:48)
#10 NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:87:59)
#11 NetworkImage.load (package:flutter/src/painting/_network_image_io.dart:50:14)
#12 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:505:13)
#13 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:380:22)
#14 ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:503:83)
#15 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:333:9)
#16 ImageProvider._createErrorHandlerAndKey.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:464:26)
#17 SynchronousFuture.then (package:flutter/src/foundation/synchronous_future.dart:41:35)
#18 ImageProvider._createErrorHandlerAndKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:461:11)
#22 ImageProvider._createErrorHandlerAndKey (package:flutter/src/painting/image_provider.dart:453:16)
#23 ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:330:5)
#24 DecorationImagePainter.paint (package:flutter/src/painting/decoration_image.dart:316:55)
#25 _BoxDecorationPainter._paintBackgroundImage (package:flutter/src/painting/box_decoration.dart:465:20)
#26 _BoxDecorationPainter.paint (package:flutter/src/painting/box_decoration.dart:483:5)
#27 RenderDecoratedBox.paint (package:flutter/src/rendering/proxy_box.dart:2150:17)
#28 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#29 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#30 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#31 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#32 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#33 RenderShiftedBox.paint (package:flutter/src/rendering/shifted_box.dart:79:15)
#34 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#35 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#36 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#37 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#38 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#39 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#40 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#41 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#42 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#43 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#44 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#45 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#46 PaintingContext._compositeChild (package:flutter/src/rendering/object.dart:198:7)
#47 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:185:7)
#48 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#49 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#50 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#51 RenderSliverMultiBoxAdaptor.paint (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:647:17)
#52 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#53 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#54 RenderSliverEdgeInsetsPadding.paint (package:flutter/src/rendering/sliver_padding.dart:274:15)
#55 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#56 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#57 RenderViewportBase._paintContents (package:flutter/src/rendering/viewport.dart:660:17)
#58 PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:387:12)
#59 PaintingContext.pushClipRect (package:flutter/src/rendering/object.dart:443:7)
#60 RenderViewportBase.paint (package:flutter/src/rendering/viewport.dart:635:38)
#61 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#62 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#63 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#64 PaintingContext._compositeChild (package:flutter/src/rendering/object.dart:198:7)
#65 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:185:7)
#66 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#67 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#68 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#69 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#70 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#71 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#72 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#73 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#74 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#75 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#76 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#77 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#78 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#79 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#80 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#81 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#82 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#83 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#84 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#85 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#86 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#87 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#88 PaintingContext._compositeChild (package:flutter/src/rendering/object.dart:198:7)
#89 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:185:7)
#90 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#91 RenderCustomPaint.paint (package:flutter/src/rendering/custom_paint.dart:608:11)
#92 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#93 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#94 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#95 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#96 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#97 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#98 PaintingContext._compositeChild (package:flutter/src/rendering/object.dart:198:7)
#99 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:185:7)
#100 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#101 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#102 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#103 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#104 PaintingContext._compositeChild (package:flutter/src/rendering/object.dart:198:7)
#105 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:185:7)
#106 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#107 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#108 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#109 RenderSliverMultiBoxAdaptor.paint (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:647:17)
#110 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#111 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#112 RenderSliverEdgeInsetsPadding.paint (package:flutter/src/rendering/sliver_padding.dart:274:15)
#113 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#114 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#115 RenderViewportBase._paintContents (package:flutter/src/rendering/viewport.dart:660:17)
#116 PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:387:12)
#117 PaintingContext.pushClipRect (package:flutter/src/rendering/object.dart:443:7)
#118 RenderViewportBase.paint (package:flutter/src/rendering/viewport.dart:635:38)
#119 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#120 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#121 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#122 PaintingContext._compositeChild (package:flutter/src/rendering/object.dart:198:7)
#123 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:185:7)
#124 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#125 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#126 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#127 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#128 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#129 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#130 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#131 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#132 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#133 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#134 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#135 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#136 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#137 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#138 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#139 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#140 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#141 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#142 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#143 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#144 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#145 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#146 PaintingContext._compositeChild (package:flutter/src/rendering/object.dart:198:7)
#147 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:185:7)
#148 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#149 RenderCustomPaint.paint (package:flutter/src/rendering/custom_paint.dart:608:11)
#150 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#151 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#152 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#153 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#154 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#155 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#156 PaintingContext._compositeChild (package:flutter/src/rendering/object.dart:198:7)
#157 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:185:7)
#158 RenderShiftedBox.paint (package:flutter/src/rendering/shifted_box.dart:79:15)
#159 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#160 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#161 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#162 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#163 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#164 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2847:15)
#165 RenderFlex.paint (package:flutter/src/rendering/flex.dart:1078:7)
#166 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#167 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#168 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2847:15)
#169 RenderCustomMultiChildLayoutBox.paint (package:flutter/src/rendering/custom_layout.dart:408:5)
#170 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#171 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#172 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#173 _RenderInkFeatures.paint (package:flutter/src/material/material.dart:555:11)
#174 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#175 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#176 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#177 PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:387:12)
#178 RenderPhysicalModel.paint (package:flutter/src/rendering/proxy_box.dart:1929:15)
#179 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#180 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#181 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2847:15)
#182 RenderCustomMultiChildLayoutBox.paint (package:flutter/src/rendering/custom_layout.dart:408:5)
#183 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#184 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#185 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#186 _RenderInkFeatures.paint (package:flutter/src/material/material.dart:555:11)
#187 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#188 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#189 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#190 PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:387:12)
#191 RenderPhysicalModel.paint (package:flutter/src/rendering/proxy_box.dart:1929:15)
#192 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#193 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#194 RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2847:15)
#195 RenderCustomMultiChildLayoutBox.paint (package:flutter/src/rendering/custom_layout.dart:408:5)
#196 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#197 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#198 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#199 _RenderInkFeatures.paint (package:flutter/src/material/material.dart:555:11)
#200 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#201 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#202 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#203 PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:387:12)
#204 RenderPhysicalModel.paint (package:flutter/src/rendering/proxy_box.dart:1929:15)
#205 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#206 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#207 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#208 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#209 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#210 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#211 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2449:7)
#212 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#213 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#214 PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:995:29)
#215 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:499:19)
#216 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:13)
#217 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:363:5)
#218 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
#219 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1081:9)
#220 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:995:5)
#224 _invoke (dart:ui/hooks.dart:151:10)
#225 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
#226 _drawFrame (dart:ui/hooks.dart:115:31)
(elided 6 frames from dart:async)
Image provider: NetworkImage("http://localhost:8080/download/44021c90-7b33-4262-aa0c-c29cf7fc69b1", scale: 1.0)
Image key: NetworkImage("http://localhost:8080/download/44021c90-7b33-4262-aa0c-c29cf7fc69b1", scale: 1.0)
====================================================================================================
Seems your trouble lies entirely on your connection, have you tried changing the IP address on your code and/or checking if you're using some kind of firewall, proxy, VPN on your computer that may refuse connections?
Would be great if you try those requests on a different environment such as Postman using the same IP address on your Flutter code.
PS: It could be also something as trivial as changing your http scheme to https.
I upgrade my Flutter version from v2.10.4 to v3.3.10 , amount of errors occure like this:
# main(2)
_CastError
Null check operator used on a null value
#0 RenderBox.size (package:flutter/src/rendering/box.dart:2023)
#1 RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:253)
#2 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#3 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#4 ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:56)
#5 RenderFlex._computeSizes (package:flutter/src/rendering/flex.dart:836)
#6 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:938)
#7 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#8 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#9 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#10 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#11 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#12 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#13 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1462)
#14 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#15 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#16 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#17 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1462)
#18 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#19 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#20 RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:292)
#21 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#22 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#23 RenderPositionedBox.performLayout (package:flutter/src/rendering/shifted_box.dart:451)
#24 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#25 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#26 RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:249)
#27 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#28 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#29 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#30 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#31 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#32 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#33 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#34 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#35 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#36 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#37 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#38 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#39 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#40 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#41 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#42 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#43 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#44 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#45 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#46 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#47 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#48 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#49 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#50 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#51 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3737)
#52 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#53 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#54 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120)
#55 RenderObject.layout (package:flutter/src/rendering/object.dart:2135)
#56 RenderBox.layout (package:flutter/src/rendering/box.dart:2418)
#57 _RenderTheatre.performLayout (package:flutter/src/widgets/overlay.dart:804)
#58 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1973)
#59 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:999)
#60 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:513)
#61 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:884)
#62 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:378)
#63 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175)
#64 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1104)
#65 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1015)
#66 _rootRun (dart:async/zone.dart:1391)
#67 _CustomZone.run (dart:async/zone.dart:1293)
#68 _CustomZone.runGuarded (dart:async/zone.dart:1201)
#69 _invoke (dart:ui/hooks.dart:150)
#70 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318)
#71 _drawFrame (dart:ui/hooks.dart:115)
According to the stack, all of them from the flutter framework. I have no idea to find out where causes this error in my code.
I guess it must a wrong stage during widget rendering.
Can you give me some idea?
My pubspec.yaml like this:
environment:
sdk: ">=2.10.0 <3.0.0"
flutter: ^3.3.10
According to the page tracking info, I finally find out this issue:
I use routes#showGeneralDialog to display a widget with wrong width.
So I get the following error whenever I sign in through Google, but I only get it on my first login. If I log out and log back in, it never appears and the app works fine.
======== Exception caught by widgets library =======================================================
The following StateError was thrown building:
Bad state: field does not exist within the DocumentSnapshotPlatform
When the exception was thrown, this was the stack:
#0 DocumentSnapshotPlatform.get._findKeyValueInMap (package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_document_snapshot.dart:87:7)
#1 DocumentSnapshotPlatform.get._findComponent (package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_document_snapshot.dart:105:23)
#2 DocumentSnapshotPlatform.get (package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_document_snapshot.dart:121:12)
#3 _JsonDocumentSnapshot.get (package:cloud_firestore/src/document_snapshot.dart:92:48)
#4 _JsonDocumentSnapshot.[] (package:cloud_firestore/src/document_snapshot.dart:96:40)
#5 _HomeState.chatRoomsList.<anonymous closure>.<anonymous closure> (package:connectlyapp/views/home.dart:58:45)
#6 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:456:22)
#7 SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1214:28)
#8 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1227:55)
#9 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2573:19)
#10 SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1220:12)
#11 RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:349:23)
#12 RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1968:59)
#13 PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:916:15)
#14 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1968:14)
#15 RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:338:5)
#16 RenderSliverMultiBoxAdaptor.addInitialChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:422:5)
#17 RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:79:12)
#18 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#19 RenderSliverEdgeInsetsPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:137:12)
#20 RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:371:11)
#21 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#22 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:510:13)
#23 RenderShrinkWrappingViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1923:12)
#24 RenderShrinkWrappingViewport.performLayout (package:flutter/src/rendering/viewport.dart:1881:20)
#25 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#26 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#27 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#28 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#29 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#30 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#31 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#32 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#33 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#34 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#35 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#36 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#37 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#38 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#39 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#40 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#41 RenderCustomPaint.performLayout (package:flutter/src/rendering/custom_paint.dart:545:11)
#42 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#43 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#44 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#45 ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:56:11)
#46 RenderFlex._computeSizes (package:flutter/src/rendering/flex.dart:829:43)
#47 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:931:32)
#48 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#49 _RenderSingleChildViewport.performLayout (package:flutter/src/widgets/single_child_scroll_view.dart:581:14)
#50 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#51 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#52 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#53 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#54 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#55 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#56 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#57 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#58 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#59 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#60 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#61 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#62 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#63 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#64 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#65 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#66 RenderCustomPaint.performLayout (package:flutter/src/rendering/custom_paint.dart:545:11)
#67 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#68 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#69 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#70 RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:233:12)
#71 RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#72 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:171:12)
#73 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:1097:7)
#74 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:240:7)
#75 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:404:14)
#76 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1713:7)
#77 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:885:18)
#78 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:453:19)
#79 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:13)
#80 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
#81 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)
#82 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)
#83 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#87 _invoke (dart:ui/hooks.dart:166:10)
#88 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#89 _drawFrame (dart:ui/hooks.dart:129:31)
(elided 3 frames from dart:async)
====================================================================================================
This is the code that the error pops up on:
Widget chatRoomsList() {
return StreamBuilder<dynamic>(
stream: chatRoomsStream,
builder: (context, snapshot) {
return snapshot.hasData
? ListView.builder(
itemCount: snapshot.data.docs.length,
shrinkWrap: true,
itemBuilder: (context, index) {
DocumentSnapshot ds = snapshot.data.docs[index];
return ChatRoomListTile(ds["lastMessage"], ds.id, myUserName);
})
: Center(child: CircularProgressIndicator());
},
);
}
What this snippet of code does is fetch chatrooms that the logged in user has interacted with, on the main page. Sort of like a Messenger Home screen. But if a new user logs in (who has no chatrooms or existing chats with any other user), the main screen should show no results.
What am I doing wrong here? I had a similar problem with my search feature on the same app, and I fixed it by putting in return Streambuilder, but here - that doesn't fix the Bad state error.
The main screen works fine if I log out and log back in, it displays the users I chatted with and their previous/last sent messages.
Kindly help me out here.
EDIT: getChatRooms() [where chatRoomsStream is initialized]:
getChatRooms() async {
chatRoomsStream = await DatabaseMethods().getChatRooms();
setState(() {});
}
DatabaseMethods().getChatRooms() [database.dart method]:
Future<Stream<QuerySnapshot>> getChatRooms() async {
String myUsername = await SharedPreferenceHelper().getUserName();
return FirebaseFirestore.instance
.collection("chatrooms")
.where("users", arrayContains: myUsername)
.snapshots();
}
I believe the issue is in this line
return ChatRoomListTile(ds["lastMessage"], ds.id, myUserName);
try changing this line to ds.data()['lastMessage']
return ChatRoomListTile(ds.data()['lastMessage'], ds.id, myUserName);
Code that worked for me
final usersRef = FirebaseFirestore.instance.collection('users');
final userDocs = await usersRef.get();
final docId =
userDocs.docs.where((doc) => doc.data()['uid'] == user.uid).first.id;
Please lemme know in comments if you any issues, will be glad to help you.
You should use doc.data() but once you use it you will get an error saying operator[] isn't defined for the type Object. That's because in recent version of firestore Document is a generic type and you must also give a type along with it example
DocumentSnapshot<Map<String,dynamic>>
if you don't give any type like this - DocumentSnapshot .The type is inferred as an Object type that doesn't suppose to have "[]" operator defined.
Please look at these two answers for more details-
https://stackoverflow.com/a/63501611/6051666
https://stackoverflow.com/a/69447502/6051666
I am tring to install and setup flutter by followig way
1. I downloaded flutter and unzip
2. Added path of flutter and bin folder in environment variable
3. Fire command flutter doctor
Then dart has been downloaded via command line and then i got error
Oops; flutter has exited unexpectedly: "Invalid argument(s): Cannot find executable for where.". Unable to generate crash report due to secondary error: Invalid argument(s): Cannot find executable for where.
please let us know at https://github.com/flutter/flutter/issues. Unhandled exception: ProcessExit: 1 #0 _handleToolError (package:flutter_tools/runner.dart:149:7) #1 _asyncErrorWrapperHelper.errorCallback (dart:async-patch/async_patch.dart:87:64) #2 _rootRunBinary (dart:async/zone.dart:1204:38) #3 _CustomZone.runBinary (dart:async/zone.dart:1093:19) #4 _FutureListener.handleError (dart:async/future_impl.dart:155:20) #5 Future._propagateToListeners.handleError (dart:async/future_impl.dart:694:47) #6 Future._propagateToListeners (dart:async/future_impl.dart:715:24) #7 Future._completeError (dart:async/future_impl.dart:534:5) #8 _AsyncAwaitCompleter.completeError (dart:async-patch/async_patch.dart:43:15) #9 _informUserOfCrash (package:flutter_tools/runner.dart) #10 _asyncErrorWrapperHelper.errorCallback (dart:async-patch/async_patch.dart:87:64) #11 _rootRunBinary (dart:async/zone.dart:1204:38) #12 _CustomZone.runBinary (dart:async/zone.dart:1093:19) #13 _FutureListener.handleError (dart:async/future_impl.dart:155:20) #14 Future._propagateToListeners.handleError (dart:async/future_impl.dart:694:47) #15 Future._propagateToListeners (dart:async/future_impl.dart:715:24) #16 Future._completeError (dart:async/future_impl.dart:534:5) #17 _AsyncAwaitCompleter.completeError (dart:async-patch/async_patch.dart:43:15) #18 _doctorText (package:flutter_tools/runner.dart) #19 _asyncErrorWrapperHelper.errorCallback (dart:async-patch/async_patch.dart:87:64) #20 _rootRunBinary (dart:async/zone.dart:1204:38) #21 _CustomZone.runBinary (dart:async/zone.dart:1093:19) #22 _FutureListener.handleError (dart:async/future_impl.dart:155:20) #23 Future._propagateToListeners.handleError (dart:async/future_impl.dart:694:47) #24 Future._propagateToListeners (dart:async/future_impl.dart:715:24) #25 Future._completeError (dart:async/future_impl.dart:534:5) #26 _AsyncAwaitCompleter.completeError (dart:async-patch/async_patch.dart:43:15) #27 AppContext.run (package:flutter_tools/src/base/context.dart) #28 _asyncErrorWrapperHelper.errorCallback (dart:async-patch/async_patch.dart:87:64) #29 _rootRunBinary (dart:async/zone.dart:1204:38) #30 _CustomZone.runBinary (dart:async/zone.dart:1093:19) #31 _FutureListener.handleError (dart:async/future_impl.dart:155:20) #32 Future._propagateToListeners.handleError (dart:async/future_impl.dart:694:47) #33 Future._propagateToListeners (dart:async/future_impl.dart:715:24) #34 Future._completeError (dart:async/future_impl.dart:534:5) #35 _AsyncAwaitCompleter.completeError (dart:async-patch/async_patch.dart:43:15) #36 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart) #37 _asyncErrorWrapperHelper.errorCallback (dart:async-patch/async_patch.dart:87:64) #38 _rootRunBinary (dart:async/zone.dart:1204:38) #39 _CustomZone.runBinary (dart:async/zone.dart:1093:19) #40 _FutureListener.handleError (dart:async/future_impl.dart:155:20) #41 Future._propagateToListeners.handleError (dart:async/future_impl.dart:694:47) #42 Future._propagateToListeners (dart:async/future_impl.dart:715:24) #43 Future._completeError (dart:async/future_impl.dart:534:5) #44 Future._asyncCompleteError.<anonymous closure> (dart:async/future_impl.dart:582:7) #45 _rootRun (dart:async/zone.dart:1184:13) #46 _CustomZone.run (dart:async/zone.dart:1077:19) #47 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1003:23) #48 _microtaskLoop (dart:async/schedule_microtask.dart:43:21) #49 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5) #50 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:118:13) #51 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:405:11) #52 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5) #53 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
I solved the issue by following 3 steps,
first step:- you need to disabled your virus guard,
second step:- you should remove cache folder entirely (it is located in ex:- 'C:\flutter\bin\cache')
Run 'Flutter Doctor' which would download all artifacts again
You have to install git and then restart your editors and your device
How can I resolve the problem as below ?
I run my application normally, it's run well.
But when I've set break point, then tried to perform debugging my code.
It always shows the error messages which do not come from my code, debugger is interrupted as well.
Unhandled exception:
NoSuchMethodError: The getter 'cls' was called on null.
Receiver: null
Tried calling: cls
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
#1 BodyBuilder.lookupInstanceMember (package:front_end/src/fasta/kernel/body_builder.dart:1604:30)
#2 BodyBuilder.scopeLookup (package:front_end/src/fasta/kernel/body_builder.dart:1764:13)
#3 BodyBuilder.handleIdentifier (package:front_end/src/fasta/kernel/body_builder.dart:1700:12)
#4 Parser.ensureIdentifier (package:front_end/src/fasta/parser/parser.dart:2165:14)
#5 Parser.parseSend (package:front_end/src/fasta/parser/parser.dart:4932:32)
#6 Parser.parseSendOrFunctionLiteral (package:front_end/src/fasta/parser/parser.dart:4675:12)
#7 Parser.parsePrimary (package:front_end/src/fasta/parser/parser.dart:4233:14)
#8 Parser.parseUnaryExpression (package:front_end/src/fasta/parser/parser.dart:4172:12)
#9 Parser.parsePrecedenceExpression (package:front_end/src/fasta/parser/parser.dart:3961:13)
#10 Parser.parseExpression (package:front_end/src/fasta/parser/parser.dart:3933:13)
#11 BodyBuilder.parseSingleExpression (package:front_end/src/fasta/kernel/body_builder.dart:1111:20)
#12 SourceLoader.buildExpression (package:front_end/src/fasta/source/source_loader.dart:327:21)
#13 IncrementalCompiler.compileExpression. (package:front_end/src/fasta/incremental_compiler.dart:795:61)
#14 CompilerContext.runInContext..
(package:front_end/src/fasta/compiler_context.dart:122:46)
#15 new Future.sync (dart:async/future.dart:224:31)
#16 CompilerContext.runInContext. (package:front_end/src/fasta/compiler_context.dart:122:19)
#17 _rootRun (dart:async/zone.dart:1124:13)
#18 _CustomZone.run (dart:async/zone.dart:1021:19)
#19 _runZoned (dart:async/zone.dart:1516:10)
#20 runZoned (dart:async/zone.dart:1463:12)
#21 CompilerContext.runInContext (package:front_end/src/fasta/compiler_context.dart:121:12)
#22 IncrementalCompiler.compileExpression (package:front_end/src/fasta/incremental_compiler.dart:726:26)
#23 IncrementalCompiler.compileExpression (package:vm/incremental_compiler.dart:156:23)
#24 FrontendCompiler.compileExpression (package:vm/frontend_server.dart:527:44)
#25 _FlutterFrontendCompiler.compileExpression (package:frontend_server/server.dart:62:22)
#26 listenAndCompile. (package:vm/frontend_server.dart:812:20)
#27 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#28 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#29 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#30 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68:11)
#31 _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
#32 _StringAdapterSink.add (dart:convert/string_conversion.dart:236:11)
#33 _LineSplitterSink._addLines (dart:convert/line_splitter.dart:150:13)
#34 _LineSplitterSink.addSlice (dart:convert/line_splitter.dart:125:5)
#35 StringConversionSinkMixin.add (dart:convert/string_conversion.dart:163:5)
#36 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120:24)
#37 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#38 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#39 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#40 _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:68:11)
#41 _EventSinkWrapper.add (dart:async/stream_transformers.dart:15:11)
#42 _StringAdapterSink.add (dart:convert/string_conversion.dart:236:11)
#43 _StringAdapterSink.addSlice (dart:convert/string_conversion.dart:241:7)
#44 _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:312:20)
#45 _Utf8ConversionSink.add (dart:convert/string_conversion.dart:305:5)
#46 _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:72:18)
#47 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:120:24)
#48 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#49 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#50 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#51 _SyncStreamController._sendData (dart:async/stream_controller.dart:764:19)
#52 _StreamController._add (dart:async/stream_controller.dart:640:7)
#53 _StreamController.add (dart:async/stream_controller.dart:586:5)
#54 _Socket._onData (dart:io-patch/socket_patch.dart:1786:41)
#55 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
#56 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
#57 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
#58 _SyncStreamController._sendData (dart:async/stream_controller.dart:764:19)
#59 _StreamController._add (dart:async/stream_controller.dart:640:7)
#60 _StreamController.add (dart:async/stream_controller.dart:586:5)
#61 new _RawSocket. (dart:io-patch/socket_patch.dart:1335:33)
#62 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:856:14)
#63 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#64 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#65 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:116:13)
#66 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:173:5)
My code:
main.dart
void main() async {
Flame.images.loadAll(<String>[
'level0.jpg'
]);
Util flameUtil = Util();
await flameUtil.fullScreen();
await flameUtil.setOrientation(DeviceOrientation.portraitUp);
MyGame game = MyGame ();
runApp(game.widget);
....
mygame.dart:
......
MyGame() {
sprite = Sprite('level0.jpg');// Break point
}
.............
note:
I am using Android studio 3.1
flutter veriosn 1.7.8
channel stable
Thanks a lot!!!