Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Preciso de ajuda, já revisei o código 3 vezes: versão fultter 2.0.3

error: Missing type arguments for generic type 'Map<String, dynamic>'. (implicit_dynamic_type at [bytebank_contacts] lib\database\app_database.dart:19)

import 'package:bytebank_contacts/models/contact.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

Future<Database> createDatabase() {
  return getDatabasesPath().then((dbPath) {
    final String path = join(dbPath, 'bytebank.db');
    return openDatabase(path, onCreate: (db, version) {
      db.execute('CREATE TABLE contacts('
          'id INTEGER PRIMARY KEY, '
          'name TEXT, '
          'account_number INTEGER)');
    }, version: 1);
  });
}

Future<int> save(Contact contact) {
  return createDatabase().then((db) {
    final Map<String, dynamic> contactMap = Map();
    contactMap['name'] = contact.name;
    contactMap['account_number'] = contact.accountNumber;
    return db.insert('contacts', contactMap);
  });
}

Future<List<Contact>> findAll() {
  return createDatabase().then((db) {
    return db.query('contacts').then((maps) {
      final List<Contact> contacts = List();
      for (Map<String, dynamic> map in maps) {
        final Contact contact = Contact(
          map['id'],
          map['name'],
          map['account_number'],
        );
        contacts.add(contact);
      }
      return contacts;
    });
  });
}
3 respostas

Future<Database> getDatabase() async {
  final String path = join(await getDatabasesPath(), 'novobanco.db');
  return openDatabase(
    path,
    onCreate: (db, version) {
      db.execute(ContactDao.tableSql);
    },
    version: 1,
  );
}

class ContactDao {
  static const String tableSql = 'CREATE TABLE $_tableName('
      '$_id INTEGER PRIMARY KEY, '
      '$_name TEXT, '
      '$_email TEXT, '
      '$_accountNumber INTEGER, '
      '$_avatarUrl TEXT) ';
  static const String _tableName = 'contacts';
  static const String _id = 'id';
  static const String _name = 'name';
  static const String _email = 'email';
  static const String _accountNumber = 'accountNumber';
  static const String _avatarUrl = 'avatarUrl';

  Future<int> saveDB(Contact contact) async {
    final Database db = await getDatabase();
    Map<String, dynamic> contactMap = _toMap(contact);
    return db.insert(_tableName, contactMap);
  }

  Future<List<Contact>> findAllDB() async {
    final Database db = await getDatabase();
    final List<Map<String, dynamic>> result = await db.query(_tableName);
    List<Contact> contacts = _toList(result);
    return contacts;
  }

  Map<String, dynamic> _toMap(Contact contact) {
    final Map<String, dynamic> contactMap = Map();
    contactMap[_id] = contact.id;
    contactMap[_name] = contact.name;
    contactMap[_email] = contact.email;
    contactMap[_accountNumber] = contact.accountNumber;
    contactMap[_avatarUrl] = contact.avatarUrl;

    return contactMap;
  }

  List<Contact> _toList(List<Map<String, dynamic>> result) {
    final List<Contact> contacts = [];
    for (Map<String, dynamic> row in result) {
      final Contact contact = Contact(
        row[_id],
        row[_name],
        row[_email],
        row[_accountNumber],
        row[_avatarUrl],
      );
      contacts.add(contact);
    }
    return contacts;
  }

  Future<int> updateDB(Contact contact) async {
    final Database db = await getDatabase();
    final Map<String, dynamic> contactMap = _toMap(contact);
    return db.update(
      _tableName,
      contactMap,
      where: _id,
      whereArgs: [contact.id],
    );
  }

  Future<int> deleteDB(int id) async {
    final Database db = await getDatabase();
    return db.delete(
      _tableName,
      where: '$_id = ?',
      whereArgs: [id],
    );
  }
}
solução!

tem campos a mais nos códigos acima que eu coloquei exclua eles ou use assim mas lembre-se de add as informações será necessário preencher todos os campos na mesma ordem