2021-12-10 10:40:20 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
2021-12-11 12:33:46 +00:00
|
|
|
|
|
|
|
import '../log/log.dart';
|
2021-12-10 10:40:20 +00:00
|
|
|
|
2021-12-11 16:17:38 +00:00
|
|
|
class TokenT {
|
|
|
|
String token;
|
|
|
|
String domain;
|
2022-09-02 16:42:38 +00:00
|
|
|
String videoPath;
|
2021-12-11 16:17:38 +00:00
|
|
|
|
2022-09-02 16:42:38 +00:00
|
|
|
TokenT(this.token, this.domain, this.videoPath);
|
2021-12-11 16:17:38 +00:00
|
|
|
}
|
|
|
|
|
2021-12-10 10:40:20 +00:00
|
|
|
class Token {
|
|
|
|
static final Token _token = Token._();
|
|
|
|
final _storage = const FlutterSecureStorage();
|
|
|
|
|
|
|
|
String _tokenval = "";
|
2021-12-11 16:17:38 +00:00
|
|
|
String _domain = "";
|
2022-09-02 16:42:38 +00:00
|
|
|
String _vPath = "";
|
2021-12-10 10:40:20 +00:00
|
|
|
|
|
|
|
static Token getInstance() {
|
|
|
|
return _token;
|
|
|
|
}
|
|
|
|
|
2021-12-11 16:17:38 +00:00
|
|
|
Future<TokenT?> getToken() async {
|
2022-09-02 16:42:38 +00:00
|
|
|
if (_tokenval == "" || _domain == "" || _vPath == "") {
|
2021-12-11 16:17:38 +00:00
|
|
|
Log.d("reading token store");
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
final token = await _storage.read(key: 'jwt');
|
|
|
|
final domain = await _storage.read(key: 'domain');
|
2022-09-02 16:42:38 +00:00
|
|
|
final vPath = await _storage.read(key: 'videoPath');
|
2022-04-15 07:16:41 +00:00
|
|
|
|
2021-12-11 12:33:46 +00:00
|
|
|
// check if value is defined in phone store
|
2022-09-02 16:42:38 +00:00
|
|
|
if (token != null && domain != null && vPath != null) {
|
2022-04-15 07:16:41 +00:00
|
|
|
_tokenval = token;
|
|
|
|
_domain = domain;
|
2022-09-02 16:42:38 +00:00
|
|
|
return TokenT(token, domain, vPath);
|
2021-12-11 12:33:46 +00:00
|
|
|
} else {
|
|
|
|
Log.d("no token defined");
|
2022-09-02 16:42:38 +00:00
|
|
|
return null;
|
2021-12-11 12:33:46 +00:00
|
|
|
}
|
2021-12-10 10:40:20 +00:00
|
|
|
} else {
|
2022-09-02 16:42:38 +00:00
|
|
|
return TokenT(_tokenval, _domain, _vPath);
|
2021-12-10 10:40:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-02 16:42:38 +00:00
|
|
|
void setToken(String token, String domain, String videoPath) {
|
2021-12-10 10:40:20 +00:00
|
|
|
_tokenval = token;
|
2021-12-11 16:17:38 +00:00
|
|
|
_domain = domain;
|
2022-09-02 16:42:38 +00:00
|
|
|
_vPath = videoPath;
|
2021-12-10 10:40:20 +00:00
|
|
|
_storage.write(key: 'jwt', value: token);
|
2021-12-11 16:17:38 +00:00
|
|
|
_storage.write(key: 'domain', value: domain);
|
2022-09-02 16:42:38 +00:00
|
|
|
_storage.write(key: 'videoPath', value: videoPath);
|
2021-12-10 10:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Token._();
|
|
|
|
}
|