import 'dart:async'; import 'package:flutter/widgets.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import '../log/log.dart'; class TokenT { String token; String domain; String videoPath; TokenT(this.token, this.domain, this.videoPath); } class Token { static final Token _token = Token._(); final _storage = const FlutterSecureStorage(); String _tokenval = ""; String _domain = ""; String _vPath = ""; static Token getInstance() { return _token; } Future getToken() async { if (_tokenval == "" || _domain == "" || _vPath == "") { Log.d("reading token store"); WidgetsFlutterBinding.ensureInitialized(); final token = await _storage.read(key: 'jwt'); final domain = await _storage.read(key: 'domain'); final vPath = await _storage.read(key: 'videoPath'); // check if value is defined in phone store if (token != null && domain != null && vPath != null) { _tokenval = token; _domain = domain; return TokenT(token, domain, vPath); } else { Log.d("no token defined"); return null; } } else { return TokenT(_tokenval, _domain, _vPath); } } void setToken(String token, String domain, String videoPath) { _tokenval = token; _domain = domain; _vPath = videoPath; _storage.write(key: 'jwt', value: token); _storage.write(key: 'domain', value: domain); _storage.write(key: 'videoPath', value: videoPath); } Token._(); }