forked from lxm_flutter/FlutterUnit
数据库设置
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:flutter_unit/app/blocs/global/global_state.dart';
|
||||
import 'package:flutter_unit/app/res/cons.dart';
|
||||
import 'package:flutter_unit/app/res/sp.dart';
|
||||
|
||||
import 'dao/db_setup/setup_db.dart';
|
||||
import 'local_db.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
@@ -33,7 +34,7 @@ class AppStart {
|
||||
} else {
|
||||
print("=====flutter.db 已存在====");
|
||||
}
|
||||
|
||||
setupDatabase();
|
||||
await LocalDb.instance.initDb();
|
||||
|
||||
bool showBg = prefs.getBool(SP.showBackground) ?? true;
|
||||
|
||||
25
lib/widget_system/repositories/dao/db_setup/setup_db.dart
Normal file
25
lib/widget_system/repositories/dao/db_setup/setup_db.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:sqlite3/open.dart';
|
||||
import 'package:sqlite3/sqlite3.dart';
|
||||
import 'package:path/path.dart';
|
||||
|
||||
setupDatabase(){
|
||||
if(Platform.isWindows){
|
||||
var location = Directory.current.path;
|
||||
windowsInit(join(location, 'sqlite3.dll'));
|
||||
}
|
||||
}
|
||||
|
||||
void windowsInit(String path) {
|
||||
open.overrideFor(OperatingSystem.windows, () {
|
||||
try {
|
||||
return DynamicLibrary.open(path);
|
||||
} catch (e) {
|
||||
stderr.writeln('Failed to load sqlite3.dll at $path');
|
||||
rethrow;
|
||||
}
|
||||
});
|
||||
sqlite3.openInMemory().dispose();
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'dao/db_setup/setup_db.dart';
|
||||
import 'dao/like_dao.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
14
pubspec.lock
14
pubspec.lock
@@ -357,6 +357,20 @@ packages:
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.0+2"
|
||||
sqflite_common_ffi:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: sqflite_common_ffi
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.0+1"
|
||||
sqlite3:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sqlite3
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -34,6 +34,7 @@ dependencies:
|
||||
# connectivity: ^3.0.3 #网络状态
|
||||
flutter_spinkit: ^5.0.0 # loading
|
||||
flutter_markdown: ^0.6.4 # markdown
|
||||
sqflite_common_ffi: ^2.0.0
|
||||
dio: ^4.0.0 # 网络请求
|
||||
path_provider_fde:
|
||||
path: ./plugins/path_provider_fde
|
||||
|
||||
Reference in New Issue
Block a user