add sqlite dep

This commit is contained in:
Mike Schwörer 2024-05-23 20:05:55 +02:00
parent f5813a5489
commit 227d7871c2
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
9 changed files with 122 additions and 4 deletions

View File

@ -7,5 +7,11 @@
- https://docs.flutter.dev/ui/widgets
- https://docs.flutter.dev/ui/widgets/material
- https://docs.flutter.dev/cookbook/persistence/sqlite
- https://pub.dev/packages/sqflite
- https://pub.dev/packages/sqflite_common_ffi

View File

@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:simplecloudnotifier/state/database.dart';
import 'nav_layout.dart';
import 'state/app_theme.dart';
import 'state/user_account.dart';
import 'package:simplecloudnotifier/nav_layout.dart';
import 'package:simplecloudnotifier/state/app_theme.dart';
import 'package:simplecloudnotifier/state/user_account.dart';
void main() async {
await SCNDatabase.create();
void main() {
runApp(
MultiProvider(
providers: [

View File

@ -57,6 +57,7 @@ class _MessageViewPageState extends State<MessageViewPage> {
}
Widget buildMessageView(Message message, bool loading) {
//TODO loading true/false indicator
return Center(
child: Column(
children: [

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,46 @@
import 'package:path_provider/path_provider.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'dart:io';
import 'package:path/path.dart' as path;
class SCNDatabase {
static SCNDatabase? instance = null;
final Database _db;
SCNDatabase._(this._db) {}
static create() async {
var docPath = await getApplicationDocumentsDirectory();
var dbpath = path.join(docPath.absolute.path, 'scn.db');
if (Platform.isWindows || Platform.isLinux) {
sqfliteFfiInit();
}
var db = await databaseFactoryFfi.openDatabase(dbpath,
options: OpenDatabaseOptions(
version: 1,
onCreate: (db, version) async {
initDatabase(db);
},
onUpgrade: (db, oldVersion, newVersion) async {
upgradeDatabase(db, oldVersion, newVersion);
},
));
return instance = SCNDatabase._(db);
}
static void initDatabase(Database db) async {
await db.execute('CREATE TABLE requests (id INTEGER PRIMARY KEY, timestamp DATETIME, name TEXT, url TEXT, response_code INTEGER, response TEXT, status TEXT)');
await db.execute('CREATE TABLE logs (id INTEGER PRIMARY KEY, timestamp DATETIME, level TEXT, text TEXT, additional TEXT)');
await db.execute('CREATE TABLE messages (message_id INTEGER PRIMARY KEY, receive_timestamp DATETIME, channel_id TEXT, timestamp TEXT, data JSON)');
}
static void upgradeDatabase(Database db, int oldVersion, int newVersion) {
// ...
}
}

View File

@ -0,0 +1 @@

View File

@ -5,10 +5,12 @@
import FlutterMacOS
import Foundation
import path_provider_foundation
import shared_preferences_foundation
import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}

View File

@ -215,6 +215,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
path_provider:
dependency: "direct main"
description:
name: path_provider
sha256: c9e7d3a4cd1410877472158bee69963a4579f78b68c65a2b7d40d1a7a88bb161
url: "https://pub.dev"
source: hosted
version: "2.1.3"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: a248d8146ee5983446bf03ed5ea8f6533129a12b11f12057ad1b4a67a2b3b41d
url: "https://pub.dev"
source: hosted
version: "2.2.4"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
sha256: f234384a3fdd67f989b4d54a5d73ca2a6c422fa55ae694381ae0f4375cd1ea16
url: "https://pub.dev"
source: hosted
version: "2.4.0"
path_provider_linux:
dependency: transitive
description:
@ -356,6 +380,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.10.0"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
sha256: "3da423ce7baf868be70e2c0976c28a1bb2f73644268b7ffa7d2e08eab71f16a4"
url: "https://pub.dev"
source: hosted
version: "2.5.4"
sqflite_common_ffi:
dependency: "direct main"
description:
name: sqflite_common_ffi
sha256: "4d6137c29e930d6e4a8ff373989dd9de7bac12e3bc87bce950f6e844e8ad3bb5"
url: "https://pub.dev"
source: hosted
version: "2.3.3"
sqlite3:
dependency: transitive
description:
name: sqlite3
sha256: b384f598b813b347c5a7e5ffad82cbaff1bec3d1561af267041e66f6f0899295
url: "https://pub.dev"
source: hosted
version: "2.4.3"
stack_trace:
dependency: transitive
description:
@ -380,6 +428,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
synchronized:
dependency: transitive
description:
name: synchronized
sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558"
url: "https://pub.dev"
source: hosted
version: "3.1.0+1"
term_glyph:
dependency: transitive
description:

View File

@ -43,6 +43,8 @@ dependencies:
url_launcher: ^6.2.4
infinite_scroll_pagination: ^4.0.0
intl: ^0.19.0
sqflite_common_ffi: ^2.3.3
path_provider: ^2.1.3
dependency_overrides: