dart-async

array of items as state in a StatefulWidget & ensuring “setState” only triggers updates for items in the array that has changed?

寵の児 提交于 2021-02-11 17:35:46
问题 Background - want to utilise a dynamic list of items for a StatefulWidget. In my usecase the widget will be calling a CustomePainter (canvas) so sometimes there will be a varying number of images to be drawn on the canvas, hence within parent StatefulWidget would like to have an "array of images". Question - if using an array as the state variable what do I need to do programmtically (if anything) to ensure only the items that have changed within the array do infact get "redrawn", in

How to wait until image(s) loaded in Dart

丶灬走出姿态 提交于 2021-02-10 23:53:20
问题 I have some basic code to load some sprite images, I am using Future.wait to wait until both images are loaded. However this still does not what I exactly want to do, Because I want to assign image width and height to members before It exits. SpaceShip(this.x, this.y) { rocket = new ImageElement(src: "nofire.png"); firingRockets = new ImageElement(src: "fire.png"); var futures = [rocket.onLoad.first, firingRockets.onLoad.first]; Future.wait(futures).then((_) { width = rocket.width; height =

How to wait until image(s) loaded in Dart

ぐ巨炮叔叔 提交于 2021-02-10 23:46:19
问题 I have some basic code to load some sprite images, I am using Future.wait to wait until both images are loaded. However this still does not what I exactly want to do, Because I want to assign image width and height to members before It exits. SpaceShip(this.x, this.y) { rocket = new ImageElement(src: "nofire.png"); firingRockets = new ImageElement(src: "fire.png"); var futures = [rocket.onLoad.first, firingRockets.onLoad.first]; Future.wait(futures).then((_) { width = rocket.width; height =

How to wait until image(s) loaded in Dart

拜拜、爱过 提交于 2021-02-10 23:42:55
问题 I have some basic code to load some sprite images, I am using Future.wait to wait until both images are loaded. However this still does not what I exactly want to do, Because I want to assign image width and height to members before It exits. SpaceShip(this.x, this.y) { rocket = new ImageElement(src: "nofire.png"); firingRockets = new ImageElement(src: "fire.png"); var futures = [rocket.onLoad.first, firingRockets.onLoad.first]; Future.wait(futures).then((_) { width = rocket.width; height =

flutter bloc and how a bloc state change can then trigger a 2nd async call before updating the Widget/UI with both? (code attached)

此生再无相见时 提交于 2021-01-29 15:32:52
问题 How would one load a set of local images for display in a widget (noting this is async - see function below) triggered by (based on) a change in state from a flutter_bloc for “settings”? Noting this bloc is persisted too via hydrated_bloc. So the use case for which I’m asking how do I code this in flutter (noting I’m using flutter_bloc) is: Use Case - Render different set of images on the same Widget I have for dynamically displaying a room for a 2D point & click adventure type game, BASED ON

Getting 'Future<Image>' can't be assigned to a variable of type 'Image' in this Flutter/Dart code?

牧云@^-^@ 提交于 2021-01-29 09:25:27
问题 I'm trying create a function to load images in Flutter (Dart) but not sure how to get this code working. I'm getting: A value of type 'Future' can't be assigned to a variable of type 'Image'. Try changing the type of the variable, or casting the right-hand type to 'Image'. import 'dart:typed_data'; import 'dart:ui' as ui; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build

Dart event queue and microtask

醉酒当歌 提交于 2020-12-29 04:01:35
问题 i am trying to understand, how dart event loop works. I read the event loop article from the website The Event Loop and Dart and the author explain pretty good how event loop in dart works. But what i don't understand is, how event get queue. For example new Future(() => 21) .then((v) => v*2) .then((v) => print(v)); Will here dart gonna create three entries in the event queue or just one? I know, that the class Future is responsible for delay execution and when i create an object from it like

How do you get the current stacktrace in Dart for a Completer.CompleteException(exception, stackTrace);

有些话、适合烂在心里 提交于 2020-03-18 03:25:30
问题 If some code returns a future and determines that the future should return "Error" or "Exception" how can a stack trace be passed to Completer.completeException(exception, stackTrace); 回答1: If I understand correctly: when you catch an exception in dart, you can also catch the stack trace: try { // something } catch(e, stacktrace) { myCompleter.completeException(e, stacktrace); } 回答2: If you're not in a catch block, you can use StackTrace.current 来源: https://stackoverflow.com/questions

Flutter - setState not updating inner Stateful Widget

馋奶兔 提交于 2020-02-26 07:02:48
问题 Basically I am trying to make an app whose content will be updated with an async function that takes information from a website, but when I do try to set the new state, it doesn't reload the new content. If I debug the app, it shows that the current content is the new one, but after "rebuilding" the whole widget, it doesn't show the new info. Edit: loadData ( ) method, basically read a URL with http package, the URL contains a JSON file whose content changes every 5 minutes with new news. For

Flutter - setState not updating inner Stateful Widget

杀马特。学长 韩版系。学妹 提交于 2020-02-26 07:02:09
问题 Basically I am trying to make an app whose content will be updated with an async function that takes information from a website, but when I do try to set the new state, it doesn't reload the new content. If I debug the app, it shows that the current content is the new one, but after "rebuilding" the whole widget, it doesn't show the new info. Edit: loadData ( ) method, basically read a URL with http package, the URL contains a JSON file whose content changes every 5 minutes with new news. For