title: Getting an error using sqflite plugin in my CRUD Flutter app
body: <p>I'm super noob in Flutter and I'm trying a "trivial" (for everyone else)
  CRUD app so I followed some tutorial </p>
  
  <p>(<a href="https://grokonez.com/android/flutter-sqlite-example-listview-crud-operations-sqflite-plugin" rel="nofollow noreferrer">https://grokonez.com/android/flutter-sqlite-example-listview-crud-operations-sqflite-plugin</a>) </p>
  
  <p>his "version" obviously works, of course mine doesn't.
  I got this error: <a href="https://i.stack.imgur.com/TM893.png" rel="nofollow noreferrer">https://i.stack.imgur.com/TM893.png</a></p>
  
  <p>here's "my" code, i guess the parts involved are DBHelper and TicketScreen:</p>
  
  <pre><code>  class DatabaseHelper {
    static final DatabaseHelper _instance = new DatabaseHelper.internal();
  
    factory DatabaseHelper() =&gt; _instance;
  
    final String ticketTable = 'ticketTable';
    final String columnId = 'id';
    final String columnDay = 'day';
    final String columnMonth = 'month';
    final String columnYear = 'year';
    final String columnFrom = 'from';
    final String columnTo = 'to';
    final String columnAircraft = 'aircraft';
    final String columnAirline = 'airline';
  
    static Database _db;
  
    DatabaseHelper.internal();
  
    Future&lt;Database&gt; get db async {
      if (_db != null) {
        return _db;
      }
      _db = await initDb();
  
      return _db;
    }
  
    initDb() async {
      String databasesPath = await getDatabasesPath();
      String path = join(databasesPath, 'ticket.db');
      var db = await openDatabase(path, version: 1, onCreate: _onCreate);
      return db;
    }
  
    void _onCreate(Database db, int newVersion) async {
      await db.execute(
          'CREATE TABLE $ticketTable($columnId INTEGER PRIMARY KEY, $columnDay TEXT, $columnMonth TEXT, $columnYear TEXT, $columnFrom TEXT, $columnTo TEXT, $columnAircraft TEXT, $columnAirline TEXT)');
    }
  
    Future&lt;int&gt; saveTicket(Ticket ticket) async {
      var dbClient = await db;
      var result = await dbClient.insert(ticketTable, ticket.toMap());
      return result;
    }
  
    Future&lt;List&gt; getAllTickets() async {
      var dbClient = await db;
      var result = await dbClient.query(ticketTable, columns: [
        columnId,
        columnDay,
        columnMonth,
        columnYear,
        columnFrom,
        columnTo,
        columnAircraft,
        columnAirline
      ]);
      return result.toList();
    }
  
    Future&lt;int&gt; getCount() async {
      var dbClient = await db;
      return Sqflite.firstIntValue(
          await dbClient.rawQuery('SELECT COUNT(*) FROM $ticketTable'));
    }
  
    Future&lt;Ticket&gt; getTicket(int id) async {
      var dbClient = await db;
      List&lt;Map&gt; result = await dbClient.query(ticketTable,
          columns: [
            columnId,
            columnDay,
            columnMonth,
            columnYear,
            columnFrom,
            columnTo,
            columnAircraft,
            columnAirline
          ],
          where: '$columnId = ?',
          whereArgs: [id]);
      if (result.length &gt; 0) {
        return new Ticket.fromMap(result.first);
      }
      return null;
    }
  
    Future&lt;int&gt; deleteTicket(int id) async {
      var dbClient = await db;
      return await dbClient
          .delete(ticketTable, where: '$columnId = ?', whereArgs: [id]);
    }
  
    Future&lt;int&gt; updateTicket(Ticket ticket) async {
      var dbClient = await db;
      return await dbClient.update(ticketTable, ticket.toMap(),
          where: "$columnId = ?", whereArgs: [ticket.id]);
    }
  
    Future close() async {
      var dbClient = await db;
      return dbClient.close();
    }
  }
  </code></pre>
  
  <hr>
  
  <hr>
  
  <pre><code> class TicketScreen extends StatefulWidget {
    final Ticket ticket;
    TicketScreen(this.ticket);
  
    @override
    State&lt;StatefulWidget&gt; createState() =&gt; new _TicketScreenState();
  }
  
  class _TicketScreenState extends State&lt;TicketScreen&gt; {
    DatabaseHelper db = new DatabaseHelper();
  
    TextEditingController _dayController;
    TextEditingController _monthController;
    TextEditingController _yearController;
    TextEditingController _fromController;
    TextEditingController _toController;
    TextEditingController _aircraftController;
    TextEditingController _airlineController;
  
    @override
    void initState() {
      super.initState();
      _dayController = new TextEditingController(text: widget.ticket.day);
      _monthController = new TextEditingController(text: widget.ticket.month);
      _yearController = new TextEditingController(text: widget.ticket.year);
      _fromController = new TextEditingController(text: widget.ticket.from);
      _toController = new TextEditingController(text: widget.ticket.to);
      _aircraftController = new TextEditingController(text: widget.ticket.aircraft);
      _airlineController = new TextEditingController(text: widget.ticket.airline);
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(title: Text('Ticket')),
        body: Container(
          margin: EdgeInsets.all(15.0),
          alignment: Alignment.center,
          child: Column(
            children: &lt;Widget&gt;[
              Text('Travel Date',
                style: new TextStyle(fontWeight: FontWeight.bold),
              ),
              Row(
                children: &lt;Widget&gt;[
            Container(
              alignment: Alignment.center, 
              width: 80.0,
                  child: TextField(
                    maxLength: 2,
                    keyboardType: TextInputType.number,
                    controller: _dayController,
                    decoration: InputDecoration(labelText: 'Day'),
                  ),
            ),
                  Text(' / '),
        Container(
          width: 80.0,
          child: TextField(
                    maxLength: 2,
                    keyboardType: TextInputType.number,
                    controller: _monthController,
                    decoration: InputDecoration(labelText: 'Month'),
                  ),
        ),
                  Text(' / '),
        Container(
          width: 160.0,
          child: TextField(
                    maxLength: 4,
                    keyboardType: TextInputType.number,
                    controller: _yearController,
                    decoration: InputDecoration(labelText: 'Year'),
                  ),
          ),
                ],
              ),
              Padding(padding: new EdgeInsets.all(5.0)),
              Row(
                children: &lt;Widget&gt;[
                  Container(
                    width: 160.0,
                    child: TextField(
                    controller: _fromController,
                    decoration: InputDecoration(labelText: 'From'),
                  ),
                  ),
                  Container(
                    width: 160.0,
                    child: TextField(
                    controller: _toController,
                    decoration: InputDecoration(labelText: 'To'),
                  ),
                  ),
                ],
              ),
              Padding(padding: new EdgeInsets.all(5.0)),
              Row(
                children: &lt;Widget&gt;[
                  Container(
                    width: 160.0,
                    child: TextField(
                    controller: _aircraftController,
                    decoration: InputDecoration(labelText: 'Aircraft'),
                  ),
                  ),
                  Container(
                    width: 160.0,
                    child: TextField(
                    controller: _airlineController,
                    decoration: InputDecoration(labelText: 'Airline'),
                  ),
                  ),
                ],
              ),
              Padding(padding: new EdgeInsets.all(5.0)),
              RaisedButton(
                child: (widget.ticket.id != null) ? Text('Update') : Text('Add'),
                onPressed: () {
                  if (widget.ticket.id != null) {
                    db
                        .updateTicket(Ticket.fromMap({
                      'id': widget.ticket.id,
                      'day': _dayController.text,
                      'year': _yearController.text,
                      'from': _fromController.text,
                      'to': _toController.text,
                      'aircraft': _aircraftController.text,
                      'airline': _airlineController.text
                    }))
                        .then((_) {
                      Navigator.pop(context, 'update');
                    });
                  } else {
                    db
                        .saveTicket(Ticket(
                            _dayController.text,
                            _monthController.text,
                            _yearController.text,
                            _fromController.text,
                            _toController.text,
                            _aircraftController.text,
                            _airlineController.text))
                        .then((_) {
                      Navigator.pop(context, 'save');
                    });
                  }
                },
              ),
            ],
          ),
        ),
      );
    }
  }
  </code></pre>
  
  <p>and  then some other stuff, but i tend to rule them out as the source of the problem</p>
  
  <pre><code>    class MyListView extends StatefulWidget {
    @override
    _ListViewState createState() =&gt; new _ListViewState();
  }
  
  class _ListViewState extends State&lt;MyListView&gt; {
    List&lt;Ticket&gt; items = new List();
    DatabaseHelper db = new DatabaseHelper();
  
    @override
    void initState() {
      super.initState();
  
      db.getAllTickets().then((tickets) {
        setState(() {
          tickets.forEach((ticket) {
            items.add(Ticket.fromMap(ticket));
          });
        });
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Ticket List',
        home: Scaffold(
          appBar: AppBar(
            title: Text('Ticket List'),
            centerTitle: true,
            backgroundColor: Colors.blue,
          ),
          body: Center(
            child: ListView.builder(
                itemCount: items.length,
                padding: const EdgeInsets.all(15.0),
                itemBuilder: (context, position) {
                  return Column(
                    children: &lt;Widget&gt;[
                      Divider(height: 5.0),
                      ListTile(
                        title: Text(
                          'From ${items[position].from} to ${items[position].to}',
                          style: TextStyle(
                            fontSize: 22.0,
                            color: Colors.deepOrangeAccent,
                          ),
                        ),
                        subtitle:
                          Text(
                            'Operated by ${items[position].airline} with  ${items[position].aircraft} ',
                            style: new TextStyle(
                              fontSize: 18.0,
                              fontStyle: FontStyle.italic,
                            ),
                          ),
                        leading: Column(
                          children: &lt;Widget&gt;[
                            Padding(padding: EdgeInsets.all(10.0)),
                            CircleAvatar(
                              backgroundColor: Colors.blueAccent,
                              radius: 20.0,
                              child: Text(
                                '${items[position].day}/${items[position].month}/${items[position].year}',
                                style: TextStyle(
                                  fontSize: 22.0,
                                  color: Colors.white,
                                ),
                              ),
                            ),
                            IconButton(
                                icon: const Icon(Icons.remove_circle_outline),
                                onPressed: () =&gt; _deleteTicket(context, items[position], position)
                            ),
                          ],
                        ),
                        onTap: () =&gt; _navigateToTicket(context, items[position]),
                      ),
                    ],
                  );
                }),
          ),
          floatingActionButton: FloatingActionButton(
            child: Icon(Icons.add),
            onPressed: () =&gt; _createNewTicket(context),
          ),
        ),
      );
    }
  
    void _deleteTicket(BuildContext context, Ticket ticket, int position) async {
      db.deleteTicket(ticket.id).then((tickets) {
        setState(() {
          items.removeAt(position);
        });
      });
    }
  
    void _navigateToTicket(BuildContext context, Ticket ticket) async {
      String result = await Navigator.push(
        context,
        MaterialPageRoute(builder: (context) =&gt; TicketScreen(ticket)),
      );
  
      if (result == 'update') {
        db.getAllTickets().then((tickets) {
          setState(() {
            items.clear();
            tickets.forEach((ticket) {
              items.add(Ticket.fromMap(ticket));
            });
          });
        });
      }
    }
  
    void _createNewTicket(BuildContext context) async {
      String result = await Navigator.push(
        context,
        MaterialPageRoute(builder: (context) =&gt; TicketScreen(Ticket('', '', '', '', '', '', ''))),
      );
  
      if (result == 'save') {
        db.getAllTickets().then((tickets) {
          setState(() {
            items.clear();
            tickets.forEach((ticket) {
              items.add(Ticket.fromMap(ticket));
            });
          });
        });
      }
    }
  }
  </code></pre>
  
  <hr>
  
  <hr>
  
  <pre><code>  class Ticket {
    int _id;
    String _day;
    String _month;
    String _year;
    String _from;
    String _to;
    String _aircraft;
    String _airline;
  
  
  
    Ticket(this._day, this._month, this._year, this._from, this._to, this._aircraft, this._airline);
  
    Ticket.map(dynamic obj) {
      this._id = obj['id'];
      this._day = obj['day'];
      this._month = obj['month'];
      this._year = obj['year'];
      this._from = obj['form'];
      this._to = obj['to'];
      this._aircraft = obj['aircraft'];
      this._airline = obj['airline'];
    }
  
    int get id =&gt; _id;
    String get day =&gt; _day;
    String get month =&gt; _month;
    String get year =&gt; _year;
    String get from =&gt; _from;
    String get to =&gt;_to;
    String get aircraft =&gt;_aircraft;
    String get airline =&gt; _airline;
  
    Map&lt;String, dynamic&gt; toMap() {
      var map = new Map&lt;String, dynamic&gt;();
      if (_id != null) {
        map['id'] = _id;
      }
      map['day'] = _day;
      map['month'] = _month;
      map['year'] = _year;
      map['from'] = _from;
      map['to'] = _to;
      map['aircraft'] = _aircraft;
      map['airline'] = _airline;
  
      return map;
    }
  
    Ticket.fromMap(Map&lt;String, dynamic&gt; map) {
      this._id = map['id'];
      this._day = map['day'];
      this._month = map['month'];
      this._year = map['year'];
      this._from =  map['from'];
      this._to = map['to'];
      this._aircraft = map['aircraft'];
      this._airline = map['airline'];
    }
  }
  </code></pre>
  
  <hr>
  
  <hr>
  
  <pre><code>  void main() =&gt; runApp(
    MaterialApp(
      title: 'Returning Data',
      home: MyListView(),
    ),
  );
  </code></pre>
  
  <p>so, can you tell me what I did wrong? 
  thank you in advance</p>
  
  <p>bonus question:
  I feel no love for SQL,
  is there any alternative db for flutter?
  I mean real DB, not saving data in sharedpref or using firebase,
  I like realm, but looks like there's not a flutter.</p>
  
  <p>thanks again </p>