构建初步的设备运行悬浮状态栏,已实现初步的的悬浮和开关功能。
优化了登录链条适配多种用户的登录操作
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_patcher/flutter_patcher.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
// 悬浮条相关
|
||||
import 'features/v2/device_list/presentation/float_bar/float_bar_controller.dart';
|
||||
import 'features/v2/device_list/presentation/float_bar/simple_float_bar.dart';
|
||||
|
||||
import 'package:maibu_satabot_v2/core/app/app_user_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/core/infrastructure/logging/app_bloc_observer.dart';
|
||||
import 'package:maibu_satabot_v2/core/logging/i_logger_service.dart';
|
||||
@@ -19,8 +23,13 @@ import 'package:maibu_satabot_v2/features/auth/presentation/bloc/auth_cubit.dart
|
||||
import 'package:maibu_satabot_v2/features/devices/presentation/bloc/devices_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/main_container/presentation/cubit/tab_config_cubit.dart';
|
||||
import 'package:maibu_satabot_v2/features/main_container/presentation/main_wrapper.dart';
|
||||
// 🔥 导入悬浮条管理器和设置服务
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/float_bar/manager/float_bar_manager.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/float_bar/view/float_bar_widget.dart';
|
||||
import 'package:maibu_satabot_v2/features/v2/device_list/presentation/float_bar/cubit/float_bar_setting_cubit.dart';
|
||||
|
||||
import 'core/di/injection.dart';
|
||||
import 'core/router/route_paths.dart';
|
||||
import 'core/localization/app_localizations.dart';
|
||||
import 'core/localization/locale_cubit.dart';
|
||||
import 'features/auth/presentation/bloc/auth_state.dart';
|
||||
@@ -28,6 +37,9 @@ import 'features/auth/presentation/bloc/login_cubit.dart';
|
||||
import 'features/devices/presentation/bloc/device_status_bloc.dart';
|
||||
import 'features/home/presentation/bloc/permission_request_bloc.dart';
|
||||
|
||||
// 🔥 全局 GetIt 实例
|
||||
final sl = GetIt.instance;
|
||||
|
||||
// 🔥 定义全局 Navigator Key
|
||||
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
@@ -38,10 +50,17 @@ void main() async {
|
||||
|
||||
await FlutterPatcher.init();
|
||||
await init();
|
||||
|
||||
final logger = sl<ILoggerService>();
|
||||
await logger.init();
|
||||
Bloc.observer = AppBlocObserver(logger);
|
||||
|
||||
// 🔥 确保 FloatBarSettingService 被初始化,这样 settingNotifier 才不会是 null
|
||||
sl<FloatBarSettingService>();
|
||||
debugPrint(
|
||||
'🔍 [FloatBar] FloatBarSettingService 已初始化,settingNotifier: ${FloatBarSettingService.settingNotifier}',
|
||||
);
|
||||
|
||||
// ⚠️ 注意:不要在启动时清除补丁版本记录!
|
||||
// 补丁版本记录只在整包更新成功后才清除
|
||||
// 如果在启动时清除,会导致差量更新后划掉App再进入时循环更新
|
||||
@@ -102,7 +121,23 @@ class MyApp extends StatelessWidget {
|
||||
theme: AppTheme.lightTheme,
|
||||
routerConfig: sl<GoRouter>(),
|
||||
builder: (context, child) {
|
||||
return _LifecycleListener(child: _UpdateChecker(child: child!));
|
||||
// 🔥 初始化悬浮条管理器并显示悬浮条
|
||||
debugPrint(
|
||||
'======== [FloatBar] MaterialApp.builder START ========',
|
||||
);
|
||||
debugPrint('🔍 [FloatBar] child: $child');
|
||||
debugPrint(
|
||||
'🔍 [FloatBar] settingNotifier: ${FloatBarSettingService.settingNotifier}',
|
||||
);
|
||||
debugPrint(
|
||||
'🔍 [FloatBar] isEnabled: ${FloatBarSettingService.isEnabled}',
|
||||
);
|
||||
debugPrint(
|
||||
'======== [FloatBar] MaterialApp.builder END ========',
|
||||
);
|
||||
return _FloatBarInitializer(
|
||||
child: _LifecycleListener(child: _UpdateChecker(child: child!)),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -111,6 +146,35 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// 悬浮条初始化组件 - 极简版
|
||||
class _FloatBarInitializer extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
const _FloatBarInitializer({required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: FloatBarController.visibilityNotifier,
|
||||
builder: (context, isVisible, child) {
|
||||
return Stack(
|
||||
children: [
|
||||
child!,
|
||||
if (isVisible)
|
||||
const Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: SimpleFloatBar(),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LifecycleListener extends StatefulWidget {
|
||||
final Widget? child;
|
||||
const _LifecycleListener({required this.child});
|
||||
@@ -247,6 +311,7 @@ class _UpdateCheckerState extends State<_UpdateChecker> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 💡 选择下载方式
|
||||
const Text(
|
||||
'💡 选择下载方式',
|
||||
style: TextStyle(
|
||||
|
||||
Reference in New Issue
Block a user