The first item is broken when I scroll back - dart

I try to make a hacker news reader. I get an error but I am not quite sure what is going on.
When I try to do the following step, the first item is vanishing and get some error log to tell me '_debugSubtreeRelayoutRootAlreadyMarkedNeedsLayout()': is not true.
Scroll up the list.
Scroll down the list to the top.
It looks like this
And I also upload the demo if it is helpful.
https://github.com/keeweeChang/flutter_news/tree/list_error
And here is the git to show the error situation.
https://media.giphy.com/media/XKGJrdAvgLcy9zyJwM/giphy.gif
Error log: I/flutter (30902): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (30902): The following assertion was thrown building
FutureBuilder(state:
I/flutter (30902): _FutureBuilderState#fd3d0):
I/flutter (30902): 'package:flutter/src/rendering/object.dart': Failed
assertion: line 1409 pos 14:
I/flutter (30902):
'_debugSubtreeRelayoutRootAlreadyMarkedNeedsLayout()': is not true.
I/flutter (30902):
I/zygote (30902): Do partial code cache collection, code=59KB,
data=43KB
I/flutter (30902): Either the assertion indicates an error in the
framework itself, or we should provide substantially
I/flutter (30902): more information in this error message to help you
determine and fix the underlying cause.
I/flutter (30902): In either case, please report this assertion by
filing a bug on GitHub:
I/flutter (30902):
https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (30902):
I/flutter (30902): When the exception was thrown, this was the stack:
I/flutter (30902): #2 RenderObject.markNeedsLayout
(package:flutter/src/rendering/object.dart:1409:14)
I/flutter (30902): #3 RenderBox.markNeedsLayout
(package:flutter/src/rendering/box.dart:1842:11)
I/flutter (30902): #4 RenderObject.dropChild
(package:flutter/src/rendering/object.dart:1158:5)
I/flutter (30902): #5
_RenderProxyBox&RenderBox&RenderObjectWithChildMixin.child= (package:flutter/src/rendering/object.dart:2744:7)
I/flutter (30902): #6
SingleChildRenderObjectElement.removeChildRenderObject
(package:flutter/src/widgets/framework.dart:4909:18)
I/flutter (30902): #7 RenderObjectElement.detachRenderObject
(package:flutter/src/widgets/framework.dart:4749:36)
I/flutter (30902): #8 Element.detachRenderObject.
(package:flutter/src/widgets/framework.dart:2866:13)
I/flutter (30902): #9 ComponentElement.visitChildren
(package:flutter/src/widgets/framework.dart:3775:14)
I/flutter (30902): #10 Element.detachRenderObject
(package:flutter/src/widgets/framework.dart:2865:5)
I/flutter (30902): #11 Element.deactivateChild
(package:flutter/src/widgets/framework.dart:2995:11)
I/flutter (30902): #12 Element.updateChild
(package:flutter/src/widgets/framework.dart:2760:7)
I/flutter (30902): #13 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:3752:16)
I/flutter (30902): #14 Element.rebuild
(package:flutter/src/widgets/framework.dart:3564:5)
I/flutter (30902): #15 BuildOwner.buildScope
(package:flutter/src/widgets/framework.dart:2277:33)
I/zygote (30902): After code cache collection, code=59KB, data=43KB
I/zygote (30902): Increasing code cache capacity to 256KB
I/flutter (30902): #16
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame
(package:flutter/src/widgets/binding.dart:700:20)
I/flutter (30902): #17
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback
(package:flutter/src/rendering/binding.dart:275:5)
I/flutter (30902): #18
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback
(package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (30902): #19
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame
(package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (30902): #20
_WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame
(package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (30902): #24 _invoke (dart:ui/hooks.dart:209:10)
I/flutter (30902): #25 _drawFrame (dart:ui/hooks.dart:168:3)
I/flutter (30902): (elided 5 frames from class _AssertionError and
package dart:async)
I/flutter (30902): ═══════════════════════════════════
I/flutter (30902): Another exception was thrown:
'package:flutter/src/rendering/object.dart': Failed assertion: line
1153 pos 12: 'child.parentData != null': is not true.
I/flutter (30902): Another exception was thrown: NoSuchMethodError:
The getter 'debugDoingLayout' was called on null.
I/flutter (30902): Another exception was thrown: RenderBox was not
laid out: _RenderListTile#46ebb relayoutBoundary=up5 NEEDS-PAINT
DETACHED
I/flutter (30902): Another exception was thrown: RenderBox was not
laid out: RenderPadding#0a187 relayoutBoundary=up4 NEEDS-PAINT
DETACHED
I/flutter (30902): Another exception was thrown: RenderBox was not
laid out: RenderSemanticsAnnotations#d9f7e relayoutBoundary=up3
NEEDS-PAINT DETACHED
I/flutter (30902): Another exception was thrown: RenderBox was not
laid out: RenderPointerListener#e0701 relayoutBoundary=up2 NEEDS-PAINT
DETACHED
I/flutter (30902): Another exception was thrown: RenderBox was not
laid out: RenderSemanticsGestureHandler#57551 relayoutBoundary=up1
NEEDS-PAINT DETACHED
I/flutter (30902): Another exception was thrown: RenderBox was not
laid out: RenderFlex#915e5 NEEDS-PAINT DETACHED
I/flutter (30902): Another exception was thrown: NoSuchMethodError:
The method '<=' was called on null.
Flutter doctor • Flutter version 1.3.8 at /Users/louis/flutter/flutterSDK
• Framework revision e5b1ed7a7f (13 days ago), 2019-03-06 14:23:37
-0800
• Engine revision f4951df193
• Dart version 2.2.1 (build 2.2.1-dev.0.0 571ea80e11)
Update
According to my test, the error is solved when I use a fixed height Container to wrap the Item. But I want to ask the ListView item is not supported dynamic height widget or any options I should be set. Or it is an issue in debug mode?
Here is the issue solved widget structure:
Widget Structure
The issue can be solved like this:
#override
Widget build(BuildContext context) {
final bloc = StoriesProvider.of(context);
return StreamBuilder(
stream: bloc.items,
builder: (context, AsyncSnapshot<Map<int, Future<ItemModel>>> snapshot) {
return Container(
height: 80,
child: buildItem(snapshot),
);
},
);
}
Widget buildItem(AsyncSnapshot<Map<int, Future<ItemModel>>> snapshot) {
if (!snapshot.hasData) {
...(Create loading widget)
}
else {
...(Create ListTile widget by FutureBuilder)
}
}

Related

calling Firebase.initializeApp() but still receive an error stating No Firebase App has been created, ONLY when using ios simulator

I have initialized Firebase in different ways.
1.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
#override
void initState() {
super.initState();
Firebase.initializeApp().whenComplete(() {
print("completed");
setState(() {});
});
}
including using FirebaseOption and adding appId, apiKey, projectId, messgingSenderId(dummy id)
//Using a FutureBuilder
atm these libraries are present:
firebase_core: ^1.10.6
firebase_auth: ^3.3.7
cloud_firestore: ^3.1.8
firebase_database: ^9.0.6
firebase_core_platform_interface: ^4.2.4
GogleService-Info.plsit is under flutterProject>ios>Runner
added via Xcode
I'm using a mac
Podfile has platform: ios, '11.0'
printing snapshot.connectionState = waiting & done
I receive an error when trying to persist to the database
I'm using FireStore Database
when trying to persist to the database using the Andriod emulator, I do not receive an error. obj is persisted.
but when trying to persist the same obj using the ios simulator I receive this error:
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
When the exception was thrown, this was the stack:
#0 MethodChannelFirebase.app (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:159:5)
#1 Firebase.app (package:firebase_core/src/firebase.dart:55:41)
#2 FirebaseFirestore.instance (package:cloud_firestore/src/firestore.dart:27:21)
#3 _firestore (package:flutter_shopping_app_fraire/providers/products.dart:6:56)
#4 _firestore (package:flutter_shopping_app_fraire/providers/products.dart)
#5 Products.addProduct (package:flutter_shopping_app_fraire/providers/products.dart:71:5)
#6 _EditProductScreenState._saveForm (package:flutter_shopping_app_fraire/screens/edit_product_screen.dart:111:53)
#7 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:989:21)
#8 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:198:24)
#9 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:608:11)
#10 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5)
#11 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:230:7)
#12 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:563:9)
#13 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:94:12)
#14 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:139:9)
#15 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:539:8)
#16 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:137:18)
#17 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:123:7)
#18 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:439:19)
#19 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:419:22)
#20 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:322:11)
#21 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:374:7)
#22 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:338:5)
#23 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:296:7)
#24 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:279:7)
#28 _invoke1 (dart:ui/hooks.dart:170:10)
#29 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:331:7)
#30 _dispatchPointerDataPacket (dart:ui/hooks.dart:94:31)
(elided 3 frames from dart:async)
Handler: "onTap"
Recognizer: TapGestureRecognizer#32df4
debugOwner: GestureDetector
state: possible
won arena
finalPosition: Offset(372.7, 95.0)
finalLocalPosition: Offset(30.7, 48.0)
button: 1
sent tap down
If you have followed all necessary implementation from google docs. Just do the following. I've faced the same issue. Adding options fixed mine.
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
Not sure exactly where I went wrong when implementing firebase/firestore into my flutter project(I was doing everything manually), but I got the ios simulator to connect with firestore database by registering my ios app using FlutterFire CLI.
so instead of manually creating a new firebase project, and registering my ios and android apps through my firebase console, I installed Firebase CLI to my project, then installed FlutterFire CLI and ran flutterfire configure, You go through a couple prompts. That created my project and also registered my apps.
It was really that simple and now both of my ios and andriod can reach the database.

Facings issues with Camera 0.2.0 and flutter 0.9.0

I am trying to setup camera 0.2.0 with flutter 0.9.0 in order to make app cater non AndroidX mobiles but I am facing weird error. I was not getting this error in the latest stable version of flutter.
My main.dart code file is
import 'package:flutter/material.dart';
import './app/alert_on_crises.dart';
import 'package:flutter/services.dart';
import 'package:camera/camera.dart';
import 'dart:async';
List<CameraDescription> cameras;
Future<void> main() async {
// SystemChrome.setPreferredOrientations([
// DeviceOrientation.portraitUp,
// DeviceOrientation.portraitDown
// ]);
cameras = await availableCameras();
runApp(new AlertOnCrises(cameras));
}
And app logs when it starts
E/flutter (12582):
[ERROR:topaz/lib/tonic/logging/dart_error.cc(16)]
Unhandled exception:
E/flutter (12582): NoSuchMethodError: Attempted to use type
'CameraDescription' as a function. Since types do not define a method
'call', this is not possible. Did you intend to call the
CameraDescription constructor and forget the 'new' operator?
E/flutter (12582): Receiver: CameraDescription
E/flutter (12582): Tried calling: CameraDescription(lensDirection:
Instance of 'CameraLensDirection', name: "0")
E/flutter (12582): #0 Object.noSuchMethod (dart:core-
patch/dart:core/object_patch.dart:46)
E/flutter (12582): #1 availableCameras.
(package:camera/camera.dart:55)
E/flutter (12582): #2 MappedListIterable.elementAt
(dart:_internal/iterable.dart:414)
E/flutter (12582): #3 ListIterable.toList
(dart:_internal/iterable.dart:219)
E/flutter (12582): #4 availableCameras (package:camera/camera.dart:59)
E/flutter (12582):
E/flutter (12582): #5 main
(file:///home/nishant/alert_on_crises/lib/main.dart:13)
E/flutter (12582):
E/flutter (12582): #6 _startIsolate. (dart:isolate-
patch/dart:isolate/isolate_patch.dart:279)
E/flutter (12582): #7 _RawReceivePortImpl._handleMessage
(dart:isolate-
patch/dart:isolate/isolate_patch.dart:165)
Syncing files to device vivo 1723... 5.8s
fire To hot reload your app on the fly, press "r". To restart the app
entirely, press "R".
An Observatory debugger and profiler on vivo 1723 is available at:
http://127.0.0.1:8101/
For a more detailed help message, press "h". To quit, press "q".

Flutter Throws NEEDS-PAINT on Everything?

everyone.
I'm currently in a time crunch to try and build an app in Flutter, and I've run into a slight problem. My app, after I implemented some code written by a colleague, is throwing a NEEDS-PAINT exception when I reach the TeamState state.
Here's a link to a Git repo that contains all our code in Main.dart.
Any and all help is greatly appreciated.
EDIT: Full error...
I/flutter (14688): Another exception was thrown: RenderBox was not laid out: RenderPointerListener#e1773 relayoutBoundary=up7 NEEDS-PAINT
Could be https://github.com/flutter/flutter/issues/27356
which happens when the text passed to Text(...) is empty.
Changing such code to
text?.isEmpty ?? false ? Container() : Text(text)
should fix it.

Flutter - 'Window_sendPlatformMessage' (4 arguments) cannot be found

I am developing an app with Flutter that takes an image and allows the user to save it in the gallery.
I am using image_picker_saver plugin to save it.
In the beginning I was calling the method to save the image in the main thread but I realized that was really slow and now I am trying to put it in a new isolated thread, but I am getting the same error all the time, so, my question is: How can I call the method to save the image in a new isolated thread?
My code looks like this:
Main.dart
class _AkkaMark extends State<CameraUpload>{
.
.
.
void _clickSaveImage() {
compute(saveImage, _imageFile).then((Future<String> futurePath) {
futurePath.then((String path){
_imageFile = new File(path);
});
});
}
.
.
.
}
toCompute.dart
Future<String> saveImage(File image) async {
return await ImagePickerSaver.saveFile(fileData: image.readAsBytesSync());
}
I tried to change the code trying to locate the error but is always the same:
E/flutter (22602): [ERROR:flutter/runtime/dart_isolate.cc(717)] Isolate (413787440) 'main.dart:_spawn()' exited with an error
E/flutter (22602): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (22602): error: native function 'Window_sendPlatformMessage' (4 arguments) cannot be found
E/flutter (22602): #0 Window.sendPlatformMessage (dart:ui/window.dart:811:9)
E/flutter (22602): #1 BinaryMessages._sendPlatformMessage (package:flutter/src/services/platform_messages.dart:40:15)
E/flutter (22602): #2 BinaryMessages.send (package:flutter/src/services/platform_messages.dart:88:12)
E/flutter (22602): #3 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:286:49)
E/flutter (22602): <asynchronous suspension>
E/flutter (22602): #4 ImagePickerSaver.saveFile (package:image_picker_saver/image_picker_saver.dart:77:38)
E/flutter (22602): <asynchronous suspension>
E/flutter (22602): #5 saveImage (package:AKKAmark/toCompute.dart:113:35)
E/flutter (22602): <asynchronous suspension>
E/flutter (22602): #6 _IsolateConfiguration.apply (package:flutter/src/foundation/isolates.dart:88:16)
E/flutter (22602): #7 _spawn.<anonymous closure> (package:flutter/src/foundation/isolates.dart:96:30)
E/flutter (22602): #8 Timeline.timeSync (dart:developer/timeline.dart:168:22)
E/flutter (22602): #9 _spawn (package:flutter/src/foundation/isolates.dart:93:12)
E/flutter (22602): #10 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:292:17)
E/flutter (22602): #11 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
Someone has any clue? Thanks in advance
Edit
I put the question on GitHub and basically plugins only can be used in the main UI thread.
'Window_sendPlatformMessage' (4 arguments) cannot be found
I put the question on GitHub and basically plugins only can be used in the main UI thread.
'Window_sendPlatformMessage' (4 arguments) cannot be found
You can try using https://pub.dev/packages/flutter_isolate to spawn an isolate that supports Flutter plugins.

Xcode address sanitizer issue with `UIImage imageNamed:#""`

When activating address sanitizer in Xcode 8, I do get an issue at the following line of code:
UIImage *myImage = [UIImage imageNamed:imageName];
imageName is an NSString, the according image exists in #1x, #2x,
#3x. The address sanitizer issue:
=================================================================
==2484==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x01d37310 in thread T0
#0 0x1fff73 in wrap_free (/private/var/mobile/Containers/Bundle/Application/C92A762E-DAAF-46D9-857B-151BAF97D0BB/Example.app/Frameworks/libclang_rt.asan_ios_dynamic.dylib+0x32f73)
#1 0x2b50fab5 in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x2ab5)
#2 0x2b50fbe5 in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x2be5)
#3 0x2b5463e1 in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x393e1)
#4 0x2b548307 in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x3b307)
#5 0x2b548233 in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x3b233)
#6 0x2b5606db in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x536db)
#7 0x2b560233 in (/System/Library/PrivateFrameworks/CoreUI.framework/CoreUI+0x53233)
#8 0x2924b611 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x632611)
#9 0x2924b375 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x632375)
#10 0x2924baf3 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x632af3)
#11 0x28eaf8bd in (/System/Library/Frameworks/UIKit.framework/UIKit+0x2968bd)
#12 0x28d46e45 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x12de45)
#13 0x76c4d1 in -[MyClass myMethod] (/private/var/mobile/Containers/Bundle/Application/C92A762E-DAAF-46D9-857B-151BAF97D0BB/Example.app/Frameworks/XY.framework/XY+0x2e4d1)
#16 0x28c2874b in (/System/Library/Frameworks/UIKit.framework/UIKit+0xf74b)
#17 0x28c284bb in (/System/Library/Frameworks/UIKit.framework/UIKit+0xf4bb)
#18 0x28c2e5e5 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x155e5)
#19 0x28c2bf5d in (/System/Library/Frameworks/UIKit.framework/UIKit+0x12f5d)
#20 0x28c9707f in (/System/Library/Frameworks/UIKit.framework/UIKit+0x7e07f)
#21 0x28e8a505 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x271505)
#22 0x28e8cacd in (/System/Library/Frameworks/UIKit.framework/UIKit+0x273acd)
#23 0x28e977a7 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x27e7a7)
#24 0x28e8b285 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x272285)
#25 0x2c09aebf in (/System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices+0x15ebf)
#26 0x2558e253 in (/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0xd0253)
#27 0x2558d517 in (/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0xcf517)
#28 0x2558c071 in (/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0xce071)
#29 0x254d799f in CFRunLoopRunSpecific (/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0x1999f)
#30 0x254d77b1 in CFRunLoopRunInMode (/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation+0x197b1)
#31 0x28c8da55 in (/System/Library/Frameworks/UIKit.framework/UIKit+0x74a55)
#32 0x28c88633 in UIApplicationMain (/System/Library/Frameworks/UIKit.framework/UIKit+0x6f633)
#34 0x34020aad in (/usr/lib/system/libdyld.dylib+0x1aad)
0x01d37310 is located 0 bytes inside of 34-byte region [0x01d37310,0x01d37332)
When I use a non-existing imageName, then the address sanitizer has no problem with that line.
The problem only seems to affect iOS 8, address sanitizer has no problems on iOS 9 and iOS 10 (latest beta). On iOS 8 it also works when I don't put the image in an asset but directly into the bundle.
This seems to be a bug in Xcode 8 Beta 6 (8S201h).
When setting the Deployment Target of your App to iOS 8.3 calling UIImage imageNamed: will crash when the referenced image is coming from an asset catalog. Using UIImage imageNamed:inBundle:compatibleWithTraitCollection: will not make a difference.
Workarounds:
Set the deployment target < iOS 8.3. iOS 8.0/.1/.2 works for me, 8.3/.4 keeps crashing
put the image directly in the apps bundle, not an asset catalog
An example project for this issue can be found on GitHub

Resources