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.
Related
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.
I am writing a program with a simple page scroller that changes pages when scrolled. I want to have these pages changed this way such that I can be able to change them with another widget that will be inserted into the stack. Currently, I am not fully understanding the error and would like to know why the error is thrown. The error is shown below. Each screen page item has only a Scaffold with text inside body.
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../screens/account.dart';
import '../screens/home.dart';
import '../screens/post.dart';
import '../screens/saved.dart';
class ScreenChanger extends StatefulWidget {
const ScreenChanger({Key? key}) : super(key: key);
#override
State<ScreenChanger> createState() => _ScreenChangerState();
}
class _ScreenChangerState extends State<ScreenChanger> {
late HomeScreen homeScreen;
late SavedScreen savedScreen;
late PostScreen postScreen;
late AccountScreen accountScreen;
#override
void initState() {
homeScreen=HomeScreen();
savedScreen=SavedScreen();
postScreen=PostScreen();
accountScreen=AccountScreen();
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: ChangeNotifierProvider(
create: (_) { return ScreenController(); },
builder: (context, child) {
return Stack(
children: [
PageView.builder(
itemCount: 4,
itemBuilder: (context, index) {
setState(() {
Provider.of<ScreenController>(context, listen: false).currentPage=index;
});
return [
homeScreen,
savedScreen,
postScreen,
accountScreen,
][Provider.of<ScreenController>(context).currentPage];
},
),
],
);
},
),
);
}
}
class ScreenController extends ChangeNotifier{
late int _currentPage;
int get currentPage => _currentPage;
set currentPage(int value) {
_currentPage = value;
notifyListeners();
}
ScreenController({
int currentPage = 0
}){
this.currentPage=currentPage;
}
}
Error
======== Exception caught by foundation library ====================================================
The following assertion was thrown while dispatching notifications for ScreenController:
setState() or markNeedsBuild() called during build.
This _InheritedProviderScope<ScreenController?> widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: _InheritedProviderScope<ScreenController?>
value: Instance of 'ScreenController'
listening to value
The widget which was currently being built when the offending call was made was: SliverFillViewport
When the exception was thrown, this was the stack:
#0 Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:4549:11)
#1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4564:6)
#2 _InheritedProviderScopeElement.markNeedsNotifyDependents (package:provider/src/inherited_provider.dart:577:5)
#3 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:351:24)
#4 ScreenController.currentPage= (package:real_estate_v02/widgets/screen_changer.dart:69:5)
#5 _ScreenChangerState.build.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:real_estate_v02/widgets/screen_changer.dart:45:75)
#6 State.setState (package:flutter/src/widgets/framework.dart:1114:30)
#7 _ScreenChangerState.build.<anonymous closure>.<anonymous closure> (package:real_estate_v02/widgets/screen_changer.dart:44:19)
#8 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:485:22)
#9 SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1376:28)
#10 SliverMultiBoxAdaptorElement.performRebuild.processElement (package:flutter/src/widgets/sliver.dart:1306:67)
#11 Iterable.forEach (dart:core/iterable.dart:325:35)
#12 SliverMultiBoxAdaptorElement.performRebuild (package:flutter/src/widgets/sliver.dart:1353:24)
#13 SliverMultiBoxAdaptorElement.update (package:flutter/src/widgets/sliver.dart:1282:7)
#14 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#15 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#16 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#17 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#18 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#19 StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#20 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#21 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5904:32)
#22 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6460:17)
#23 _ViewportElement.update (package:flutter/src/widgets/viewport.dart:237:11)
#24 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#25 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#26 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#27 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#28 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#29 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#30 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#31 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#32 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#33 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#34 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#35 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#36 StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#37 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#38 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#39 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#40 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#41 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#42 ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#43 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#44 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#45 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#46 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#47 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#48 ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#49 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#50 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#51 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#52 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#53 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#54 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#55 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#56 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#57 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#58 ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#59 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#60 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#61 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#62 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#63 StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#64 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#65 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#66 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#67 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#68 StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#69 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#70 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#71 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#72 ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#73 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#74 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#75 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#76 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#77 StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#78 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#79 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5904:32)
#80 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6460:17)
#81 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#82 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#83 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#84 StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#85 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#86 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#87 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#88 ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#89 _InheritedProviderScopeElement.update (package:provider/src/inherited_provider.dart:523:11)
#90 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#91 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#92 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#93 StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#94 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#95 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#96 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#97 StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#98 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#99 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#100 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
.......
#350 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1104:9)
#351 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:881:7)
(elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)
The ScreenController sending notification was: Instance of 'ScreenController'
====================================================================================================
======== Exception caught by widgets library =======================================================
The following assertion was thrown building:
setState() or markNeedsBuild() called during build.
This ScreenChanger widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: ScreenChanger
state: _ScreenChangerState#ffffa
The widget which was currently being built when the offending call was made was: SliverFillViewport
When the exception was thrown, this was the stack:
#0 Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:4549:11)
#1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4564:6)
#2 State.setState (package:flutter/src/widgets/framework.dart:1134:15)
#3 _ScreenChangerState.build.<anonymous closure>.<anonymous closure> (package:real_estate_v02/widgets/screen_changer.dart:44:19)
#4 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:485:22)
#5 SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1376:28)
#6 SliverMultiBoxAdaptorElement.performRebuild.processElement (package:flutter/src/widgets/sliver.dart:1306:67)
#7 Iterable.forEach (dart:core/iterable.dart:325:35)
#8 SliverMultiBoxAdaptorElement.performRebuild (package:flutter/src/widgets/sliver.dart:1353:24)
#9 SliverMultiBoxAdaptorElement.update (package:flutter/src/widgets/sliver.dart:1282:7)
#10 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#11 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#12 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#14 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#15 StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#16 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#17 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5904:32)
#18 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6460:17)
#19 _ViewportElement.update (package:flutter/src/widgets/viewport.dart:237:11)
#20 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#21 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#22 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#23 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#24 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#25 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#26 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#27 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#28 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#30 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#31 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#32 StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#33 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#34 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#35 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#36 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#37 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#38 ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#39 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#40 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#41 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#42 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#43 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#44 ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#45 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#46 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#47 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#48 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#49 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#50 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6307:14)
#51 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#52 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#53 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#54 ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#55 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#56 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#57 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#58 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#59 StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#60 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#61 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#62 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#63 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#64 StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#65 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#66 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#67 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#68 ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#69 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#70 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#71 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#72 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#73 StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#74 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#75 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5904:32)
#76 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6460:17)
#77 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#78 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#79 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#80 StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#81 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#82 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#83 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#84 ProxyElement.update (package:flutter/src/widgets/framework.dart:5228:5)
#85 _InheritedProviderScopeElement.update (package:provider/src/inherited_provider.dart:523:11)
#86 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#87 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#88 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#89 StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#90 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#91 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#92 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#93 StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#94 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#95 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#96 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#97 StatelessElement.update (package:flutter/src/widgets/framework.dart:4956:5)
#98 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#99 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)
#100 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
.....
#345 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15)
#346 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1104:9)
#347 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:881:7)
(elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)
====================================================================================================
Found another solution:
Widget build(BuildContext context) {
return Scaffold(
body: ChangeNotifierProvider(
create: (_) { return ScreenController(); },
builder: (context, child) {
final screenController = Provider.of<ScreenController>(context);
return Stack(
children: [
PageView.builder(
itemCount: 4,
itemBuilder: (context, index) {
setState(() {
screenController.currentPage=index;
});
return [
homeScreen,
savedScreen,
postScreen,
accountScreen,
][screenController.currentPage];
},
),
],
);
},
),
);
}
You are calling setState middle of widget build. You can wait to finish the frame and then call setState.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Provider.of<ScreenController>(context, listen: false).currentPage = index;
}); // you may not needed using setState because there is not state variable needed to be updated
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'),
I have tried many ways to solve it in the last 3 days, but nothing worked. Has anyone experienced it too?
Dart analysis issue
NoSuchMethodError: The setter 'type=' was called on null.
Version information
Dart SDK 2.12.2
Dart IntelliJ 201.9335
Android Studio 4.1.3
Windows 10 10.0
Details
NoSuchMethodError: The setter 'type=' was called on null.
Receiver: null
Tried calling: type=Instance of 'InterfaceTypeImpl'
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1 Null.type= (dart:core/null.dart:1:1)
#2 ApplyResolutionVisitor.visitVariableDeclaration (package:analyzer/src/summary2/apply_resolution.dart:1327:13)
#3 VariableDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:10555:49)
#4 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#5 ApplyResolutionVisitor.visitVariableDeclarationList (package:analyzer/src/summary2/apply_resolution.dart:1345:20)
#6 VariableDeclarationListImpl.accept (package:analyzer/src/dart/ast/ast.dart:10655:15)
#7 ApplyResolutionVisitor.visitTopLevelVariableDeclaration (package:analyzer/src/summary2/apply_resolution.dart:1231:20)
#8 TopLevelVariableDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:9909:15)
#9 LinkedContext.applyResolution (package:analyzer/src/summary2/bundle_reader.dart:512:11)
#10 LinkedUnitContext.applyResolution (package:analyzer/src/summary2/linked_unit_context.dart:93:25)
#11 PropertyInducingElementImpl.typeInternal (package:analyzer/src/dart/element/element.dart:6731:21)
#12 ElementTypeProvider.getFieldType (package:analyzer/src/generated/element_type_provider.dart:62:15)
#13 PropertyInducingElementImpl.type (package:analyzer/src/dart/element/element.dart:6724:52)
#14 PropertyAccessorElementImpl_ImplicitGetter.returnTypeInternal (package:analyzer/src/dart/element/element.dart:6579:47)
#15 ElementTypeProvider.getExecutableReturnType (package:analyzer/src/generated/element_type_provider.dart:49:15)
#16 PropertyAccessorElementImpl_ImplicitGetter.returnType (package:analyzer/src/dart/element/element.dart:6571:35)
#17 PropertyAccessorElementImpl_ImplicitGetter.typeInternal (package:analyzer/src/dart/element/element.dart:6596:19)
#18 ElementTypeProvider.getExecutableType (package:analyzer/src/generated/element_type_provider.dart:55:15)
#19 PropertyAccessorElementImpl_ImplicitGetter.type (package:analyzer/src/dart/element/element.dart:6582:56)
#20 SimpleIdentifierResolver._getTypeOfProperty (package:analyzer/src/dart/resolver/simple_identifier_resolver.dart:52:42)
#21 SimpleIdentifierResolver._resolve2 (package:analyzer/src/dart/resolver/simple_identifier_resolver.dart:257:20)
#22 SimpleIdentifierResolver.resolve (package:analyzer/src/dart/resolver/simple_identifier_resolver.dart:42:5)
#23 ResolverVisitor.visitSimpleIdentifier (package:analyzer/src/generated/resolver.dart:1863:51)
#24 SimpleIdentifierImpl.accept (package:analyzer/src/dart/ast/ast.dart:8970:49)
#25 ResolverVisitor.visitArgumentList (package:analyzer/src/generated/resolver.dart:887:20)
#26 ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:355:49)
#27 MethodInvocationResolver._resolveArguments (package:analyzer/src/dart/resolver/method_invocation_resolver.dart:291:23)
#28 MethodInvocationResolver._resolveArguments_finishInference (package:analyzer/src/dart/resolver/method_invocation_resolver.dart:295:5)
#29 MethodInvocationResolver._setDynamicResolution (package:analyzer/src/dart/resolver/method_invocation_resolver.dart:782:5)
#30 MethodInvocationResolver._resolveReceiverType (package:analyzer/src/dart/resolver/method_invocation_resolver.dart:675:5)
#31 MethodInvocationResolver._resolveReceiverNull (package:analyzer/src/dart/resolver/method_invocation_resolver.dart:542:5)
#32 MethodInvocationResolver.resolve (package:analyzer/src/dart/resolver/method_invocation_resolver.dart:93:7)
#33 ElementResolver.visitMethodInvocation (package:analyzer/src/generated/element_resolver.dart:394:31)
#34 MethodInvocationImpl.accept (package:analyzer/src/dart/ast/ast.dart:7186:49)
#35 ResolverVisitor.visitMethodInvocation (package:analyzer/src/generated/resolver.dart:1706:10)
#36 MethodInvocationImpl.accept (package:analyzer/src/dart/ast/ast.dart:7186:49)
#37 AwaitExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:902:18)
#38 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#39 UnifyingAstVisitor.visitAwaitExpression (package:analyzer/dart/ast/visitor.dart:3137:51)
#40 ResolverVisitor.visitAwaitExpression (package:analyzer/src/generated/resolver.dart:944:11)
#41 AwaitExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:898:49)
#42 ExpressionStatementImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:3680:18)
#43 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#44 UnifyingAstVisitor.visitExpressionStatement (package:analyzer/dart/ast/visitor.dart:3229:59)
#45 ExpressionStatementImpl.accept (package:analyzer/src/dart/ast/ast.dart:3676:49)
#46 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#47 BlockImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1087:17)
#48 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#49 UnifyingAstVisitor.visitBlock (package:analyzer/dart/ast/visitor.dart:3143:31)
#50 ScopedVisitor.visitBlock.<anonymous closure> (package:analyzer/src/generated/resolver.dart:2480:13)
#51 ScopedVisitor._withDeclaredLocals (package:analyzer/src/generated/resolver.dart:3076:8)
#52 ScopedVisitor.visitBlock (package:analyzer/src/generated/resolver.dart:2479:5)
#53 BlockImpl.accept (package:analyzer/src/dart/ast/ast.dart:1083:49)
#54 BlockFunctionBodyImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1042:13)
#55 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#56 UnifyingAstVisitor.visitBlockFunctionBody (package:analyzer/dart/ast/visitor.dart:3146:55)
#57 ScopedVisitor.visitBlockFunctionBody (package:analyzer/src/generated/resolver.dart:2489:13)
#58 ResolverVisitor.visitBlockFunctionBody (package:analyzer/src/generated/resolver.dart:957:13)
#59 BlockFunctionBodyImpl.accept (package:analyzer/src/dart/ast/ast.dart:1038:49)
#60 FunctionExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:5010:12)
#61 FunctionExpressionResolver.resolve (package:analyzer/src/dart/resolver/function_expression_resolver.dart:65:10)
#62 ResolverVisitor.visitFunctionExpression (package:analyzer/src/generated/resolver.dart:1460:37)
#63 FunctionExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:5004:49)
#64 NamedExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7385:18)
#65 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#66 UnifyingAstVisitor.visitNamedExpression (package:analyzer/dart/ast/visitor.dart:3360:51)
#67 ResolverVisitor.visitNamedExpression (package:analyzer/src/generated/resolver.dart:1744:11)
#68 NamedExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:7380:49)
#69 ResolverVisitor.visitArgumentList (package:analyzer/src/generated/resolver.dart:887:20)
#70 ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:355:49)
#71 ResolverVisitor.visitInstanceCreationExpression (package:analyzer/src/generated/resolver.dart:1621:24)
#72 InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:6130:15)
#73 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#74 ListLiteralImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:6762:15)
#75 TypedLiteralResolver.resolveListLiteral (package:analyzer/src/dart/resolver/typed_literal_resolver.dart:97:10)
#76 ResolverVisitor.visitListLiteral (package:analyzer/src/generated/resolver.dart:1648:27)
#77 ListLiteralImpl.accept (package:analyzer/src/dart/ast/ast.dart:6757:49)
#78 NamedExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7385:18)
#79 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#80 UnifyingAstVisitor.visitNamedExpression (package:analyzer/dart/ast/visitor.dart:3360:51)
#81 ResolverVisitor.visitNamedExpression (package:analyzer/src/generated/resolver.dart:1744:11)
#82 NamedExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:7380:49)
#83 ResolverVisitor.visitArgumentList (package:analyzer/src/generated/resolver.dart:887:20)
#84 ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:355:49)
#85 ResolverVisitor.visitInstanceCreationExpression (package:analyzer/src/generated/resolver.dart:1621:24)
#86 InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:6130:15)
#87 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#88 ListLiteralImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:6762:15)
#89 TypedLiteralResolver.resolveListLiteral (package:analyzer/src/dart/resolver/typed_literal_resolver.dart:97:10)
#90 ResolverVisitor.visitListLiteral (package:analyzer/src/generated/resolver.dart:1648:27)
#91 ListLiteralImpl.accept (package:analyzer/src/dart/ast/ast.dart:6757:49)
#92 NamedExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7385:18)
#93 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#94 UnifyingAstVisitor.visitNamedExpression (package:analyzer/dart/ast/visitor.dart:3360:51)
#95 ResolverVisitor.visitNamedExpression (package:analyzer/src/generated/resolver.dart:1744:11)
#96 NamedExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:7380:49)
#97 ResolverVisitor.visitArgumentList (package:analyzer/src/generated/resolver.dart:887:20)
#98 ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:355:49)
#99 ResolverVisitor.visitInstanceCreationExpression (package:analyzer/src/generated/resolver.dart:1621:24)
#100 InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:6130:15)
#101 NamedExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7385:18)
#102 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#103 UnifyingAstVisitor.visitNamedExpression (package:analyzer/dart/ast/visitor.dart:3360:51)
#104 ResolverVisitor.visitNamedExpression (package:analyzer/src/generated/resolver.dart:1744:11)
#105 NamedExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:7380:49)
#106 ResolverVisitor.visitArgumentList (package:analyzer/src/generated/resolver.dart:887:20)
#107 ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:355:49)
#108 ResolverVisitor.visitInstanceCreationExpression (package:analyzer/src/generated/resolver.dart:1621:24)
#109 InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:6130:15)
#110 NamedExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7385:18)
#111 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#112 UnifyingAstVisitor.visitNamedExpression (package:analyzer/dart/ast/visitor.dart:3360:51)
#113 ResolverVisitor.visitNamedExpression (package:analyzer/src/generated/resolver.dart:1744:11)
#114 NamedExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:7380:49)
#115 ResolverVisitor.visitArgumentList (package:analyzer/src/generated/resolver.dart:887:20)
#116 ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:355:49)
#117 ResolverVisitor.visitInstanceCreationExpression (package:analyzer/src/generated/resolver.dart:1621:24)
#118 InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:6130:15)
#119 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#120 ListLiteralImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:6762:15)
#121 TypedLiteralResolver.resolveListLiteral (package:analyzer/src/dart/resolver/typed_literal_resolver.dart:97:10)
#122 ResolverVisitor.visitListLiteral (package:analyzer/src/generated/resolver.dart:1648:27)
#123 ListLiteralImpl.accept (package:analyzer/src/dart/ast/ast.dart:6757:49)
#124 NamedExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7385:18)
#125 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#126 UnifyingAstVisitor.visitNamedExpression (package:analyzer/dart/ast/visitor.dart:3360:51)
#127 ResolverVisitor.visitNamedExpression (package:analyzer/src/generated/resolver.dart:1744:11)
#128 NamedExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:7380:49)
#129 ResolverVisitor.visitArgumentList (package:analyzer/src/generated/resolver.dart:887:20)
#130 ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:355:49)
#131 ResolverVisitor.visitInstanceCreationExpression (package:analyzer/src/generated/resolver.dart:1621:24)
#132 InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:6130:15)
#133 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#134 ListLiteralImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:6762:15)
#135 TypedLiteralResolver.resolveListLiteral (package:analyzer/src/dart/resolver/typed_literal_resolver.dart:97:10)
#136 ResolverVisitor.visitListLiteral (package:analyzer/src/generated/resolver.dart:1648:27)
#137 ListLiteralImpl.accept (package:analyzer/src/dart/ast/ast.dart:6757:49)
#138 NamedExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7385:18)
#139 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#140 UnifyingAstVisitor.visitNamedExpression (package:analyzer/dart/ast/visitor.dart:3360:51)
#141 ResolverVisitor.visitNamedExpression (package:analyzer/src/generated/resolver.dart:1744:11)
#142 NamedExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:7380:49)
#143 ResolverVisitor.visitArgumentList (package:analyzer/src/generated/resolver.dart:887:20)
#144 ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:355:49)
#145 ResolverVisitor.visitInstanceCreationExpression (package:analyzer/src/generated/resolver.dart:1621:24)
#146 InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:6130:15)
#147 NamedExpressionImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7385:18)
#148 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#149 UnifyingAstVisitor.visitNamedExpression (package:analyzer/dart/ast/visitor.dart:3360:51)
#150 ResolverVisitor.visitNamedExpression (package:analyzer/src/generated/resolver.dart:1744:11)
#151 NamedExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:7380:49)
#152 ResolverVisitor.visitArgumentList (package:analyzer/src/generated/resolver.dart:887:20)
#153 ArgumentListImpl.accept (package:analyzer/src/dart/ast/ast.dart:355:49)
#154 ResolverVisitor.visitInstanceCreationExpression (package:analyzer/src/generated/resolver.dart:1621:24)
#155 InstanceCreationExpressionImpl.accept (package:analyzer/src/dart/ast/ast.dart:6130:15)
#156 ReturnStatementImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:8621:18)
#157 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#158 UnifyingAstVisitor.visitReturnStatement (package:analyzer/dart/ast/visitor.dart:3410:51)
#159 ResolverVisitor.visitReturnStatement (package:analyzer/src/generated/resolver.dart:1846:11)
#160 ReturnStatementImpl.accept (package:analyzer/src/dart/ast/ast.dart:8617:49)
#161 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#162 BlockImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1087:17)
#163 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#164 UnifyingAstVisitor.visitBlock (package:analyzer/dart/ast/visitor.dart:3143:31)
#165 ScopedVisitor.visitBlock.<anonymous closure> (package:analyzer/src/generated/resolver.dart:2480:13)
#166 ScopedVisitor._withDeclaredLocals (package:analyzer/src/generated/resolver.dart:3076:8)
#167 ScopedVisitor.visitBlock (package:analyzer/src/generated/resolver.dart:2479:5)
#168 BlockImpl.accept (package:analyzer/src/dart/ast/ast.dart:1083:49)
#169 BlockFunctionBodyImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1042:13)
#170 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#171 UnifyingAstVisitor.visitBlockFunctionBody (package:analyzer/dart/ast/visitor.dart:3146:55)
#172 ScopedVisitor.visitBlockFunctionBody (package:analyzer/src/generated/resolver.dart:2489:13)
#173 ResolverVisitor.visitBlockFunctionBody (package:analyzer/src/generated/resolver.dart:957:13)
#174 BlockFunctionBodyImpl.accept (package:analyzer/src/dart/ast/ast.dart:1038:49)
#175 MethodDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:7042:12)
#176 ResolverVisitor.visitNode (package:analyzer/src/generated/resolver.dart:1750:10)
#177 UnifyingAstVisitor.visitMethodDeclaration (package:analyzer/dart/ast/visitor.dart:3351:55)
#178 ScopedVisitor.visitMethodDeclarationInScope (package:analyzer/src/generated/resolver.dart:2926:11)
#179 ScopedVisitor.visitMethodDeclaration (package:analyzer/src/generated/resolver.dart:2919:7)
#180 ResolverVisitor.visitMethodDeclaration (package:analyzer/src/generated/resolver.dart:1666:11)
#181 MethodDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:7033:49)
#182 NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#183 ScopedVisitor.visitClassMembersInScope (package:analyzer/src/generated/resolver.dart:2550:18)
#184 ScopedVisitor.visitClassDeclaration (package:analyzer/src/generated/resolver.dart:2531:7)
#185 ResolverVisitor.visitClassDeclaration (package:analyzer/src/generated/resolver.dart:1015:13)
#186 ClassDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:1536:49)
#187 ResolverVisitor.visitCompilationUnit (package:analyzer/src/generated/resolver.dart:1091:23)
#188 CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:2134:49)
#189 LibraryAnalyzer._resolveFile (package:analyzer/src/dart/analysis/library_analyzer.dart:709:10)
#190 LibraryAnalyzer.analyzeSync.<anonymous closure> (package:analyzer/src/dart/analysis/library_analyzer.dart:139:7)
#191 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:397:8)
#192 LibraryAnalyzer.analyzeSync (package:analyzer/src/dart/analysis/library_analyzer.dart:138:11)
#193 LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:107:12)
#194 AnalysisDriver._computeAnalysisResult2.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1319:63)
#195 PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#196 AnalysisDriver._computeAnalysisResult2 (package:analyzer/src/dart/analysis/driver.dart:1296:20)
#197 AnalysisDriver._computeAnalysisResult.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1249:14)
#198 _rootRun (dart:async/zone.dart:1354:13)
#199 _CustomZone.run (dart:async/zone.dart:1258:19)
#200 _runZoned (dart:async/zone.dart:1788:10)
#201 runZoned (dart:async/zone.dart:1710:10)
#202 NullSafetyUnderstandingFlag.enableNullSafetyTypes (package:analyzer/dart/element/null_safety_understanding_flag.dart:42:12)
#203 AnalysisDriver._computeAnalysisResult (package:analyzer/src/dart/analysis/driver.dart:1248:40)
#204 AnalysisDriver._computeIndex (package:analyzer/src/dart/analysis/driver.dart:1386:37)
#205 AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:995:39)
#206 AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2018:24)
<asynchronous suspension>
#0 Driver._captureExceptions.errorFunction (package:analysis_server/src/server/driver.dart:480:7)
#1 _CustomZone.handleUncaughtError (dart:async/zone.dart:1241:19)
#2 _CustomZone.runGuarded (dart:async/zone.dart:1164:7)
#3 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
#4 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#5 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#6 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:120:13)
#7 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:402:11)
#8 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
Debug log
1617529296421 => {"id":"1198","method":"analysis.updateContent","params":{"files":{"C:\\Users\\krish\\AndroidStudioProjects\\smart_vendor\\lib\\screens\\detail_order_screen.dart":{"type":"add","conten...
1617529296421 <= {"id":"1198","result":{}}
1617529296421 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
1617529296452 => {"id":"1199","method":"edit.getAssists","params":{"file":"C:\\Users\\krish\\AndroidStudioProjects\\smart_vendor\\lib\\screens\\detail_order_screen.dart","offset":124,"length":0},"clie...
1617529296608 <= {"id":"1199","result":{"assists":[]}}
1617529296608 <= {"event":"completion.availableSuggestions","params":{"changedLibraries":[{"id":982,"uri":"package:smart_vendor/screens/screens.dart","items":[{"label":"IllustrationPage","declaringLib...
1617529296608 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}
1617529297046 => {"id":"1200","method":"analysis.updateContent","params":{"files":{"C:\\Users\\krish\\AndroidStudioProjects\\smart_vendor\\lib\\screens\\detail_order_screen.dart":{"type":"add","conten...
1617529297046 <= {"id":"1200","result":{}}
1617529297046 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
1617529297077 => {"id":"1201","method":"edit.getAssists","params":{"file":"C:\\Users\\krish\\AndroidStudioProjects\\smart_vendor\\lib\\screens\\detail_order_screen.dart","offset":123,"length":0},"clie...
1617529297216 <= {"id":"1201","result":{"assists":[]}}
1617529297232 <= {"event":"completion.availableSuggestions","params":{"changedLibraries":[{"id":982,"uri":"package:smart_vendor/screens/screens.dart","items":[{"label":"IllustrationPage","declaringLib...
1617529297232 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}
1617529299111 => {"id":"1202","method":"edit.getAssists","params":{"file":"C:\\Users\\krish\\AndroidStudioProjects\\smart_vendor\\lib\\screens\\detail_order_screen.dart","offset":261,"length":8},"clie...
1617529299173 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
1617529299173 <= {"id":"1202","result":{"assists":[]}}
1617529299173 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}
1617529300705 => {"id":"1203","method":"analysis.setPriorityFiles","params":{"files":["C:\\Developments\\flutter\\packages\\flutter\\lib\\src\\widgets\\framework.dart"]},"clientRequestTime":1617529300...
1617529300705 => {"id":"1204","method":"analysis.setSubscriptions","params":{"subscriptions":{"OVERRIDES":["C:\\Developments\\flutter\\packages\\flutter\\lib\\src\\widgets\\framework.dart"],"CLOSING_L...
1617529300705 <= {"id":"1203"}
1617529300705 <= {"id":"1204"}
1617529300830 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
1617529300845 <= {"event":"analysis.highlights","params":{"file":"C:\\Developments\\flutter\\packages\\flutter\\lib\\src\\widgets\\framework.dart","regions":[{"type":"DIRECTIVE","offset":169,"length":...
1617529300861 <= {"event":"analysis.navigation","params":{"file":"C:\\Developments\\flutter\\packages\\flutter\\lib\\src\\widgets\\framework.dart","regions":[{"offset":176,"length":12,"targets":[0]},{...
1617529300861 <= {"event":"analysis.closingLabels","params":{"file":"C:\\Developments\\flutter\\packages\\flutter\\lib\\src\\widgets\\framework.dart","labels":[{"offset":9145,"length":486,"label":"Flu...
1617529300876 <= {"event":"analysis.outline","params":{"file":"C:\\Developments\\flutter\\packages\\flutter\\lib\\src\\widgets\\framework.dart","kind":"LIBRARY","outline":{"element":{"kind":"COMPILATI...
1617529300876 <= {"event":"analysis.overrides","params":{"file":"C:\\Developments\\flutter\\packages\\flutter\\lib\\src\\widgets\\framework.dart","overrides":[{"offset":2033,"length":8,"superclassMemb...
1617529300892 <= {"event":"flutter.outline","params":{"file":"C:\\Developments\\flutter\\packages\\flutter\\lib\\src\\widgets\\framework.dart","outline":{"kind":"DART_ELEMENT","offset":0,"length":2660...
1617529300892 <= {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}
This is one of some files that caused this exception:
library screens;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:smart_vendor/lang/lang.dart';
import 'package:smart_vendor/cubit/cubit.dart';
import 'package:smart_vendor/models/models.dart';
import 'package:smart_vendor/shared/shared.dart';
import 'package:smart_vendor/widgets/widgets.dart';
part 'address_page.dart';
part 'general_page.dart';
part 'sign_in_page.dart';
part 'sign_up_page.dart';
part 'sign_up_agent_page.dart';
part 'sign_up_personal_page.dart';
part 'sign_up_business_page.dart';
part 'main_page.dart';
part 'profile_page.dart';
part 'history_page.dart';
part 'illustration_page.dart';
part 'filter_page.dart';
part 'success_page.dart';
part 'success_sign_up_page.dart';
part 'take_order_confirmation_page.dart';
part 'detail_order_screen.dart';
I have a Timer that has a small animation which is a circle around it. The Timer is called from another route to start (ExamTimer(size: 40.0),). And when ever I navigate to another route I get the following Error:
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown while finalizing the widget tree:
ExamTimerState#c1b45(tickers: tracking 1 ticker) was disposed with an active Ticker.
ExamTimerState created a Ticker via its TickerProviderStateMixin, but at the time dispose() was called on the mixin, that Ticker was still active. All Tickers must be disposed before calling super.dispose().
Tickers used by AnimationControllers should be disposed by calling dispose() on the AnimationController itself. Otherwise, the ticker will leak.
The offending ticker was: _WidgetTicker(created by ExamTimerState#c1b45(lifecycle state: created, tickers: tracking 0 tickers))
The stack trace when the _WidgetTicker was actually created was:
#0 new Ticker.<anonymous closure> (package:flutter/src/scheduler/ticker.dart:66:40)
#1 new Ticker (package:flutter/src/scheduler/ticker.dart:68:6)
#2 new _WidgetTicker (package:flutter/src/widgets/ticker_provider.dart:237:80)
#3 TickerProviderStateMixin.createTicker (package:flutter/src/widgets/ticker_provider.dart:168:34)
#4 new AnimationController (package:flutter/src/animation/animation_controller.dart:245:21)
#5 ExamTimerState.initState (package:azmoonasli/models/ExamTimer.dart:27:18)
#6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)
#7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#9 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
#10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#11 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#13 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#14 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#15 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#16 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#18 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#20 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#21 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#22 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#24 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#25 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#27 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#28 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#29 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#30 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#31 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#33 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#34 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#35 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#36 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#37 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#38 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#39 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#40 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#41 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#42 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
#43 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#44 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#45 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#46 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#47 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#48 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#49 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#50 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
#51 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#52 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#53 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#54 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#55 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#56 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#57 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#58 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#59 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#60 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#61 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#62 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#63 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#64 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#65 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#66 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#67 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#68 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#69 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#70 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#71 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#72 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#73 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#74 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#75 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#76 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#77 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#78 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#79 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#80 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#81 ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4617:11)
#82 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#83 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
#84 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#85 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#86 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#87 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#88 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#89 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#90 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#91 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#92 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#93 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#94 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#95 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#96 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#97 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#98 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#99 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#100 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#101 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#102 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#103 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#104 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#105 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#106 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#108 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#109 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#110 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#111 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#112 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#113 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#114 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#115 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#116 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#117 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#118 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#119 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#120 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#121 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#122 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#123 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#124 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#125 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#126 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#127 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#128 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#129 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#130 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#131 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#132 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#133 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#134 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#135 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#136 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#137 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#138 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#139 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#140 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#141 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#142 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#143 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#144 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#145 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#146 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#147 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#148 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#149 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#150 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#151 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#152 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#153 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#154 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#155 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#156 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#157 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#158 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#159 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#160 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#161 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#162 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#163 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#164 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#165 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#166 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#167 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#168 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#169 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#170 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#171 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#172 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#173 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#174 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#175 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#176 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#177 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#178 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#179 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#180 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#181 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#182 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#183 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#184 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#185 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#186 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#187 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#188 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#189 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#190 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#191 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#192 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#193 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#194 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#195 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#196 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#197 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#198 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#199 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#200 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#201 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#202 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#203 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#204 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#205 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#206 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#207 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#208 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#209 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#210 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#211 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#212 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#213 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#217 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#224 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#225 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#226 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#227 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#228 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#229 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#230 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#231 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#232 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#233 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#234 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#235 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#236 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#237 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#238 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#239 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#240 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#241 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#242 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5219:32)
#243 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5561:17)
#244 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#245 _TheatreElement.update (package:flutter/src/widgets/overlay.dart:605:16)
#246 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#247 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#249 StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5)
#250 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#251 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#252 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#253 ProxyElement.update (package:flutter/src/widgets/framework.dart:4557:5)
#254 _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:94:11)
#255 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#256 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
#257 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#258 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#259 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#260 StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5)
#261 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#262 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
#263 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#264 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
#265 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#266 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#267 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#268 StatelessElement.update (package:flutter/src/widgets/framework.dart:4298:5)
#269 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#270 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#272 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2432:33)
#273 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:773:20)
#274 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
#275 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
#276 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
#277 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)
#281 _invoke (dart:ui/hooks.dart:259:10)
#282 _drawFrame (dart:ui/hooks.dart:217:3)
(elided 3 frames from package dart:async)
When the exception was thrown, this was the stack:
#0 TickerProviderStateMixin.dispose.<anonymous closure> (package:flutter/src/widgets/ticker_provider.dart:185:13)
#1 TickerProviderStateMixin.dispose (package:flutter/src/widgets/ticker_provider.dart:203:6)
#2 StatefulElement.unmount (package:flutter/src/widgets/framework.dart:4435:12)
#3 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1748:13)
#4 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1746:7)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
Here's my code:
import 'package:flutter/material.dart';
import 'dart:math' as math;
class ExamTimer extends StatefulWidget {
final double size;
ExamTimer({#required this.size, });
#override
ExamTimerState createState() => ExamTimerState();
}
class ExamTimerState extends State<ExamTimer> with TickerProviderStateMixin {
AnimationController controller;
String get timerString {
Duration duration = controller.duration * controller.value;
return '${duration.inMinutes}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
}
#override
void initState() {
super.initState();
controller = AnimationController(
vsync: this,
duration: Duration(minutes: 20),
);
}
#override
Widget build(BuildContext context) {
ThemeData themeData = Theme.of(context);
controller.reverse(from: controller.value == 0.0 ? 1.0 : controller.value);
return Stack(
alignment: Alignment.center,
children: <Widget>[ AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child) {
return CustomPaint(
size: Size(widget.size, widget.size),
painter: TimerPainter(
animation: controller,
backgroundColor: Colors.white,
color: themeData.indicatorColor,
));
},
),
AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child) {
return Text(
timerString,
style: TextStyle(fontSize: 12.0),
);
}),
],
);
}
}
class TimerPainter extends CustomPainter {
TimerPainter({
this.animation,
this.backgroundColor,
this.color,
}) : super(repaint: animation);
final Animation<double> animation;
final Color backgroundColor, color;
#override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = backgroundColor
..strokeWidth = 5.0
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke;
canvas.drawCircle(size.center(Offset.zero), size.width / 2.0, paint);
paint.color = color;
double progress = (1.0 - animation.value) * 2 * math.pi;
canvas.drawArc(Offset.zero & size, math.pi * 1.5, progress, false, paint);
}
#override
bool shouldRepaint(TimerPainter old) {
return animation.value != old.animation.value ||
color != old.color ||
backgroundColor != old.backgroundColor;
}
}
So I have 3 questions:
How to dispose() the timer when user manually Navigates to another route?
I need to know The time from when user started ExamTimer() to when he navigated to another route(Total time passed).
How to Navigate automatically to another route when the timer finishes it's duration.
A sample code or any approach would be so appreciated.
First, You need to dispose your AnimationController by this way
controller?.dispose();
About your questions:
1. This is how you can dispose a Timer
yourTimer.cancel();
2.Eleapsed time can be calculated ether by using StopWatch or Timer
StopWatch
//start a stopwatch
final watch = StopWatch()..start();
//Eleapsed time
watch.eleapsed //returns a Duration
//Stop it
watch.stop()
//You can also reset when you return to your page
watch.reset();
Timer
//Start
final timer = Timer.periodic(Duration(seconds:1), (Timer ticker){
if(ticker.tick == 2){//Wait for 1*2 seconds
//Navigate here
}
//Total eleapsed time
timer.tick*yourDurationUnit // used when creating this timer
)
Navigate automatically
Timer timer = Timer(Duration(seconds: 2), (){
//Navigate here
});
NOTE: You should dispose Timer and StopWatch in dispose method or it'll cause memory leaks