Sqlentity

o Sqlentity é um ORM focado em facilitar o vida do desenvolvedor, onde é possivel criar um classe e apartir desta classe realizar a criação do banco de dados interno (sqlite) no dispositivo mobile.

é recomentado realizar os configurações e preparação do banco, no construtor inicial da classe, evite usa-lo no initState.

instalação

dependencies:
  sqlentity: ^1.0.1

Exemplo em codigo

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:sqlentity/base-entity/entity.dart';
import 'package:sqlentity/database/database-config.dart';
import 'package:sqlentity/repository/dao/i-dao-repository.dart';
import 'package:sqlentity/repository/dao/dao-repository.dart';



void main()  => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<UserEntity> users = new List();
  IDAORepository<UserEntity> _idao;

  _MyAppState(){
    initDatabase();
    _idao = new DAORepository(new UserEntity());
    initData();
  }

  void initDatabase() {
    DataBaseConfig dataBaseConfig = DataBaseConfig.getInstance();
    dataBaseConfig.database_name = "Teste";
    dataBaseConfig.database_version = 1;
    dataBaseConfig.entitys = [new UserEntity()];
  }

  void initData() async {
    //criar a entidade
    UserEntity jose = new UserEntity(name: "Jose");
    UserEntity marcos = new UserEntity(name: "Marcos");
    UserEntity rodrigo = new UserEntity(name: "Rodrigo");

    //realiza a inserção no banco e retorna o id
    int idjose = await _idao.insert(jose);
    await _idao.insert(marcos);
    int idrodrigo = await _idao.insert(rodrigo);
    jose.id = idjose;
    jose.name = "Roger";

    //realiza a atualização da entidade no banco e retorna um status
    await _idao.update(jose);
    rodrigo.id = idrodrigo;

    //realiza a exclusao no banco e retorna um status
    await _idao.delete(rodrigo);

    //lista de usuarios no banco
    var userlist = await _idao.select() as List<UserEntity>;
    setState(() {
      //setando lista
      users = userlist;
    });
  }


  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: const Text('DataBase'),
          ),
          body: new ListView.builder(
              padding: new EdgeInsets.all(4.0),
              shrinkWrap: true,
              itemCount: users.length,
              itemBuilder: (context, index) {
                return new Container(
                    child: new Center(
                        child: new Text(
                  '${users[index].name}',
                )));
              })),
    );
  }
}

class UserEntity extends Entity {
  int _id;
  String _name;

  UserEntity({var id: 0, var name: ""}) : super('USER') {
    this.id = id;
    this.name = name;
  }

  @override
  void configColumn() {
    //O id deve ser sempre o primeiro caso queira usar as operaçoes padroes do DAO
    createColumn("ID", "INTEGER PRIMARY KEY AUTOINCREMENT", 1);

    //nova coluna
    createColumn("NAME", "TEXT", 1);
  }

  @override
  Entity map(Map<String, dynamic> map) {
    return new UserEntity(
      id: map['ID'],
      name: map['NAME'],
    );
  }

  int get id => _id;

  set id(int value) {
    _id = value;
    updateValeu("ID", value: id);
  }

  String get name => _name;

  set name(String value) {
    _name = value;
    updateValeu("NAME", value: _name);
  }
}

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

Libraries

abstract-database
column
dao-repository
database-config
entity
i-dao-repository

Dart

dart:ui
Built-in types and core primitives for a Flutter application. [...]

Core

dart:async
Support for asynchronous programming, with classes such as Future and Stream. [...]
dart:collection
Classes and utilities that supplement the collection support in dart:core. [...]
dart:convert
Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
dart:core
Built-in types, collections, and other core functionality for every Dart program. [...]
dart:developer
Interact with developer tools such as the debugger and inspector. [...]
dart:math
Mathematical constants and functions, plus a random number generator. [...]
dart:typed_data
Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]

VM

dart:io
File, socket, HTTP, and other I/O support for non-web applications. [...]
dart:isolate
Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]