Using the bloc pattern for select

A SelectBloc is available to use the bloc pattern.

Select bloc

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

class _PageSelectBlocState extends State<PageSelectBloc> {
  SelectBloc bloc;

  void initState() {
    this.bloc = SelectBloc(
        table: "items", orderBy: "name", verbose: true);

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("My app"),
      body: StreamBuilder<List<Map>>(
          stream: bloc.items,
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            if (snapshot.hasData) {
              // the select query has not found anything
              if ( == 0) {
                return Center(
                  child: Text(
                      "No data. Use the + in the appbar to insert an item"),
              // the select query has results
              return ListView.builder(
                  itemBuilder: (BuildContext context, int index) {
                    var item =[index];
                    return ListTile(
                      title: GestureDetector(
                        child: Text(item["name"]),
                        onTap: () => print("Action"),
            } else {
              // the select query is still running
              return CircularProgressIndicator();

class PageSelectBloc extends StatefulWidget {
  _PageSelectBlocState createState() => _PageSelectBlocState();

SelectBloc class:

Required parameter:

table:String name of the table, required

Optional parameters:

select:String the select sql clause
where:String the where sql clause
joinTable:String join table name
joinOn:String join on sql clause
orderBy:String the sql order_by clause
limit:int the sql limit clause
offset:int the sql offset clause
reactive:bool if true the select bloc will react to database changes. Defaults to false
verbose:bool true or false
database:Db the database to use: default is the default database

Join queries

void initState() {
   this.bloc = SelectBloc(table: "product", offset: 10, limit: 20,
                          select: "id, name, price, as category_name",
                          joinTable: "category",
                          joinOn: "");