Skip to content

Commit

Permalink
refs #26 Cleanup handling of couchbase integration
Browse files Browse the repository at this point in the history
"getting started" docs are lacking on the flutter docs for couchbase
Need to initialize the DB inside of main before you do anything.
This currently just captures whatever gets scanned in terms of UUIDs.
Will figure out what to do with this later.
  • Loading branch information
truedat101 committed Feb 8, 2024
1 parent 9e4b670 commit 14b40a8
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 12 deletions.
28 changes: 24 additions & 4 deletions magnet_app/lib/app_state_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:io' show Platform, sleep;
// import 'dart:js_interop';
import 'dart:math';
import 'dart:async';

import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:provider/provider.dart';

Expand All @@ -9,7 +11,8 @@ import 'package:magnet_app/provider/ble_provider.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart';
// import 'package:location_permissions/location_permissions.dart';
import 'package:permission_handler/permission_handler.dart';
import 'dart:async';
import 'package:cbl/cbl.dart';


/**
*
Expand All @@ -23,7 +26,7 @@ class AppState extends BLEProvider {
String? app_screen = "splash";
String? prev_screen = null;
bool timerStatus = false;

AsyncDatabase? _db;

Timer? btnStatusTimer;

Expand All @@ -45,8 +48,11 @@ class AppState extends BLEProvider {
return scanStarted;
}

Future initDB() async {
_db = await Database.openAsync('magnetdb-schema1');
}

AppState() {

Timer(const Duration(seconds: 5), () {
// scanAndConnectToDevice();
print("Move to home screen");
Expand All @@ -58,6 +64,9 @@ class AppState extends BLEProvider {

//Scan And Connect Methods
void startScan() async {
if (_db == null) {
initDB();
}
bool permGranted = false;
scanStarted = true;
notifyListeners();
Expand Down Expand Up @@ -98,13 +107,24 @@ class AppState extends BLEProvider {
print("Scanning ...");
scanDeviceStream = ble.scanForDevices(
withServices: [], // [serviceUuid]
scanMode: ScanMode.lowLatency).listen((device) {
scanMode: ScanMode.lowLatency).listen((device) async {
print("examining new device");
print("---------------------");

if (device.id == deviceId) {
print("--------------> Found match!!!!");
} else {
// Create a new document.
final adoc = await _db!.document(device.id);
if (adoc == null) {
final mutableDocumemt = MutableDocument.withId('hotel::1')
..setInteger(1, key: 'scans')
..setString('todo', key: 'name')
..setDate(DateTime.now(), key: 'createdAt');
await _db?.saveDocument(mutableDocumemt);
}


device.serviceData.forEach((k, v) {
print('{ key: $k, value: $v }');
});
Expand Down
8 changes: 6 additions & 2 deletions magnet_app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@

import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';


import 'package:cbl_flutter/cbl_flutter.dart';

import 'package:magnet_app/splash_page.dart';
import 'package:magnet_app/about.dart';
import 'package:magnet_app/app_state_model.dart';
import 'package:magnet_app/provider/ble_provider.dart';


void main() {
Future<void> main() async {

WidgetsFlutterBinding.ensureInitialized();
// Now initialize Couchbase Lite.
await CouchbaseLiteFlutter.init();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
Expand Down
4 changes: 4 additions & 0 deletions magnet_app/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#include "generated_plugin_registrant.h"

#include <audioplayers_linux/audioplayers_linux_plugin.h>
#include <cbl_flutter_ce/cbl_flutter_ce.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin");
audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar);
g_autoptr(FlPluginRegistrar) cbl_flutter_ce_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "CblFlutterCe");
cbl_flutter_ce_register_with_registrar(cbl_flutter_ce_registrar);
}
1 change: 1 addition & 0 deletions magnet_app/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_linux
cbl_flutter_ce
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
2 changes: 2 additions & 0 deletions magnet_app/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import FlutterMacOS
import Foundation

import audioplayers_darwin
import cbl_flutter_ce
import path_provider_foundation
import shared_preferences_foundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
CblFlutterCe.register(with: registry.registrar(forPlugin: "CblFlutterCe"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
}
32 changes: 28 additions & 4 deletions magnet_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.2"
cbl_dart:
dependency: "direct dev"
description:
name: cbl_dart
sha256: b7ac781c2b01297849b2740db8fc051b25f323d4516b51a66295c9280319cd36
url: "https://pub.dev"
source: hosted
version: "2.2.2"
cbl_ffi:
dependency: transitive
description:
Expand All @@ -121,6 +129,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.9"
cbl_flutter_ce:
dependency: "direct main"
description:
name: cbl_flutter_ce
sha256: "14a6035bf95e284f48b1c49c92b4122bb06b74197b82c1eae9014204294a9880"
url: "https://pub.dev"
source: hosted
version: "2.2.2"
cbl_flutter_platform_interface:
dependency: transitive
description:
Expand All @@ -133,10 +149,10 @@ packages:
dependency: transitive
description:
name: cbl_libcblite_api
sha256: b2cfb36c883b2b14029f47710f00908a26fcea0ef5182b053fe9d7738413920e
sha256: "839f16022fca3417acc171b683d8b542344277deab5df497736adb2ed803a60a"
url: "https://pub.dev"
source: hosted
version: "3.1.3"
version: "3.1.1"
cbl_libcblitedart_api:
dependency: transitive
description:
Expand Down Expand Up @@ -301,10 +317,10 @@ packages:
dependency: transitive
description:
name: http
sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525"
sha256: "5895291c13fa8a3bd82e76d5627f69e0d85ca6a30dcac95c4ea19a5d555879c2"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
version: "0.13.6"
http_parser:
dependency: transitive
description:
Expand Down Expand Up @@ -345,6 +361,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
logging:
dependency: transitive
description:
name: logging
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
matcher:
dependency: transitive
description:
Expand Down
10 changes: 8 additions & 2 deletions magnet_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ dependencies:
permission_handler: ^11.0.1
audioplayers: ^5.2.0
cbl_flutter: ^2.0.9
# This dependency selects the Community Edition of Couchbase Lite.
# For the Enterprise Edition add `cbl_flutter_ee` instead.
cbl_flutter_ce: ^2.2.2
flutter_neumorphic:
git:
url: https://github.com/truedat101/Flutter-Neumorphic
ref: feature/remoce_accentcolor # branch name
dev_dependencies:
flutter_test:
sdk: flutter

flutter_launcher_icons: "^0.13.1"

# The "flutter_lints" package below contains a set of recommended lints to
Expand All @@ -61,9 +64,12 @@ dev_dependencies:
# rules and activating additional ones.
flutter_lints: ^2.0.0

# This dependency allows you to use Couchbase Lite in Flutter
# unit tests and not just in integration tests.
cbl_dart: ^2.2.2
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

flutter_launcher_icons:
image_path: "assets/images/magnet_icon.png"
android: true
Expand Down
3 changes: 3 additions & 0 deletions magnet_app/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
#include "generated_plugin_registrant.h"

#include <audioplayers_windows/audioplayers_windows_plugin.h>
#include <cbl_flutter_ce/cbl_flutter_ce.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
AudioplayersWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
CblFlutterCeRegisterWithRegistrar(
registry->GetRegistrarForPlugin("CblFlutterCe"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
}
1 change: 1 addition & 0 deletions magnet_app/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_windows
cbl_flutter_ce
permission_handler_windows
)

Expand Down

0 comments on commit 14b40a8

Please sign in to comment.