Skip to content

Commit 41669c6

Browse files
committed
不同用户不同数据库
1 parent d0da7a6 commit 41669c6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/common/ab/SqlManager.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'dart:async';
22
import 'dart:io';
33

4+
import 'package:gsy_github_app_flutter/common/dao/UserDao.dart';
5+
import 'package:gsy_github_app_flutter/common/model/User.dart';
46
import 'package:sqflite/sqflite.dart';
57

68
/**
@@ -20,9 +22,17 @@ class SqlManager {
2022
static init() async {
2123
// open the database
2224
var databasesPath = await getDatabasesPath();
23-
String path = databasesPath + _NAME;
25+
var userRes= await UserDao.getUserInfoLocal();
26+
String dbName = _NAME;
27+
if(userRes != null && userRes.result) {
28+
User user = userRes.data;
29+
if(user != null && user.login != null) {
30+
dbName = user.login + "_" + _NAME;
31+
}
32+
}
33+
String path = databasesPath + dbName;
2434
if (Platform.isIOS) {
25-
path = databasesPath + "/" + _NAME;
35+
path = databasesPath + "/" + dbName;
2636
}
2737
_database = await openDatabase(path, version: _VERSION, onCreate: (Database db, int version) async {
2838
// When creating the db, create the table

0 commit comments

Comments
 (0)