更新数据库
This commit is contained in:
@@ -11,14 +11,22 @@ import '../../data/local/drift/app_database.dart';
|
||||
/// 用法:
|
||||
/// ```dart
|
||||
/// // 登录后开库
|
||||
/// await ref.read(storageSdkProvider).openDatabase(user.id);
|
||||
/// await ref.read(storageSdkLifecycleProvider).openDatabase(user.id);
|
||||
///
|
||||
/// // CRUD 示例
|
||||
/// final db = ref.read(storageSdkProvider);
|
||||
/// await db.insertOrReplace(appDb.users, companion);
|
||||
/// await db.insertOrReplace<UsersCompanion>(companion);
|
||||
/// final users = await db.selectAll<User>();
|
||||
/// ```
|
||||
|
||||
final storageSdkProvider = Provider<StorageSdkApi>((ref) {
|
||||
return StorageSdkApi(
|
||||
databaseFactory: (executor) => AppDatabase(executor),
|
||||
tableRegistry: (db) => AppDatabase.getTableRegistry(db),
|
||||
);
|
||||
});
|
||||
|
||||
/// 生命周期管理,仅供登录/登出使用。
|
||||
final storageSdkLifecycleProvider = Provider<StorageSdkLifecycle>((ref) {
|
||||
return ref.read(storageSdkProvider) as StorageSdkLifecycle;
|
||||
});
|
||||
@@ -64,6 +64,7 @@ enum AppRouteName {
|
||||
chatDetail('/chat/detail'),
|
||||
// 路径参数形式:导航用 AppRouteName.chatDetailByIdPath(id),不直接用 .path
|
||||
chatDetailById('/chat/:id'),
|
||||
chatDBTest('/chat/dbTest'),
|
||||
|
||||
// ── Settings 子路由 ───────────────────────────────────────────────────────
|
||||
settingsTheme('/settings/theme'),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:im_app/features/chat/view/chat_db_test_page.dart';
|
||||
|
||||
import '../../features/app_tab/view/app_tab.dart';
|
||||
import '../../features/chat/view/chat_detail_page.dart';
|
||||
@@ -115,6 +116,13 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
// parentNavigatorKey: _rootKey 确保路由覆盖 Shell,TabBar 消失
|
||||
//
|
||||
// extra 传参:接收 ({String conversationId, String title})
|
||||
GoRoute(
|
||||
parentNavigatorKey: _rootKey,
|
||||
path: AppRouteName.chatDBTest.path,
|
||||
builder: (context, state) {
|
||||
return const ChatDbTestPage();
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
parentNavigatorKey: _rootKey,
|
||||
path: AppRouteName.chatDetail.path,
|
||||
|
||||
@@ -34,13 +34,13 @@ String? authGuard(AuthNotifier authNotifier, GoRouterState state) {
|
||||
case AppRouteName.login:
|
||||
// 已登录还在登录页 → 跳聊天页
|
||||
return isLoggedIn ? AppRouteName.chat.path : null;
|
||||
|
||||
case AppRouteName.chat:
|
||||
case AppRouteName.chatDetail:
|
||||
case AppRouteName.chatDetailById:
|
||||
case AppRouteName.contact:
|
||||
case AppRouteName.settings:
|
||||
case AppRouteName.settingsTheme:
|
||||
case AppRouteName.chatDBTest:
|
||||
// 受保护路由 → 未登录跳登录页
|
||||
return isLoggedIn ? null : AppRouteName.login.path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user