324 questions
1
vote
2
answers
83
views
FutureBuilder doesn't build widget as expected
I've been trying to solve this problem for a couple of days now, but to no avail. I have a simple app with three tabs:
Deliveries Page: Has a DropdownMenuFormField (basically just a DropdownMenu with ...
0
votes
1
answer
148
views
Dart Isolate Error: Illegal argument in isolate message: object is unsendable
I'm trying to use Dart isolates to offload JSON parsing in my Flutter package. However, when I run the following function, I get an error about an "unsendable object" in isolate messages.
...
1
vote
1
answer
54
views
Why does piping nullable stream into a non-nullable stream controller cause a runtime but not a compile-time error?
The following code compiles:
import 'dart:async';
void main() {
final streamNullable = StreamController<int?>();
final streamNotNullable = StreamController<int>();
streamNullable....
1
vote
1
answer
77
views
`extension FutureIterable<T>.wait` does not work properly in Dart/Flutter
extension FutureIterable<T>.wait does not work properly
from the documentation:
/// Similar to [Future.wait], but reports errors using a
/// [ParallelWaitError], which allows the caller to
/// ...
1
vote
1
answer
144
views
How does dart event loop handle Streams?
Streams are meant to handle asynchronous flow of data which keeps on emitting data, but I want to understand how these streams are handled by event loop and where do they exist in main memory.
In a ...
1
vote
1
answer
198
views
Concurrency in Flutter Bloc: why is the state not propagating through multiple subsequent async functions?
I'm using Flutter with flutter_bloc, and I'm in front of the following scenario.
Scenario
I have a Cubit with two methods beings loadFoo and loadBar:
class UserCubit extends Cubit<UserState> {
...
2
votes
1
answer
131
views
Multiple async throws result in unhandled exception
I have an async method which in turn calls some other async methods which can throw errors.
The problem is that the try-catch only handles the first exception thrown.
I'm assuming that once a function ...
0
votes
0
answers
59
views
Dart Stream Future.delayed incorrect delay
I'm trying to make a Stream modifier function which adds 'latency' to all items going through it:
extension SE<T> on Stream<T> {
Stream<T> delayed(Duration latency) {
return ...
0
votes
0
answers
101
views
Why does Dart Stream Controller return different streams from its "stream" getter?
I'm working with dart as part of a hobby project and I found something kind of strange, namely the StreamController class as part of the Dart:async library returns different streams each time you call ...
1
vote
1
answer
678
views
How to cancel Future.wait (in dart)?
I have two Future functions which I run asynchronously:
List<Future<bool>> jobs = [];
jobs.add(asyncFunction1());
jobs.add(asyncFunction2());
jobsResults = await Future.wait(jobs);
If ...
0
votes
1
answer
90
views
Dart: `return future` vs `async return future`
I'm running this code:
import 'dart:async';
void main() {
final c = Future.value(); // Other constructors and `Completer.future` all yield same results.
print(c == sync(c));
print(c == aSync(...
1
vote
1
answer
141
views
Capture all futures in a Zone
In Dart is there any way to capture all Future's created inside a Zone?
Currently, I'm forced to manually capture them all, but this seems prone to forgetting to do it. So I want to automate this if ...
0
votes
1
answer
96
views
Using FutureBuilder in ConsumerStatefulWidget class causes error
I am trying to use a FutureBuilder with a ListView to display a list of documents from a Firestore db. I am getting errors saying the future: is not defined and the builder: is not defined. I also get ...
0
votes
1
answer
148
views
How to create a matcher that verifies an async callback is doing right thing?
I would like to create a matcher that takes async or non-async callback, sets up some listeners, invokes callback, verifies listeners received expected events, and then clean up listeners.
However, I ...
1
vote
2
answers
1k
views
What is the difference between using unawaited and not using unawaited in flutter/dart?
I've just stumbled upon a github repo containing an example of flutter application for google_sign_in package.
I'm confused about a particular usage of unawaited used inside the example :
Future<...
2
votes
1
answer
3k
views
Flutter integration tests - how to ignore exceptions thrown inside `Timer` callbacks?
I'm trying to write a test for an app which isn't well-implemented, and has an exception that is thrown inside a Timer callback. I'd like to ignore that exception inside my integration test, because I'...
1
vote
2
answers
1k
views
The value of expression of type 'void' can't be used in then()
How to fix this kind of errors when using then?
void handleSubmitWrapper() {
final future = handleSubmit();
future.then(context.loaderOverlay.hide()); // error
}
Future<void> handleSubmit() ...
1
vote
1
answer
312
views
Why is the `await` keyword often omitted when using the shared_preferences plugin?
While using shared prefs plugin it's common to explore code like below
void saveList() async {
final prefs = await SharedPreferences.getInstance();
prefs.setStringList("listKey", aList); ...
0
votes
1
answer
242
views
Why is my function preventing the dialog dismiss/pop in Flutter?
I am trying to execute a function after a dialog is dismissed/popped. I read this article How to run code after showDialog is dismissed in Flutter? and tried to do it as recommended but it wouldn't ...
0
votes
2
answers
285
views
Flutter, how to return different widget based on future value?
I would like to base on a future bool value, to set different icons pass back to a data card inside a list, I tried .then or FutureBuilder, but still not successful.
Scaffold:
child: ListView.builder(
...
16
votes
2
answers
4k
views
Difference between FlutterError.onError and PlatformDispatcher.instance.onError in Flutter
Let's say in a Flutter app we want to catch any uncaught exceptions/errors at the top level, so we do this as per the docs:
main() {
// All uncaught errors thrown from synchronous code blocks ...
1
vote
0
answers
153
views
Dart Stream Not Cancelling
I have a class that contains a stream that listens for objects to be created.
class Conversation {
// variables for live query
late QueryBuilder<ParseObject> message_live_query_;
final ...
0
votes
1
answer
584
views
Stream Listening For List Updates
I'm trying to understand how to use streams to notify listeners when there is a new addition to a list, below I wrote an example program that sums up what I'm trying to accomplish. Everytime there is ...
0
votes
1
answer
695
views
Generic Widget for listening Streams in Flutter
I would like to create a StatefulWidget which I'll use all over the app for listening streams of different types. Since I try to keep all the widgets Stateless I wanted to extract this functionality.
...
1
vote
0
answers
24
views
why dart doesn't execute the code in order? [duplicate]
My Flutter app is executing the code inside the .then() function after everything is finished. I thought that this function was used to wait for the code to be executed. Am I understanding something ...
-1
votes
1
answer
61
views
i have question about asynchronous programming at flutter
void main() async {
check();
print('end');
}
Future check() async {
var version = lookUpVersion();
print(version);
}
int lookUpVersion() {
return 12;
}
void main() async {
check();
...
0
votes
1
answer
71
views
How to save `Map<String, dynamic>` returning from async method in the constructor?
I have a class like below & method readJson which returns Future<Map<String, dynamic>> and in constructor TestRemoteConfigManager(){}, I want to assign the returned value to testValues ...
1
vote
1
answer
772
views
Screen not updated after calling FutureBuilder again
I have a screen that loads shopping cart items in a ListView.builder:
Expanded(
child: RefreshIndicator(
onRefresh: refresh,
child: ...
3
votes
2
answers
855
views
Flutter Riverpod, how to set minimut loading state time?
Building an app with Flutter and Riverpod, using a lot of:
ref.watch(someProvider).when(data: (someData){
// render layout with data
}, error: (err, stack) {
// do stuff with error
}, loading: ()...
0
votes
1
answer
141
views
Force asynchronous code to run synchronously dart
I currently have a class that stores images after fetching images asynchronously over GRPC. There is an issue with the handling of events. The problem can be shown here:
import 'dart:async';
main() {
...
0
votes
1
answer
236
views
Applying a boolean operator on FutureOr<bool> as part of fold
I am trying to check whether a boolean value in Firestore is true for a list of documents.
On trying to compile the code below I keep on getting the error The argument type 'Future<bool> ...
0
votes
1
answer
299
views
Flutter Listview after run empty, but filled only with Flutter Hot reload
How can I correct this code? That might have sparked the need to win another solution.
enter image description here
This result is only after a hot reload, and at the first start it is empty.
class ...
0
votes
1
answer
1k
views
How to return a Stream using an async* function in Flutter
I am working on a chat app using Flutter and Firebase. I am new to Dart and so got stuck when I wanted to create a function which fetches (using await) a particular document from one collection (...
0
votes
0
answers
81
views
Does a dart broadcast `StreamController` support multiple producers?
Can I have multiple asynchronous operations that call controller.add(myEvent) on a single broadcast StreamController? In other words, can I have multiple producers that emit stream events on the same ...
0
votes
3
answers
232
views
Dart async execution order
I'm trying to understand proper execution order of async functions in Dart. Here is a code that puzzles me:
void main() async {
print(1);
f1();
print(3);
}
void f1() async {
print(2);
}
...
0
votes
0
answers
61
views
Dart test complex async
I'm struggling with testing the piece of functionality that is highly asynchronous
. Overal idea is following:
function A puts data to local storage
function B monitors local storage and syncs ...
2
votes
1
answer
9k
views
What is the equivalent of Kotlin's Flow.flatMapLatest in Dart Stream?
In Kotlin there is Flow.flatMapLatest() function that:
Returns a flow that switches to a new flow produced by transform function every time the original flow emits a value. When the original flow ...
0
votes
1
answer
401
views
Refreshing ListView.builder with ToggleButton flutter
Basically, I'm trying to make an app, that on one of the screens - the content of a listview will be updated by choosing one of the options listed in the toggleButtons (One shows only upcoming events ...
0
votes
3
answers
2k
views
Value of variable is not updating in flutter
I am using TextFormField in my code and I have added the suffix icon inside it. I want that the value of textformfield will be assigned to the variable name "city" and the value of the ...
0
votes
3
answers
120
views
why statement is getting called before await function in flutter
I have created a demo for learning async and await
Here it is happening that a statement is executed before await function..
According to me
output should be A second Z First
but its giving
output ...
3
votes
2
answers
5k
views
create async await steps with Timer instead of Future.delayed(...)
Is it possible to perform async steps with Timer instead of Future.delayed? The main reason is the availability of cancel() method in the Timer class, which allows me to cancel a running timer when a ...
0
votes
2
answers
386
views
Why is flutter printing out widget name?
I have a problem with flutter printing out the name and rendering Widget name after running the application
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@...
0
votes
1
answer
402
views
Dart's runZoned - how is it different than async await
So I've read the docs and this example in particular:
runZoned(() {
HttpServer.bind('0.0.0.0', port).then((server) {
server.listen(staticFiles.serveRequest);
});
},
onError: (e, stackTrace) =&...
0
votes
1
answer
907
views
How do I convert 'Future<String?>' to 'Future<String>?' in Flutter?
So basically Iam working with the network_info_plus package to read the current connected Wifiname of the device. I want to use a FutureBuilder to get the future from await info.getWifiName();. The ...
1
vote
2
answers
3k
views
Update widget every 5 seconds
I need to do the widget with Flutter like "N users watch on it now", where N comes from the backend, and I need to update it every 5 seconds if the widget is visible.
I tried a few ...
1
vote
1
answer
722
views
How to make showDIalog wait for a function to finish first before building widget
So I'm trying to create a qr scanner feature, I manage to do all the function and functionality for the code, but when my code try to fetch the data the widget build run first resulting some data is ...
1
vote
4
answers
2k
views
Flutter: Update the UI with value from an async function
I want to see a the value of a counter in a flutter UI when the counter is updated asynchronously.
Staring from the sample flutter project, I would expect the below would make it, but only the final ...
0
votes
1
answer
1k
views
Flutter Isolate receives only the initial message
I'm trying to use an Isolate that will send a request, so as not to block the main thread/isolate.
After using so, the function of the spawned Isolate is called only once, on the initial passed ...
0
votes
1
answer
574
views
'!_debugLocked': is not true
Function:
navigateToAudioScreen(file, aPlay) async {
// await Future.delayed(Duration(seconds: 3));
WidgetsBinding.instance!.addPostFrameCallback((_) async {
await Future.delayed(...
2
votes
1
answer
2k
views
Write a test for reading and writing files in dart
I am learning Flutter and Dart currently. Now I want to read and write files to memory. I have code for reading and writing. Now I want tests for that. Here is where I run into problems. I always get:
...