Future is not recognized in Flutter (Dart)

Asked

Viewed 60 times

0

I’m studying Flutter and recently I’ve had a rather boring problem. I was using Future for my asynchronous programming and I did all the code, just like the example I was seeing. However, I realized that Future was not being recognized, and there was a recommendation for me to do the import package async. I did it, but still the problem did not solve.

Future<int> insertAgendamento(Agendamento agendamento) async {
    Database db = await this.database;

    var resultado = await db.insert(agendaTable, agendamento.toMap());

    return resultado;
}

Turns out I’ve already done the import and put a dependency on pubspec.yaml.

import 'dart:async';

When I hover over my "Future" the following message appears:

Future isn’t a type. Try correcting the name to match an existing type.

And in that import, The warning appears that I am not using it... Maybe it is something silly, that for lack of attention, I could not find. But I’d like your help.

  • 1

    Hello! Could you [Edit] your question to include the error message you are receiving? :)

  • Hello Luiz! I made the edition you asked for. The error that appears, is in Visual Studio, when I step the mouse over the Future.

  • What version of your flutter and Dart?

  • Leandro, my version of Flutter is (Channel stable, 1.22.6) I updated it recently, because I thought that was the problem. The Dart version is SDK version: 2.10.5 (stable).

1 answer

0

I managed to solve the problem, what I needed to do was set up my import to be called by Fut: import 'dart:async' as Fut;

Soon after, I went to my code and put:

Fut.Future<int> insertAgendamento(Agendamento agendamento) async {
Database db = await this.database;

var resultado = await db.insert(agendaTable, agendamento.toMap());

return resultado;}

After that, my problem was solved.

I found this alternative in this discussion on github, whose solution was presented by the yringler user.

  • As much as it 'worked', I would not consider it a valid solution. It has to work without using these tricks, clear the cache, restart the IDE, make sure you haven’t created another class named Future..

  • Thanks for the tip Julio, I took these steps (clear the cache and restart the IDE) and solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.