mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 02:37:55 +00:00
getting spaces and rooms from api {null checks}
This commit is contained in:
@@ -10,50 +10,77 @@ class SplashView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//TODO remove this delay
|
||||
Future.value().then((value) async {
|
||||
var isLoggedIn = await const FlutterSecureStorage()
|
||||
.read(key: Token.loginAccessTokenKey) !=
|
||||
null;
|
||||
if (isLoggedIn) {
|
||||
Navigator.pushReplacementNamed(context, Routes.homeRoute);
|
||||
} else {
|
||||
Navigator.pushReplacementNamed(context, Routes.authLogin);
|
||||
}
|
||||
});
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(
|
||||
Assets.imagesBackground,
|
||||
return FutureBuilder(
|
||||
future: getTokenAndValidate(context),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
if (snapshot.data ?? false) {
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Navigator.pushReplacementNamed(context, Routes.homeRoute);
|
||||
});
|
||||
} else {
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Navigator.pushReplacementNamed(context, Routes.authLogin);
|
||||
});
|
||||
}
|
||||
}
|
||||
return Scaffold(
|
||||
body: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(
|
||||
Assets.imagesBackground,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(Assets.imagesVector),
|
||||
fit: BoxFit.cover,
|
||||
opacity: 0.9,
|
||||
Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(Assets.imagesVector),
|
||||
fit: BoxFit.cover,
|
||||
opacity: 0.9,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SvgPicture.asset(
|
||||
Assets.imagesLogo,
|
||||
width: 240,
|
||||
)
|
||||
],
|
||||
),
|
||||
SvgPicture.asset(
|
||||
Assets.imagesLogo,
|
||||
width: 240,
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> getTokenAndValidate(BuildContext context) async {
|
||||
return await const FlutterSecureStorage()
|
||||
.read(key: Token.loginAccessTokenKey)
|
||||
.then((value) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
print("Decoding token Started");
|
||||
var tokenData = Token.decodeToken(value ?? "");
|
||||
print("checking token data");
|
||||
|
||||
if (tokenData.containsKey('exp')) {
|
||||
var exp = tokenData['exp'] ?? 0;
|
||||
var currentTime = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
print('time: $currentTime exp: $exp');
|
||||
return currentTime < exp;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user