Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

int isn't a type

Tags:

sql

flutter

dart

on passing the version to the on create method and integer(int) of the id that i want to fetch from the database,i get an error saying "int isn't a type"error Image

class NewsDbProvider {
  Database db;

  int() async {

    Directory documentsDirectory =await getApplicationDocumentsDirectory();
    final path = join(documentsDirectory.path, "items.db");

    db = await openDatabase(
        path,
        version: 1,
        onCreate: (Database newDb,int version){
          newDb.execute("""
            CREATE TABLE Items
            (

            )
            """);
        }
    );
  }

  fetchItem(int id) async{
    db.query(
      "Items",
      columns: null,
      where: 'id = ?',
      whereArgs: {id},
    );
  }
}
like image 707
user8273163 Avatar asked Jul 09 '19 10:07

user8273163


People also ask

Is int a class in Dart?

Yes, Dart's int type is a "reference type". Dart does not have value types at all, all values are instances of a class, including integers.

Is not a subtype of type string?

To Solve type 'int' is not a subtype of type 'String' error in Dart Error is saying you are passing String where flutter required for the Integer value. So that you have to pass Integer there Or you can just use our solutions to solve this error.

What is covariant Dart?

Covariant is a fancy type theory term, but it basically means 'this class or its subclasses'. You are explicitly telling Dart to tighten the type checking of this argument to a subclass of the original.


1 Answers

You named a method of NewsDbProvider as int, which is why the keyword isn't being recognised anymore. Try renaming it.

like image 118
Sven Avatar answered Sep 23 '22 14:09

Sven