You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
4.6 KiB
165 lines
4.6 KiB
3 years ago
|
import 'dart:async';
|
||
|
import 'package:camera/camera.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:page_transition/page_transition.dart';
|
||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||
|
import 'package:teso/Services/DynamicLinks.dart';
|
||
|
import 'package:teso/Services/locator.dart';
|
||
|
import 'package:teso/main_screen.dart';
|
||
|
import 'package:teso/util/SizeConfig.dart';
|
||
|
import 'package:teso/util/consts.dart';
|
||
|
import 'LandingPage.dart';
|
||
|
import 'package:http/http.dart' as http;
|
||
|
|
||
|
class Splash extends StatefulWidget {
|
||
|
@override
|
||
|
_SplashState createState() => _SplashState();
|
||
|
}
|
||
|
|
||
|
class _SplashState extends State<Splash> with TickerProviderStateMixin {
|
||
|
List<CameraDescription> connectedCameras;
|
||
|
Animation<double> _animation;
|
||
|
AnimationController _controller;
|
||
|
final DynamicLinkService _dynamicLinkService = locator<DynamicLinkService>();
|
||
|
|
||
|
gotoPersonnalServer() {
|
||
|
_controller = AnimationController(
|
||
|
duration: const Duration(milliseconds: 2000), vsync: this, value: 0.1);
|
||
|
_animation =
|
||
|
CurvedAnimation(parent: _controller, curve: Curves.bounceInOut);
|
||
|
|
||
|
_controller.forward();
|
||
|
}
|
||
|
|
||
|
var timeout = const Duration(seconds: 2);
|
||
|
var ms = const Duration(milliseconds: 1);
|
||
|
|
||
|
bool gone = false;
|
||
|
|
||
|
startTimeout() {
|
||
|
// return new Timer(Duration(seconds: 5), loggedIn);
|
||
|
loggedIn();
|
||
|
}
|
||
|
|
||
|
void handleTimeout() {
|
||
|
changeScreen();
|
||
|
}
|
||
|
|
||
|
changeScreen() async {
|
||
|
Navigator.pushReplacement(
|
||
|
context,
|
||
|
PageTransition(
|
||
|
type: PageTransitionType.rightToLeft,
|
||
|
child: LandingPage(
|
||
|
connectedCameras: connectedCameras,
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
//Provider.of<HomeProvider>(context, listen: false).getFeeds();
|
||
|
}
|
||
|
|
||
|
void loggedIn() async {
|
||
|
await _dynamicLinkService.handleDynamicLinks();
|
||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||
|
String tokens = prefs.getString("tokensTeso");
|
||
|
if (tokens != null) {
|
||
|
Navigator.pushReplacement(
|
||
|
context,
|
||
|
PageTransition(
|
||
|
type: PageTransitionType.rightToLeft,
|
||
|
child: MainScreens(
|
||
|
connectedCameras: connectedCameras,
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
} else {
|
||
|
changeScreen();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Future<bool> apiversionCheck() async {
|
||
|
try {
|
||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||
|
String token = prefs.getString('tokensTeso');
|
||
|
Map<String, String> requestHeaders = {
|
||
|
'Content-type': 'application/json',
|
||
|
'Authorization': token
|
||
|
};
|
||
|
var register = serverLocation + 'api/version/current';
|
||
|
var client = await http.get(Uri.parse(register)).timeout(
|
||
|
const Duration(seconds: 5),
|
||
|
onTimeout: () {
|
||
|
return http.Response(
|
||
|
'Error', 408); // Request Timeout response status code
|
||
|
},
|
||
|
);
|
||
|
if (client.statusCode == 200) {
|
||
|
String currentVersion = prefs.getString("api-version") != null
|
||
|
? prefs.getString("api-version")
|
||
|
: "";
|
||
|
if (currentVersion != client.body) {
|
||
|
try {
|
||
|
var register = Uri.parse(serverLocation + 'api/logout');
|
||
|
await http.get(register, headers: requestHeaders);
|
||
|
} catch (_) {}
|
||
|
await prefs.clear();
|
||
|
await prefs.setBool("launched", true);
|
||
|
await prefs.setString("api-version", client.body);
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
} catch (e) {
|
||
|
print(e);
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
gotoPersonnalServer();
|
||
|
availableCameras().then((value) {
|
||
|
connectedCameras = value;
|
||
|
});
|
||
|
apiversionCheck().then((t) => {startTimeout()});
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
SizeConfig().init(context);
|
||
|
return Scaffold(
|
||
|
backgroundColor: Colors.white,
|
||
|
body: Center(
|
||
|
child: Column(
|
||
|
// mainAxisSize: MainAxisSize.max,
|
||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
children: <Widget>[
|
||
|
Container(
|
||
|
alignment: Alignment.center,
|
||
|
child: ScaleTransition(
|
||
|
scale: _animation,
|
||
|
child: Image.asset(
|
||
|
"assets/images/tesoCouponInsignia.png",
|
||
|
width: 80.0,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
SizedBox(
|
||
|
height: 20,
|
||
|
),
|
||
|
Text(
|
||
|
"${Constants.appName}",
|
||
|
style: TextStyle(
|
||
|
color: tesoGold,
|
||
|
fontSize: 25,
|
||
|
fontWeight: FontWeight.bold,
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|