|
@@ -1,8 +1,11 @@
|
|
|
import 'dart:async';
|
|
|
|
|
|
+import 'package:fis_common/logger/logger.dart';
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
+import 'package:vitalapp/architecture/app_parameters.dart';
|
|
|
+import 'package:vitalapp/rpc.dart';
|
|
|
import 'package:vitalapp/store/store.dart';
|
|
|
import 'controller.dart';
|
|
|
|
|
@@ -27,28 +30,32 @@ class _ImageAnimationState extends State<ImageAnimation>
|
|
|
late final SplashController _controller;
|
|
|
late AnimationController _animationController;
|
|
|
late Animation<double> _animation;
|
|
|
+ int _callServerTimes = 0;
|
|
|
+
|
|
|
+
|
|
|
+ bool _isLocalStation = false;
|
|
|
+
|
|
|
+ Timer? _serverCheckTimer;
|
|
|
|
|
|
@override
|
|
|
void initState() {
|
|
|
super.initState();
|
|
|
-
|
|
|
+ _isLocalStation = AppParameters.data.isLocalStation;
|
|
|
+ if (_isLocalStation) {
|
|
|
+ _serverCheckTimer = Timer.periodic(
|
|
|
+ Duration(seconds: 1), (Timer t) => checkForConnected());
|
|
|
+ }
|
|
|
_controller = Get.find<SplashController>();
|
|
|
-
|
|
|
final animationCompleter = Completer<void>();
|
|
|
-
|
|
|
Future.wait([
|
|
|
_controller.loadData(),
|
|
|
animationCompleter.future,
|
|
|
]).then((_) {
|
|
|
-
|
|
|
- if (!kIsWeb || Store.user.token == null) {
|
|
|
- _controller.onRouteTo();
|
|
|
+ if (_isLocalStation) {
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if (kIsWeb && Store.user.token != null) {
|
|
|
- Get.offAllNamed("/");
|
|
|
- }
|
|
|
+ _nextPage();
|
|
|
});
|
|
|
|
|
|
|
|
@@ -75,9 +82,37 @@ class _ImageAnimationState extends State<ImageAnimation>
|
|
|
void dispose() {
|
|
|
|
|
|
_animationController.dispose();
|
|
|
+
|
|
|
+ _serverCheckTimer?.cancel();
|
|
|
super.dispose();
|
|
|
}
|
|
|
|
|
|
+ void checkForConnected() async {
|
|
|
+
|
|
|
+ bool isCallSuccess = await callServer();
|
|
|
+
|
|
|
+ if (isCallSuccess) {
|
|
|
+ logger.i('call server success,times:${_callServerTimes}');
|
|
|
+
|
|
|
+ _serverCheckTimer?.cancel();
|
|
|
+ _nextPage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<bool> callServer() async {
|
|
|
+ try {
|
|
|
+ await rpc.vinnoServer.echoAsync();
|
|
|
+ return true;
|
|
|
+ } catch (e) {
|
|
|
+ _callServerTimes++;
|
|
|
+ logger.i('call server times:${_callServerTimes}');
|
|
|
+ if (kDebugMode) {
|
|
|
+ print('call server times:${_callServerTimes}');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
return Scaffold(
|
|
@@ -102,4 +137,16 @@ class _ImageAnimationState extends State<ImageAnimation>
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ void _nextPage() {
|
|
|
+
|
|
|
+ if (!kIsWeb || Store.user.token == null) {
|
|
|
+ _controller.onRouteTo();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (kIsWeb && Store.user.token != null) {
|
|
|
+ Get.offAllNamed("/");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|