Эх сурвалжийг харах

全局设置rpc请求加密

Melon 1 жил өмнө
parent
commit
e42000809d

+ 17 - 4
lib/pages/splash/controller.dart

@@ -1,11 +1,15 @@
+import 'dart:async';
+
 import 'package:get/get.dart';
 import 'package:vnoteapp/architecture/defines.dart';
+import 'package:vnoteapp/rpc.dart';
 import 'package:vnoteapp/store/store.dart';
 import 'state.dart';
 
 class SplashController extends FControllerBase {
   final state = SplashState();
 
+  /// 跳转路由
   void onRouteTo() async {
     if (Store.user.isLogOn) {
       Get.offAllNamed("/");
@@ -14,11 +18,20 @@ class SplashController extends FControllerBase {
     }
   }
 
-  @override
-  void onReady() {
-    //
+  /// 加载数据
+  Future<void> loadData() async {
+    await Future.wait([
+      _loadServerSettings(),
+      // 其他异步加载项
+    ]);
+  }
 
-    super.onReady();
+  /// 加载服务配置
+  Future<void> _loadServerSettings() async {
+    // TODO: 调用接口
+    await Future.delayed(const Duration(milliseconds: 800));
+    // TODO: 在Manager中设置
+    rpc.enableRequestEncrypt = true;
   }
 
   @override

+ 22 - 8
lib/pages/splash/view.dart

@@ -1,3 +1,5 @@
+import 'dart:async';
+
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 import 'controller.dart';
@@ -7,7 +9,6 @@ class SplashPage extends GetView<SplashController> {
 
   @override
   Widget build(BuildContext context) {
-    // TODO:
     return const ImageAnimation();
   }
 }
@@ -21,29 +22,42 @@ class ImageAnimation extends StatefulWidget {
 
 class _ImageAnimationState extends State<ImageAnimation>
     with SingleTickerProviderStateMixin {
-  late AnimationController _controller;
+  late final SplashController _controller;
+  late AnimationController _animationController;
   late Animation<double> _animation;
 
   @override
   void initState() {
     super.initState();
 
+    _controller = Get.find<SplashController>();
+
+    final animationCompleter = Completer<void>();
+
+    Future.wait([
+      _controller.loadData(),
+      animationCompleter.future,
+    ]).then((_) {
+      // 等待动画和数据加载,全部完成后跳转路由
+      _controller.onRouteTo();
+    });
+
     // 创建动画控制器
-    _controller = AnimationController(
+    _animationController = AnimationController(
       duration: const Duration(milliseconds: 4200),
       vsync: this,
     );
 
     // 创建动画
-    _animation = Tween<double>(begin: 0, end: 1).animate(_controller);
+    _animation = Tween<double>(begin: 0, end: 1).animate(_animationController);
 
     // 启动动画
-    _controller.forward();
+    _animationController.forward();
 
-    _controller.addStatusListener((status) {
+    _animationController.addStatusListener((status) {
       if (status == AnimationStatus.completed) {
         // 动画结束
-        Get.find<SplashController>().onRouteTo();
+        animationCompleter.complete();
       }
     });
   }
@@ -51,7 +65,7 @@ class _ImageAnimationState extends State<ImageAnimation>
   @override
   void dispose() {
     // 销毁动画控制器
-    _controller.dispose();
+    _animationController.dispose();
     super.dispose();
   }
 

+ 1 - 1
pubspec.yaml

@@ -74,7 +74,7 @@ dependencies_overrides:
   fis_jsonrpc:
     git:
       url: http://git.ius.plus:88/Project-VNOTE/FlutterJsonRPC.git
-      ref: "f7e2c4c"
+      ref: c2a08f8153
   # fis_ui:
   #   git:
   #     url: http://git.ius.plus:88/Project-Wing/fis_lib_ui.git