feat: 新增站内消息系统,支持通知与订单跳转
This commit is contained in:
1 parent
411ec8be23
commit
c799b62f6b
14 files changed
+464
-9
No files matched your search
+50
-2
@@ -1,19 +1,67 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../core/app_keys.dart';
|
||||
import '../core/notifications/keep_alive.dart';
|
||||
import '../core/notifications/local_notifications.dart';
|
||||
import '../core/theme/app_theme.dart';
|
||||
import '../core/theme/app_typography.dart';
|
||||
import '../features/auth/application/session_controller.dart';
|
||||
import '../features/notice/application/notice_alert_controller.dart';
|
||||
import 'router.dart';
|
||||
|
||||
class VoltLinkApp extends ConsumerWidget {
|
||||
class VoltLinkApp extends ConsumerStatefulWidget {
|
||||
const VoltLinkApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
ConsumerState<VoltLinkApp> createState() => _VoltLinkAppState();
|
||||
}
|
||||
|
||||
class _VoltLinkAppState extends ConsumerState<VoltLinkApp> {
|
||||
StreamSubscription<String>? _tapSub;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 运行期点击系统通知 → 跳转对应页面
|
||||
_tapSub = LocalNotifications.instance.taps.listen(_openRoute);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// 冷启动由通知拉起时,初始化阶段已把路由暂存下来
|
||||
final route = LocalNotifications.instance.takeLaunchRoute();
|
||||
if (route != null) _openRoute(route);
|
||||
// 已登录则开启 Android 前台服务
|
||||
unawaited(
|
||||
BackgroundKeepAlive.setEnabled(ref.read(sessionProvider).isLoggedIn),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tapSub?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _openRoute(String route) {
|
||||
if (!mounted || route.isEmpty) return;
|
||||
ref.read(routerProvider).go(route);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final router = ref.watch(routerProvider);
|
||||
|
||||
// 登录/登出时同步 Android 前台服务开关
|
||||
ref.listen(sessionProvider.select((s) => s.isLoggedIn), (_, loggedIn) {
|
||||
unawaited(BackgroundKeepAlive.setEnabled(loggedIn));
|
||||
});
|
||||
|
||||
// 激活站内消息提醒轮询
|
||||
ref.watch(noticeAlertProvider);
|
||||
|
||||
return MaterialApp.router(
|
||||
title: 'VoltLink',
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
||||
Reference in new issue
Block a user