Please can you kindly with me basic use cases of the library.
I'm very new to Flutter and I don't really know how to begin.
Directory documentsDirectory = await getApplicationDocumentsDirectory();
String path = join(documentsDirectory.path, "demo.db");
but got Invalid Directory.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Snapshot from http://www.nasdaq.com/screening/company-list.aspx
// Fetched 2/23/2014.
// "Symbol","Name","LastSale","MarketCap","IPOyear","Sector","industry","Summary Quote",
// Data in stock_data.json
import 'dart:convert';
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
//import 'package:sqflite/sqflite.dart';
import 'user_store.dart';
class User {
String UserId;
String UserName;
String UserSurname;
String UserEmail;
String UserForgotPwrdLongToken;
String UserForgotPwrdShortToken;
String UserPhoneNumber;
String UserActive;
User(this.UserId, this.UserName, this.UserSurname, this.UserEmail, this.UserForgotPwrdLongToken,
this.UserForgotPwrdShortToken, this.UserPhoneNumber, this.UserActive);
User.fromJson(Map fields) {
UserId = fields['UserId'];
UserName = fields['UserName'];
UserSurname = fields['UserSurname'];
UserEmail = fields['UserEmail'];
UserForgotPwrdLongToken = fields['UserForgotPwrdLongToken'];
UserForgotPwrdShortToken = fields['UserForgotPwrdShortToken'];
UserPhoneNumber = fields['UserPhoneNumber'];
UserActive = fields['UserActive'];
}
}
class UserData extends ChangeNotifier{
String email;
String password;
Future<int> response;
bool status;
String message;
http.Client _httpClient;
bool get loading => _httpClient != null;
UserData(this.email, this.password){
_httpClient = createHttpClient();
this.response = authentication();
}
authentication() async {
String url = "http://localhost/api/user/login";
String body = "email="+this.email+"&password="+this.password;
Map headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "application/json"};
var response = await _httpClient.post(url, body: body, headers: headers);
print('Response status: ${response.body}');
Map data = JSON.decode(response.body);
// set the response details here
this.status = data["status"];
this.message = data["message"];
if(data["status"]){
**// Create tables for user table and store information**
}
notifyListeners();
void _end() {
_httpClient?.close();
_httpClient = null;
}
}
import 'dart:async';
import 'package:sqflite/sqflite.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
final String tableUser = "user";
final String columnId = "_id";
final String columnTitle = "title";
final String columnDone = "done";
class UserStore {
int id;
String title;
bool done;
Map toMap() {
Map map = {columnTitle: title, columnDone: done == true ? 1 : 0};
if (id != null) {
map[columnId] = id;
}
return map;
}
UserStore();
UserStore.fromMap(Map map) {
id = map[columnId];
title = map[columnTitle];
done = map[columnDone] == 1;
}
}
class UserStoreProvider {
Database db;
Future open(String path) async {
db = await openDatabase(path, version: 1,
onCreate: (Database db, int version) async {
await db.execute('''
create table $tableUser (
$columnId integer primary key autoincrement,
$columnTitle text not null,
$columnDone integer not null)
''');
});
}
Future<UserStore> insert(UserStore user) async {
user.id = await db.insert(tableUser, user.toMap());
return user;
}
Future<UserStore> getTodo(int id) async {
List<Map> maps = await db.query(tableUser,
columns: [columnId, columnDone, columnTitle],
where: "$columnId = ?",
whereArgs: [id]);
if (maps.length > 0) {
return new UserStore.fromMap(maps.first);
}
return null;
}
Future<int> delete(int id) async {
return await db.delete(tableUser, where: "$columnId = ?", whereArgs: [id]);
}
Future<int> update(UserStore user) async {
return await db.update(tableUser, user.toMap(),
where: "$columnId = ?", whereArgs: [user.id]);
}
Future close() async => db.close();
}