From 227d7871c24edcfd010c186d8ad2fa1bb26b33f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Thu, 23 May 2024 20:05:55 +0200 Subject: [PATCH] add sqlite dep --- flutter/README.md | 6 ++ flutter/lib/main.dart | 11 ++-- .../lib/pages/message_view/message_view.dart | 1 + flutter/lib/state/application_log.dart | 1 + flutter/lib/state/database.dart | 46 +++++++++++++++ flutter/lib/state/request_log.dart | 1 + .../Flutter/GeneratedPluginRegistrant.swift | 2 + flutter/pubspec.lock | 56 +++++++++++++++++++ flutter/pubspec.yaml | 2 + 9 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 flutter/lib/state/application_log.dart create mode 100644 flutter/lib/state/database.dart create mode 100644 flutter/lib/state/request_log.dart diff --git a/flutter/README.md b/flutter/README.md index 1046744..bd17bac 100644 --- a/flutter/README.md +++ b/flutter/README.md @@ -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 + + + \ No newline at end of file diff --git a/flutter/lib/main.dart b/flutter/lib/main.dart index fa9a19c..6efde5a 100644 --- a/flutter/lib/main.dart +++ b/flutter/lib/main.dart @@ -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: [ diff --git a/flutter/lib/pages/message_view/message_view.dart b/flutter/lib/pages/message_view/message_view.dart index 808b0eb..1450bd0 100644 --- a/flutter/lib/pages/message_view/message_view.dart +++ b/flutter/lib/pages/message_view/message_view.dart @@ -57,6 +57,7 @@ class _MessageViewPageState extends State { } Widget buildMessageView(Message message, bool loading) { + //TODO loading true/false indicator return Center( child: Column( children: [ diff --git a/flutter/lib/state/application_log.dart b/flutter/lib/state/application_log.dart new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/flutter/lib/state/application_log.dart @@ -0,0 +1 @@ + diff --git a/flutter/lib/state/database.dart b/flutter/lib/state/database.dart new file mode 100644 index 0000000..547f88b --- /dev/null +++ b/flutter/lib/state/database.dart @@ -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) { + // ... + } +} diff --git a/flutter/lib/state/request_log.dart b/flutter/lib/state/request_log.dart new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/flutter/lib/state/request_log.dart @@ -0,0 +1 @@ + diff --git a/flutter/macos/Flutter/GeneratedPluginRegistrant.swift b/flutter/macos/Flutter/GeneratedPluginRegistrant.swift index 997e35d..b19945c 100644 --- a/flutter/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/flutter/macos/Flutter/GeneratedPluginRegistrant.swift @@ -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")) } diff --git a/flutter/pubspec.lock b/flutter/pubspec.lock index 131e53c..059c06f 100644 --- a/flutter/pubspec.lock +++ b/flutter/pubspec.lock @@ -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: diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml index 178aa9a..16ccbf1 100644 --- a/flutter/pubspec.yaml +++ b/flutter/pubspec.yaml @@ -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: