I am just testing some streams from a GPS. I could plug in the gps stream directly, but I want to separate this for the moment. So I can using a StreamBuilder with my own created stream.
This all seems to be working, but the Streambuilder seems to 'miss' certain snapshots, which has me confused. Shouldn't it be guaranteed to receive all data from the stream (if it's not a broadcast)? Or am I using streams incorrectly ?
If you look at the data added/received, I can see count 5 & 7 were both added, but never received. If I just 'listen' the data without the StreamBuilder, all of the data seems to appear.
Streambuilder code:
Widget build(BuildContext context) {
final ApplicationBloc bloc = BlocProvider.of<ApplicationBloc>(context);
return StreamBuilder<Map<String, dynamic>>(
stream: bloc.gps.stream,
builder: (BuildContext context, AsyncSnapshot<Map<String, dynamic>> snapshot){
if( snapshot.hasData ) {
print("Receiving ${snapshot.data['count']}");
return Text("${snapshot.data['timestamp']}\n${snapshot.data['latitude']},${snapshot.data['longitude']}\n",
style: Theme.of(context).textTheme.display1,);
} else {
return Text('waiting for GPS...', style: Theme.of(context).textTheme.display1,);
}
}
);
}
Add to stream code:
var locationOptions = LocationOptions(accuracy: LocationAccuracy.bestForNavigation, distanceFilter: 0, timeInterval: 1, forceAndroidLocationManager: false);
final Geolocator geoLocator = new Geolocator();
geoLocator.getPositionStream( locationOptions ).listen(
(Position position) {
_count++;
Map<String, dynamic> listenerCurrentLocation = {
'latitude' : position.latitude,
'longitude' : position.longitude,
'speed' : position.speed,
'accuracy' : position.accuracy,
'altitude' : position.altitude,
'timestamp' : position.timestamp,
'count' : _count,
};
print( "Adding: $listenerCurrentLocation");
gpsController.sink.add( listenerCurrentLocation );
});
Output from Run console
I/flutter (16345): Receiving 2
I/flutter (16345): Adding: {latitude: 50.829798333333336, longitude: -0.18484833333333334, speed: 0.0, accuracy: 20.0, altitude: 11.7, timestamp: 2019-01-13 14:21:02.000Z, count: 3}
I/flutter (16345): Receiving 3
I/flutter (16345): Adding: {latitude: 50.829798333333336, longitude: -0.18484833333333334, speed: 0.0, accuracy: 20.0, altitude: 11.7, timestamp: 2019-01-13 14:21:03.000Z, count: 4}
I/flutter (16345): Receiving 4
I/flutter (16345): Adding: {latitude: 50.829798333333336, longitude: -0.18484833333333334, speed: 0.0, accuracy: 20.0, altitude: 11.7, timestamp: 2019-01-13 14:21:04.000Z, count: 5}
I/flutter (16345): Adding: {latitude: 50.829798333333336, longitude: -0.18484833333333334, speed: 0.0, accuracy: 20.0, altitude: 0.0, timestamp: 2019-01-13 14:21:04.000Z, count: 6}
I/flutter (16345): Receiving 6
I/flutter (16345): Adding: {latitude: 50.829798333333336, longitude: -0.18484833333333334, speed: 0.0, accuracy: 20.0, altitude: 11.7, timestamp: 2019-01-13 14:21:05.000Z, count: 7}
I/flutter (16345): Adding: {latitude: 50.829798333333336, longitude: -0.18484833333333334, speed: 0.0, accuracy: 20.0, altitude: 0.0, timestamp: 2019-01-13 14:21:05.000Z, count: 8}
I/flutter (16345): Receiving 8
This is the expected behavior.
As opposed to using stream.listen, StreamBuilder calls its builder only when a new frame is requested.
It is fine because StreamBuilder should be used only to build the layout, in which case it doesn't matter if a value is missed.
If this behavior is undesired, consider switching to a manual listening instead:
Stream stream;
StreamSubscription sub;
initState() {
super.initState();
sub = stream.listen((value) {
// do something with `value`
});
}
dispose() {
sub.cancel();
super.dispose();
}
Related
I want to track distance of user continuously using StreamSubscription but every time the app crashed. Plugin used for locating user is location. here is the code.
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:location/location.dart';
import 'package:latlong/latlong.dart' as LatLong;
const LatLng defaultPosition = LatLng(0.906706, 123.259054);
class MapRoute extends StatefulWidget {
final LatLng lokasiKegiatan;
final double maxPerimeter;
MapRoute(this.lokasiKegiatan, this.maxPerimeter);
#override
_MapRouteState createState() => _MapRouteState();
}
class _MapRouteState extends State<MapRoute> {
Completer<GoogleMapController> mapController = Completer();
bool isLoading = false;
bool isUserNearby = false;
bool isUserVisible = true;
Location _locationManager = new Location();
StreamSubscription<LocationData> _locationTrackerSub;
LocationData _lokasiTerkini;
String errorMessage;
double distanceToLocation;
#override
void initState() {
// TODO: implement initState
super.initState();
_locationTrackerSub = _locationManager.onLocationChanged().listen((data) {
setState(() {
_lokasiTerkini = data;
});
});
}
#override
void dispose() {
// TODO: implement dispose
_locationTrackerSub = null;
super.dispose();
}
#override
Widget build(BuildContext context) {
MarkerId markerId = MarkerId('ACARA PEMDA');
Marker markerLokasi = new Marker(
markerId: markerId,
position: widget.lokasiKegiatan,
infoWindow: InfoWindow(
title: 'Apel Bersama',
snippet: 'Apel Bersama PEMDA BOLMUT',
),
icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueRed));
final Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
markers[markerId] = markerLokasi;
return Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Padding(
padding: EdgeInsets.all(3.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
child: Column(
children: <Widget>[
SizedBox(
height: 400,
child: Stack(
children: <Widget>[
GoogleMap(
mapType: MapType.normal,
onMapCreated: _onMapCreated,
myLocationEnabled: isUserVisible,
initialCameraPosition: CameraPosition(
target: defaultPosition,
zoom: 15,
),
markers: Set<Marker>.of(markers.values),
),
Positioned(
top: 12,
left: 12,
child: SizedBox(
width: 39,
height: 37,
child: RaisedButton(
elevation: 1.0,
padding: EdgeInsets.all(2.0),
shape: RoundedRectangleBorder(
side: BorderSide(
width: 0.5,
color: Colors.white,
),
borderRadius: BorderRadius.all(
Radius.circular(5.0),
),
),
child: Icon(
Icons.location_on,
color: Colors.black54,
size: 27,
),
color: Colors.white,
onPressed: _goToLokasiKegiatan,
),
),
),
Positioned(
top: 25,
left: 57,
child: distanceToLocation != null
? Text('0 KM')
: Text(
'menghitung jarak ke lokasi kegiatan...',
style: ThemeData().textTheme.title,
),
)
],
),
),
],
),
),
),
SizedBox(
height: 20.0,
),
RaisedButton(
color: Colors.blue,
shape:
CircleBorder(side: BorderSide(width: 1.0, color: Colors.amber)),
elevation: 5,
child: Icon(
Icons.fingerprint,
color: Colors.white,
size: 74,
),
onPressed: isUserNearby ? () {} : null)
],
);
}
void _onMapCreated(GoogleMapController controller) async {
mapController.complete(controller);
_goToLokasiKegiatan();
}
void _goToLokasiKegiatan() async {
mapController.future.then((controller) {
controller.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(target: widget.lokasiKegiatan, zoom: 18.0),
),
);
});
}
double calculateUserDistance(LocationData currentPosition) {
//converting from gmap to latlong package
var lat = widget.lokasiKegiatan.latitude;
var long = widget.lokasiKegiatan.longitude;
var ulat = currentPosition.latitude;
var ulong = currentPosition.longitude;
var jarak = LatLong.Distance();
double meter = jarak.as(
LatLong.LengthUnit.Meter,
new LatLong.LatLng(lat, long),
new LatLong.LatLng(ulat, ulong),
);
return meter;
}
void _processUserLocation(LocationData locationData) async {
var distanceToLocation = calculateUserDistance(locationData);
if (distanceToLocation <= widget.maxPerimeter) {
setState(() {
isUserNearby = true;
});
}
setState(() {
this.distanceToLocation = distanceToLocation;
});
}
void _initLocation() async {
LocationData location;
try {
if (await _locationManager.hasPermission()) {
_locationTrackerSub = _locationManager.onLocationChanged().listen(
(locationData) {
setState(() {
_lokasiTerkini = locationData;
});
},
);
}
} catch (e) {
debugPrint(e);
}
}
}
and the debug output..
Launching lib\main.dart on ASUS X00QD in debug mode...
Built build\app\outputs\apk\debug\app-debug.apk.
I/SimplePermission(16555): Checking permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
Reloaded 2 of 449 libraries in 1,234ms.
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
Reloaded 2 of 449 libraries in 951ms.
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 2
I/SimplePermission(16555): Requesting permission : android.permission.ACCESS_FINE_LOCATION
I/SimplePermission(16555): Requesting permission status : 3
I/zzbz (16555): Making Creator dynamically
W/mple.absensigp(16555): Unsupported class loader
W/mple.absensigp(16555): Skipping duplicate class check due to unsupported classloader
I/DynamiteModule(16555): Considering local module com.google.android.gms.maps_dynamite:0 and remote module com.google.android.gms.maps_dynamite:221
I/DynamiteModule(16555): Selected remote version of com.google.android.gms.maps_dynamite, version >= 221
V/DynamiteModule(16555): Dynamite loader version >= 2, using loadModule2NoCrashUtils
W/mple.absensigp(16555): Unsupported class loader
W/mple.absensigp(16555): Skipping duplicate class check due to unsupported classloader
I/Google Maps Android API(16555): Google Play services client version: 12451000
I/Google Maps Android API(16555): Google Play services package version: 15090039
W/mple.absensigp(16555): Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
D/NetworkSecurityConfig(16555): No Network Security Config specified, using platform default
I/DpmTcmClient(16555): RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor
W/DynamiteModule(16555): Local module descriptor class for com.google.android.gms.googlecertificates not found.
I/DynamiteModule(16555): Considering local module com.google.android.gms.googlecertificates:0 and remote module com.google.android.gms.googlecertificates:4
I/DynamiteModule(16555): Selected remote version of com.google.android.gms.googlecertificates, version >= 4
W/mple.absensigp(16555): Unsupported class loader
W/mple.absensigp(16555): Skipping duplicate class check due to unsupported classloader
I/Adreno (16555): DequeueBuffer: dequeueBuffer failed
I/Adreno (16555): DequeueBuffer: dequeueBuffer failed
I/Adreno (16555): DequeueBuffer: dequeueBuffer failed
W/OpenGLRenderer(16555): swapBuffers encountered EGL error 12301 on 0x75f6b20a00, halting rendering...
I/Google Maps Android API(16555): Google Play services package version: 15090039
W/System (16555): A resource failed to call release.
I/Google Maps Android API(16555): Google Play services package version: 15090039
I/Google Maps Android API(16555): Google Play services package version: 15090039
W/System (16555): A resource failed to call release.
W/System (16555): A resource failed to call release.
I/Google Maps Android API(16555): Google Play services package version: 15090039
W/System (16555): A resource failed to call release.
I/Google Maps Android API(16555): Google Play services package version: 15090039
I/mple.absensigp(16555): Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
W/System (16555): A resource failed to call release.
Reloaded 3 of 449 libraries in 1,114ms.
I/Adreno (16555): DequeueBuffer: dequeueBuffer failed
I/Adreno (16555): DequeueBuffer: dequeueBuffer failed
I/Adreno (16555): DequeueBuffer: dequeueBuffer failed
W/OpenGLRenderer(16555): swapBuffers encountered EGL error 12301 on 0x75ef08a900, halting rendering...
E/flutter (16555): [ERROR:flutter/shell/platform/android/platform_view_android_jni.cc(40)] java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/app/ActivityCompat;
E/flutter (16555): at com.lyokone.location.LocationPlugin.checkPermissions(LocationPlugin.java:186)
E/flutter (16555): at com.lyokone.location.LocationPlugin.onListen(LocationPlugin.java:271)
E/flutter (16555): at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onListen(EventChannel.java:181)
E/flutter (16555): at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler.onMessage(EventChannel.java:160)
E/flutter (16555): at io.flutter.view.FlutterNativeView$PlatformMessageHandlerImpl.handleMessageFromDart(FlutterNativeView.java:188)
E/flutter (16555): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:202)
E/flutter (16555): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (16555): at android.os.MessageQueue.next(MessageQueue.java:326)
E/flutter (16555): at android.os.Looper.loop(Looper.java:163)
E/flutter (16555): at android.app.ActivityThread.main(ActivityThread.java:6732)
E/flutter (16555): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (16555): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/flutter (16555): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/flutter (16555): Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.ActivityCompat" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.example.absensigps-vaz4urV31quLBNjs6K8-IA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.absensigps-vaz4urV31quLBNjs6K8-IA==/lib/arm64, /data/app/com.example.absensigps-vaz4urV31quLBNjs6K8-IA==/base.apk!/lib/arm64-v8a, /system/lib64]]
E/flutter (16555): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
E/flutter (16555): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/flutter (16555): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/flutter (16555): ... 13 more
E/flutter (16555):
F/flutter (16555): [FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(77)] Check failed: CheckException(env).
F/libc (16555): Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 16555 (mple.absensigps), pid 16555 (mple.absensigps)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'asus/WW_X00QD/ASUS_X00QD:9/PPR1.180610.009/16.0611.1901.1-0:user/release-keys'
Revision: '0'
ABI: 'arm64'
pid: 16555, tid: 16555, name: mple.absensigps >>> com.example.absensigps <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: '[FATAL:flutter/shell/platform/android/platform_view_android_jni.cc(77)] Check failed: CheckException(env).
'
x0 0000000000000000 x1 00000000000040ab x2 0000000000000006 x3 0000000000000008
x4 0000000000000000 x5 0000000000000000 x6 0000000000000000 x7 0000008000000000
x8 0000000000000083 x9 afcf0ea64e096394 x10 0000000000000000 x11 fffffffc7ffffbdf
x12 0000000000000001 x13 0000000000000018 x14 ffffffffffffffff x15 0000f282b913c801
x16 00000076978b02c8 x17 00000076977ee0d0 x18 0000000000000001 x19 00000000000040ab
x20 00000000000040ab x21 0000007fd63435b8 x22 00000000000000c3 x23 0000000000000099
x24 00000075f8bbdfc0 x25 0000000000000050 x26 00000075eb83a6a0 x27 0000007612cf7c88
x28 0000000000000034 x29 0000007fd63435a0
sp 0000007fd6343560 lr 00000076977e2bfc pc 00000076977e2c24
backtrace:
#00 pc 0000000000021c24 /system/lib64/libc.so (abort+116)
#01 pc 00000000006b7e48 /data/app/com.example.absensigps-vaz4urV31quLBNjs6K8-IA==/lib/arm64/libflutter.so (offset 0x690000)
#02 pc 00000000006aca1c /data/app/com.example.absensigps-vaz4urV31quLBNjs6K8-IA==/lib/arm64/libflutter.so (offset 0x690000)
#03 pc 00000000006abc74 /data/app/com.example.absensigps-vaz4urV31quLBNjs6K8-IA==/lib/arm64/libflutter.so (offset 0x690000)
#04 pc 00000000006e5018 /data/app/com.example.absensigps-vaz4urV31quLBNjs6K8-IA==/lib/arm64/libflutter.so (offset 0x690000)
#05 pc 00000000006b9368 /data/app/com.example.absensigps-vaz4urV31quLBNjs6K8-IA==/lib/arm64/libflutter.so (offset 0x690000)
#06 pc 00000000006baf58 /data/app/com.example.absensigps-vaz4urV31quLBNjs6K8-IA==/lib/arm64/libflutter.so (offset 0x690000)
#07 pc 00000000000141c0 /system/lib64/libutils.so (android::Looper::pollInner(int)+856)
#08 pc 0000000000013dcc /system/lib64/libutils.so (android::Looper::pollOnce(int, int*, int*, void**)+60)
#09 pc 0000000000120a94 /system/lib64/libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv*, _jobject*, long, int)+44)
#10 pc 00000000003e4fec /system/framework/arm64/boot-framework.oat (offset 0x3d0000) (android.media.MediaExtractor.seekTo [DEDUPED]+140)
#11 pc 000000000000284c /dev/ashmem/dalvik-jit-code-cache (deleted) (android.os.MessageQueue.next+204)
#12 pc 000000000006c8d4 /dev/ashmem/dalvik-jit-code-cache (deleted) (android.os.Looper.loop+404)
#13 pc 0000000000554cdc /system/lib64/libart.so (art_quick_osr_stub+44)
#14 pc 0000000000306f9c /system/lib64/libart.so (art::jit::Jit::MaybeDoOnStackReplacement(art::Thread*, art::ArtMethod*, unsigned int, int, art::JValue*)+1996)
#15 pc 000000000052ad1c /system/lib64/libart.so (MterpMaybeDoOnStackReplacement+144)
#16 pc 000000000054b9f0 /system/lib64/libart.so (ExecuteMterpImpl+33136)
#17 pc 0000000000b15512 /system/framework/boot-framework.vdex (android.os.Looper.loop+986)
#18 pc 0000000000252fc0 /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.3783761849+488)
#19 pc 0000000000258ab4 /system/lib64/libart.so (art::interpreter::ArtInterpreterToInterpreterBridge(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame*, art::JValue*)+216)
#20 pc 00000000002792a0 /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+940)
#21 pc 0000000000525c14 /system/lib64/libart.so (MterpInvokeStatic+204)
#22 pc 0000000000547194 /system/lib64/libart.so (ExecuteMterpImpl+14612)
#23 pc 00000000003919ec /system/framework/boot-framework.vdex (android.app.ActivityThread.main+256)
#24 pc 0000000000252fc0 /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.3783761849+488)
#25 pc 0000000000514fa4 /system/lib64/libart.so (artQuickToInterpreterBridge+1020)
#26 pc 000000000055dafc /system/lib64/libart.so (art_quick_to_interpreter_bridge+92)
#27 pc 0000000000554c4c /system/lib64/libart.so (art_quick_invoke_static_stub+604)
#28 pc 00000000000cf6e8 /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+232)
#29 pc 000000000045c840 /system/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104)
#30 pc 000000000045e294 /system/lib64/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned long)+1440)
#31 pc 00000000003ee1d4 /system/lib64/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*)+52)
#32 pc 000000000011e6d4 /system/framework/arm64/boot-core-oj.oat (offset 0x114000) (java.lang.Class.getDeclaredMethodInternal [DEDUPED]+180)
#33 pc 0000000000554988 /system/lib64/libart.so (art_quick_invoke_stub+584)
#34 pc 00000000000cf6c8 /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+200)
#35 pc 000000000027f2b4 /system/lib64/libart.so (art::interpreter::ArtInterpreterToCompiledCodeBridge(art::Thread*, art::ArtMethod*, art::ShadowFrame*, unsigned short, art::JValue*)+344)
#36 pc 00000000002792bc /system/lib64/libart.so (bool art::interpreter::DoCall<false, false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, art::JValue*)+968)
#37 pc 0000000000524710 /system/lib64/libart.so (MterpInvokeVirtual+588)
#38 pc 0000000000547014 /system/lib64/libart.so (ExecuteMterpImpl+14228)
#39 pc 0000000000c3779e /system/framework/boot-framework.vdex (com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run+22)
#40 pc 0000000000252fc0 /system/lib64/libart.so (_ZN3art11interpreterL7ExecuteEPNS_6ThreadERKNS_20CodeItemDataAccessorERNS_11ShadowFrameENS_6JValueEb.llvm.3783761849+488)
#41 pc 0000000000514fa4 /system/lib64/libart.so (artQuickToInterpreterBridge+1020)
#42 pc 000000000055dafc /system/lib64/libart.so (art_quick_to_interpreter_bridge+92)
#43 pc 0000000000bf9920 /system/framework/arm64/boot-framework.oat (offset 0x3d0000) (com.android.internal.os.ZygoteInit.main+3088)
#44 pc 0000000000554c4c /system/lib64/libart.so (art_quick_invoke_static_stub+604)
#45 pc 00000000000cf6e8 /system/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+232)
#46 pc 000000000045c840 /system/lib64/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod*, art::(anonymous namespace)::ArgArray*, art::JValue*, char const*)+104)
#47 pc 000000000045c4a0 /system/lib64/libart.so (art::InvokeWithVarArgs(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, std::__va_list)+424)
#48 pc 0000000000361b60 /system/lib64/libart.so (art::JNI::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, std::__va_list)+652)
#49 pc 00000000000b2e24 /system/lib64/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+120)
#50 pc 00000000000b57a8 /system/lib64/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool)+756)
#51 pc 00000000000022f8 /system/bin/app_process64 (main+1380)
#52 pc 00000000000aca4c /system/lib64/libc.so (__libc_init+88)
Lost connection to device.
Exited (sigterm)
Thank you for helping a noob..
I'm trying to create a ListView but when I import the list_form.dart class i get this error. Maybe I made some mistakes with the layout because if I try to run it inside the main file I don't get this error.
This is the error:
I/flutter (12956): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (12956): The following assertion was thrown during performResize():
I/flutter (12956): Vertical viewport was given unbounded height.
I/flutter (12956): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter (12956): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter (12956): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter (12956): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter (12956): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter (12956): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter (12956): the height of the viewport to the sum of the heights of its children.
I/flutter (12956):
I/flutter (12956): When the exception was thrown, this was the stack:
I/flutter (12956): #0 RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:1133:15)
I/flutter (12956): #1 RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:1186:6)
I/flutter (12956): #2 RenderObject.layout (package:flutter/src/rendering/object.dart:1616:9)
I/flutter (12956): #3 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #4 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #5 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #6 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #7 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #8 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #9 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #10 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #11 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #12 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #13 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #14 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #15 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #16 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #17 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #18 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #19 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
I/flutter (12956): #20 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #21 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
I/flutter (12956): #22 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #23 RenderPositionedBox.performLayout (package:flutter/src/rendering/shifted_box.dart:381:13)
I/flutter (12956): #24 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #25 MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:141:11)
I/flutter (12956): #26 _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:339:7)
I/flutter (12956): #27 MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:211:7)
I/flutter (12956): #28 RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:355:14)
I/flutter (12956): #29 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #30 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #31 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #32 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #33 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1192:11)
I/flutter (12956): #34 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #35 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #36 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #37 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #38 _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1192:11)
I/flutter (12956): #39 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #40 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #41 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #42 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #43 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #44 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #45 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #46 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #47 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #48 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #49 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #50 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #51 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #52 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #53 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #54 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #55 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:2884:13)
I/flutter (12956): #56 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #57 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:520:15)
I/flutter (12956): #58 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #59 __RenderTheatre&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #60 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #61 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #62 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #63 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #64 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #65 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #66 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #67 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #68 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #69 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:108:13)
I/flutter (12956): #70 RenderObject.layout (package:flutter/src/rendering/object.dart:1631:7)
I/flutter (12956): #71 RenderView.performLayout (package:flutter/src/rendering/view.dart:147:13)
I/flutter (12956): #72 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1506:7)
I/flutter (12956): #73 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:765:18)
I/flutter (12956): #74 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:270:19)
I/flutter (12956): #75 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:674:13)
I/flutter (12956): #76 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
I/flutter (12956): #77 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (12956): #78 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (12956): #79 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:751:7)
I/flutter (12956): #81 _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
I/flutter (12956): #82 _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
I/flutter (12956): #83 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
I/flutter (12956): (elided one frame from package dart:async)
I/flutter (12956):
I/flutter (12956): The following RenderObject was being processed when the exception was fired:
I/flutter (12956): RenderViewport#925a8 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (12956): creator: Viewport ← _ScrollableScope ← IgnorePointer-[GlobalKey#8e8f7] ← Semantics ← Listener ←
I/flutter (12956): _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#67ae5] ←
I/flutter (12956): _ScrollSemantics-[GlobalKey#17eb8] ← RepaintBoundary ← CustomPaint ← RepaintBoundary ←
I/flutter (12956): NotificationListener<ScrollNotification> ← ⋯
I/flutter (12956): parentData: <none> (can use size)
I/flutter (12956): constraints: BoxConstraints(unconstrained)
I/flutter (12956): size: MISSING
I/flutter (12956): axisDirection: down
I/flutter (12956): crossAxisDirection: right
I/flutter (12956): offset: ScrollPositionWithSingleContext#c4917(offset: 0.0, range: null..null, viewport: null,
I/flutter (12956): ScrollableState, AlwaysScrollableScrollPhysics -> ClampingScrollPhysics, IdleScrollActivity#2fecf,
I/flutter (12956): ScrollDirection.idle)
I/flutter (12956): anchor: 0.0
I/flutter (12956): This RenderObject had the following descendants (showing up to depth 5):
I/flutter (12956): RenderSliverPadding#74d62 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (12956): RenderSliverList#5c56d NEEDS-LAYOUT NEEDS-PAINT
I/flutter (12956): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: RenderViewport#925a8 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: RenderViewport#925a8 NEEDS-PAINT
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#8bbda relayoutBoundary=up11 NEEDS-PAINT
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#209b4 relayoutBoundary=up10 NEEDS-PAINT
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#a9641 relayoutBoundary=up9 NEEDS-PAINT
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#9f5b4 relayoutBoundary=up8 NEEDS-PAINT
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#47944 relayoutBoundary=up7 NEEDS-PAINT
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#e17a8 relayoutBoundary=up6 NEEDS-PAINT
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#a2328 relayoutBoundary=up5 NEEDS-PAINT
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#02607 relayoutBoundary=up4 NEEDS-PAINT
I/flutter (12956): Another exception was thrown: RenderBox was not laid out: RenderFlex#79164 relayoutBoundary=up3 NEEDS-PAINT
I/flutter (12956): Another exception was thrown: 'package:flutter/src/rendering/shifted_box.dart': Failed assertion: line 310 pos 12: 'child.hasSize': is not true.
I/flutter (12956): Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
This is the list_form.dart class:
import 'package:flutter/material.dart';
class ListForm extends StatefulWidget {
#override
ListFormState createState() => new ListFormState();
}
class ListFormState extends State<ListForm> {
List<String> products = ["Test1", "Test2", "Test3"];
#override
Widget build(BuildContext context) {
return new Container(
child: new Center(
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new ListView.builder(
itemCount: products.length,
itemBuilder: (BuildContext ctxt, int index) {
return new Text(products[index]);
}
),
new IconButton(
icon: Icon(Icons.remove_circle),
onPressed: () { },
)
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
),
new TextField(
decoration: new InputDecoration(
hintText: "Prodotto"
),
onSubmitted: (String str) {
setState(() {
products.add(str);
});
},
),
]
)
)
);
}
}
This is the app_base.dart class:
import 'package:flutter/material.dart';
import '../UI/list_form.dart';
class AppBase extends StatefulWidget {
#override
State createState() => new AppBaseState();
}
class AppBaseState extends State<AppBase> {
bool _pressed = true;
#override
Widget build(BuildContext context) {
return new Material(
color: Colors.greenAccent,
child: new Scaffold(
body:
new ListForm(),
appBar: AppBar(
centerTitle: true,
title: const Text('Skeeper'),
backgroundColor: Colors.green,
),
floatingActionButton: FloatingActionButton(
tooltip: 'Test',
child: new Icon(Icons.add),
backgroundColor: Colors.green,
onPressed: () {
setState(() {
_pressed = !_pressed;
});
},
),
)
);
}
}
Don't worry if there is some unused code, it's a work in progress and this error just stopped me continuing what I was doing.
The problem is that you are placing the ListView inside a Column/Row. The text in the exception gives a good explanation of the error.
To avoid the error you need to provide a size to the ListView inside.
I propose you this code that uses an Expanded to inform the horizontal size (maximum available) and the SizedBox (Could be a Container) for the height:
new Row(
children: <Widget>[
Expanded(
child: SizedBox(
height: 200.0,
child: new ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: products.length,
itemBuilder: (BuildContext ctxt, int index) {
return new Text(products[index]);
},
),
),
),
new IconButton(
icon: Icon(Icons.remove_circle),
onPressed: () {},
),
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
)
,
You can add some code like this
ListView.builder{
shrinkWrap: true,
}
Reason for the error:
Column tries to expands in vertical axis, and so does the ListView, hence you need to constrain the height of ListView.
Solutions
Use either Expanded or Flexible if you want to allow ListView to take up entire left space in Column.
Column(
children: <Widget>[
Expanded(
child: ListView(...),
)
],
)
Use SizedBox if you want to restrict the size of ListView to a certain height.
Column(
children: <Widget>[
SizedBox(
height: 200, // constrain height
child: ListView(),
)
],
)
Use shrinkWrap, if your ListView isn't too big.
Column(
children: <Widget>[
ListView(
shrinkWrap: true, // use it
)
],
)
use shrinkWrap: true,
With shrinkWrap: true, you can change this behavior so that the ListView only occupies the space it needs (it will still scroll when there more items).
If you set it to true, the list will wrap its content and be as big as it children allows it to be.
like this.
ListView.builder(
shrinkWrap: true,
itemBuilder: (context, index) {
.........
}
)
Placing your list view in a Flexible widget may also help,
Flexible( fit: FlexFit.tight, child: _buildYourListWidget(..),)
I used this code to fix the issue of displaying items in the horizontal list.
new Container(
height: 20,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: array.length,
itemBuilder: (context, index){
return array[index];
},
),
],
),
);
Wrap your ListView in an Expanded widget
Expanded(child:MyListView())
I had a similir problem, but in my case, I put a row in the leading of the ListView, and it was consuming all the space, of course. I just had to take the Row out of the leading, and it was solved. I would recommend to check if the problem is a larger widget than its container can have.
Expanded(child:MyListView())
I had a simmilar problem, but in my case I was put a row in the leading of the Listview, and it was consumming all the space, of course. I just had to take the Row out of the leading, and it was solved. I would recomend to check if the problem is a widget larger than its containner can have.
My app started crashing with the same error just completely out of the blue.
I really appreciate the other answers mentioned here on this page. But none worked for me. I was on Flutter 2.0.0 and upgrading to Flutter 2.2.2 fixed the issue without changing anything in my existing code.
Expanded widget will fix that problem, mainly that error occurs when you user multiples widgets with dynamic sizes in a column or a row
You can Always resolve this error in one of the following three ways:
Wrap your ListView with Expanded widget.
Wrap your ListView with SizedBox and give it a specific height.
You can add below your listView this line: shrinkWrap: true,
In the case where you are using a Column/Row ensure to specify the size they should occupy e.g.
SizedBox(
height: 100,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
CircularProgressIndicator(),
SizedBox(
width: 15,
),
Expanded(
child: Text("Data Laoding"),
)
],
),
),
See, wrap with expanded, no matter of anything.
Flexible widget also sometimes doesn't works.
Hope, this will be helpful.
Rendering,
Parent widget error,
Assertion are basic errors.
This will catch fears in a programmer.
I had similar issue, I was using an SvgPicture widget inside a SizedBox widget and instead of specifying the height property in the SizedBox I did it inside the SvgPicture widget.
If that is your case, then I recommend you specify the height of the SizedBox.
Wrap the list view inside a Container and specify the width.
Column(
children: [
Container(
width: MediaQuery.of(context).size.width,
child: ListView.builder(..)
This will solve the issue.
I have a SliverAppBar with title and subtitle like this:
SliverAppBar(
backgroundColor: Colors.white,
forceElevated: true,
elevation: 1.0,
pinned: true,
floating: true,
snap: false,
title: Column(
children: <Widget>[
Container(padding: EdgeInsets.only(top: 6.0, bottom: 5.0),
child: Text('Contest', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w500))),
Text(_getFiltersString(), style: TextStyle(fontSize: 14.0, color: Colors.grey[700]),)
]),
It runs but if i scroll i receive this error:
I/flutter ( 4765): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 4765): The following message was thrown during layout:
I/flutter ( 4765): A RenderFlex overflowed by 30 pixels on the bottom.
I/flutter ( 4765):
I/flutter ( 4765): The overflowing RenderFlex has an orientation of Axis.vertical.
I/flutter ( 4765): The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
I/flutter ( 4765): black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
I/flutter ( 4765): Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
I/flutter ( 4765): RenderFlex to fit within the available space instead of being sized to their natural size.
I/flutter ( 4765): This is considered an error condition because it indicates that there is content that cannot be
I/flutter ( 4765): seen. If the content is legitimately bigger than the available space, consider clipping it with a
I/flutter ( 4765): ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
I/flutter ( 4765): like a ListView.
I/flutter ( 4765): The specific RenderFlex in question is:
I/flutter ( 4765): RenderFlex#968e7 relayoutBoundary=up14 OVERFLOWING
I/flutter ( 4765): creator: Column ← Semantics ← DefaultTextStyle ← LayoutId-[<_ToolbarSlot.middle>] ←
I/flutter ( 4765): CustomMultiChildLayout ← NavigationToolbar ← DefaultTextStyle ← IconTheme ← Builder ←
I/flutter ( 4765): CustomSingleChildLayout ← ClipRect ← ConstrainedBox ← ⋯
I/flutter ( 4765): parentData: <none> (can use size)
I/flutter ( 4765): constraints: BoxConstraints(0.0<=w<=176.0, 0.0<=h<=20.3)
I/flutter ( 4765): size: Size(70.0, 20.3)
I/flutter ( 4765): direction: vertical
I/flutter ( 4765): mainAxisAlignment: start
I/flutter ( 4765): mainAxisSize: max
I/flutter ( 4765): crossAxisAlignment: center
I/flutter ( 4765): verticalDirection: down
I/flutter ( 4765): ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
I/flutter ( 4765): ════════════════════════════════════════════════════════════════════════════════════════════════════
Reloaded 32 of 722 libraries in 2.887ms.
What i have to use instead of Column?
Thanks
This means that the widget is bigger than the view. Now what you can do is wrap the Column in a SingleChildScrollView to let it scroll:
SingleChildScrollView( child: Column(...) )
ringBuffers = [AudioQueueBufferRef](repeating: AudioQueueBufferRef(), count:inflightBuffersCount)
says init() is unavailable: use 'nil' literal
but if it is
ringBuffers = [AudioQueueBufferRef](repeating: nil, count: inflightBuffersCount)
it says
main.swift:152:29: Expression type '[AudioQueueBufferRef]' is ambiguous without more context
if it is
var ringBuffers = [AudioQueueBufferRef!](repeating:nil, count:3)
let status = AudioQueueAllocateBuffer(inQueue!, bufferSize, &ringBuffers[0])
print("\(status.description)")
prints
vm_map failed: 0x4 ((os/kern) invalid argument)
4
I think assigning nil is not right
Stream description I have used is
let inFormat = AudioStreamBasicDescription(
mSampleRate: Double(sampleRate),
mFormatID: kAudioFormatLinearPCM,
mFormatFlags: kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked,
mBytesPerPacket: UInt32(numChannels * MemoryLayout<UInt16>.size),
mFramesPerPacket: 1,
mBytesPerFrame: UInt32(numChannels * MemoryLayout<UInt16>.size),
mChannelsPerFrame: UInt32(numChannels),
mBitsPerChannel: UInt32(8 * (MemoryLayout<UInt16>.size)),
mReserved: UInt32(0)
)
AudioQueueNewOutput(&inFormat, AQOutputCallback, &player, nil, nil, 0, &inQueue)
You got this wrong ;) You don't need to allocate anything at all; the buffer will be created by the AudioQueueAllocateBuffer function you are calling.
For instance:
var buffer: AudioQueueBufferRef? = nil
let status = AudioQueueAllocateBuffer(inQueue!, bufferSize, &buffer)
I have the following dart code:
.dart
Future<int> currentMrn( ) async {
var rootRef = await firebaseClient;
var mrnRef = await rootRef.child( 'ids/mrn' );
var event = await mrnRef.onValue.first;
DataSnapshot ss = event.snapshot;
return ss.val( );
}
Future<int> nextMrn( ) async {
int curMrn = 0;
var rootRef = await firebaseClient;
Future<int> futureMrn = currentMrn( );
futureMrn.then( ( int value ) {
if ( value == null ) {
rootRef.child('ids/mrn').set(curMrn);
//futureMrn = Future.value([curMrn]);
}
else {
curMrn = value + 1;
rootRef.child('ids/mrn').set(curMrn);
//futureMrn = Future.value([curMrn]);
}
} );
return currentMrn( );
}
The code is called as such:
.dart
nextMrn().then((int value) {
print(value);
});
However, the printed value is ALWAYS 1 less than the value in firebase.
It seems that currentMrn() is not getting the new updated value.
I am using the dart firebase package at https://pub.dartlang.org/packages/firebase
Thanks for your help.
EDIT 1
Running the future.then (first version) of nextMrn() throws the following exception
Exception: Uncaught Error: The null object does not have a method 'cancel'.
NoSuchMethodError: method not found: 'cancel'
Receiver: null
Arguments: []
Stack Trace:
#0 Object._noSuchMethod (dart:core-patch/object_patch.dart:42)
#1 Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#2 _cancelAndValue (dart:async/stream_pipe.dart:58)
#3 Stream.first.<anonymous closure> (dart:async/stream.dart:937)
#4 _RootZone.runUnaryGuarded (dart:async/zone.dart:1104)
#5 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#6 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:270)
#7 _SyncBroadcastStreamController._sendData (dart:async/broadcast_stream_controller.dart:362)
#8 _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:237)
#9 Query._createStream.addEvent (package:firebase/src/firebase.dart:531:12)
#10 JsObject._callMethod (dart:js:678)
#11 JsObject.callMethod (dart:js:618)
#12 Query._createStream.startListen (package:firebase/src/firebase.dart:539:11)
#13 _runGuarded (dart:async/stream_controller.dart:769)
#14 _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:199)
#15 _ControllerStream._createSubscription (dart:async/stream_controller.dart:787)
#16 _StreamImpl.listen (dart:async/stream_impl.dart:474)
#17 Stream.first (dart:async/stream.dart:935)
#18 currentMrn.<currentMrn_async_body> (package:epimss_shared/src/epimss_shared_db_client.dart:34:36)
#19 _RootZone.runUnary (dart:async/zone.dart:1166)
#20 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:494)
#21 _Future._propagateToListeners (dart:async/future_impl.dart:577)
#22 _Future._completeWithValue (dart:async/future_impl.dart:368)
#23 _Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:422)
#24 _microtaskLoop (dart:async/schedule_microtask.dart:43)
#25 _microtaskLoopEntry (dart:async/schedule_microtask.dart:52)
#26 _ScheduleImmediateHelper._handleMutation (dart:html:42529)
Line #18 above refers to the
var event = await mrnRef.onValue.first;
line in the currentMrn() method. Seems like an attempt is made to cancel an event. Not certain.
EDIT 2
Because all prior attempts returns an integer 1 less than is expected, I have included the code for currentMrn() directly in nextMrn() as follows:
Future<int> currentMrn( ) async {
var rootRef = await firebaseClient;
var mrnRef = await rootRef.child( 'ids/mrn' );
var event = await mrnRef.onValue.first;
DataSnapshot ss = event.snapshot;
return ss.val( );
}
Future<int> nextMrn( ) async {
var curMrn = 0;
var rootRef = await firebaseClient;
var mrnRef = await rootRef.child( 'ids/mrn' );
var event = await mrnRef.onValue.first;
DataSnapshot ss = event.snapshot;
var value = ss.val( );
if ( value == null ) {
curMrn += curMrn + 1;
rootRef.child( 'ids/mrn' ).set( curMrn );
}
else {
curMrn = value + 1;
rootRef.child( 'ids/mrn' ).set( curMrn );
}
return curMrn;
//TODO correct Bad state: Cannot fire new event. Controller is already firing an event
}
This correctly returns the expected value when nextMrn() is invoked. However, it throws the exception below:
FIREBASE WARNING: Exception was thrown by user callback.
Uncaught Unhandled exception:
Bad state: Cannot fire new event. Controller is already firing an event
#0 _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:236)
#1 Query._createStream.addEvent (package:firebase/src/firebase.dart:531:12)
#2 JsObject._callMethod (dart:js:678)
#3 JsObject.callMethod (dart:js:618)
#4 Firebase.set (package:firebase/src/firebase.dart:258:9)
#5 nextMrn.<nextMrn_async_body> (package:epimss_shared/src/epimss_shared_db_client.dart:56:38)
#6 _RootZone.runUnary (dart:async/zone.dart:1166)
#7 _Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:494)
#8 _Future._propagateToListeners (dart:async/future_impl.dart:577)
#9 _Future._complete (dart:async/future_impl.dart:358)
#10 _cancelAndValue (dart:async/stream_pipe.dart:62)
#11 Stream.first.<anonymous closure> (dart:async/stream.dart:937)
#12 _RootZone.runUnaryGuarded (dart:async/zone.dart:1104)
#13 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341)
#14 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:270)
#15 _SyncBroadcastStreamController._sendData (dart:async/broadcast_stream_controller.dart:362)
#16 _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:237)
#17 Query._createStream.addEvent (package:firebase/src/firebase.dart:531:12)
(anonymous function)
that points to the following line in the refactored nextMrn()
rootRef.child( 'ids/mrn' ).set( curMrn );
Two questions:
1. How is this corrected.
2. How do I catch an error in the nextMrn()?
Thanks
Future<int> nextMrn( ) async {
int curMrn = 0;
var rootRef = await firebaseClient;
Future<int> futureMrn = currentMrn( );
// missing return leads to broken future chain
return futureMrn.then( ( int value ) {
if ( value == null ) {
rootRef.child('ids/mrn').set(curMrn);
//futureMrn = Future.value([curMrn]);
}
else {
curMrn = value + 1;
rootRef.child('ids/mrn').set(curMrn);
//futureMrn = Future.value([curMrn]);
}
// add the actual return in the chain to ensure
// id doesn't return before the calculation is completed
}).then((_) => currentMrn( );
}
or with async/await
Future<int> nextMrn( ) async {
int curMrn = 0;
var rootRef = await firebaseClient;
var futureMrn = currentMrn( );
var value = await futureMrn;
if ( value == null ) {
rootRef.child('ids/mrn').set(curMrn);
//futureMrn = Future.value([curMrn]);
}
else {
curMrn = value + 1;
rootRef.child('ids/mrn').set(curMrn);
//futureMrn = Future.value([curMrn]);
}
return currentMrn( );
}
I couldn't really figure out what exactly the intention of your code is. Hope it works anyway.