修复0AI接入后列表无法触发更新的问题
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../providers/auth_provider.dart';
|
||||
import '../../providers/note_refresh.dart';
|
||||
import '../add/add_page.dart';
|
||||
import '../assistant/assistant_page.dart';
|
||||
import '../home/dashboard_page.dart';
|
||||
@@ -24,12 +25,16 @@ class MainShell extends ConsumerStatefulWidget {
|
||||
ConsumerState<MainShell> createState() => _MainShellState();
|
||||
}
|
||||
|
||||
class _MainShellState extends ConsumerState<MainShell> {
|
||||
class _MainShellState extends ConsumerState<MainShell>
|
||||
with WidgetsBindingObserver {
|
||||
int _index = 0; // 默认选中「首页」
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 监听前后台切换:在电脑上改完笔记 → 切回 App 时数据要是新的。
|
||||
// 这类「绕过 App 的写操作」没有任何通知可听,只能靠这个时机对账。
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
// 兜底:未登录直接回登录页
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!ref.read(authProvider).isLoggedIn) {
|
||||
@@ -38,6 +43,21 @@ class _MainShellState extends ConsumerState<MainShell> {
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
// resumed 才是真正的「回到前台」;inactive/paused 是离开过程中的中间态,
|
||||
// 那些时候对账没意义(用户正在离开),还会白白打请求。
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
refreshNoteDataOnResume(ref);
|
||||
}
|
||||
}
|
||||
|
||||
void _goLogin() {
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
MaterialPageRoute(builder: (_) => const LoginPage()),
|
||||
|
||||
Reference in New Issue
Block a user