step 22 : add check obejct xmodel di splash screen
This commit is contained in:
@@ -21,53 +21,116 @@ class SplashScreen extends HookConsumerWidget {
|
||||
SystemUiOverlay.bottom,
|
||||
]);
|
||||
|
||||
// useEffect(() {
|
||||
// WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||
// final shared = await SharedPreferences.getInstance();
|
||||
// final bearerString = shared.getString(Constant.bearerName);
|
||||
|
||||
// if (bearerString == null || bearerString == "null") {
|
||||
// Timer(const Duration(seconds: 3), () {
|
||||
// Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
// loginRoute,
|
||||
// (route) => false,
|
||||
// );
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
|
||||
// final xmodel = jsonDecode(bearerString);
|
||||
// if (xmodel == null) return;
|
||||
|
||||
// final authModel = AuthModel(
|
||||
// host: xmodel["host"],
|
||||
// token: xmodel["token"],
|
||||
// model: UserModel(
|
||||
// userId: xmodel["model"]['M_UserID'],
|
||||
// username: xmodel["model"]['M_UserUsername'],
|
||||
// groupDashboard: xmodel["model"]['M_UserGroupDashboard'],
|
||||
// defaultSampleStationId: xmodel["model"]
|
||||
// ['M_UserDefaultT_SampleStationID'],
|
||||
// staffName: xmodel["model"]['M_StaffName'],
|
||||
// isCourier: xmodel["model"]['is_courier'],
|
||||
// timeAutoLogout: xmodel["model"]['time_autologout'],
|
||||
// ip: xmodel["model"]['ip'],
|
||||
// agent: xmodel["model"]['agent'],
|
||||
// version: xmodel["model"]['version'],
|
||||
// lastLogin: xmodel["model"]['last-login'],
|
||||
// satelliteId: xmodel["model"]['M_SatelliteID'],
|
||||
// ),
|
||||
// );
|
||||
|
||||
// ref.read(currentUserProvider.notifier).state = authModel;
|
||||
|
||||
// Timer(const Duration(seconds: 3), () {
|
||||
// Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
// homeRoute,
|
||||
// (route) => false,
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
// return () {};
|
||||
// }, []);
|
||||
|
||||
void _goToLogin() {
|
||||
Timer(const Duration(seconds: 2), () {
|
||||
Navigator.of(context)
|
||||
.pushNamedAndRemoveUntil(loginRoute, (route) => false);
|
||||
});
|
||||
}
|
||||
|
||||
void _goToHome() {
|
||||
Timer(const Duration(seconds: 2), () {
|
||||
Navigator.of(context)
|
||||
.pushNamedAndRemoveUntil(homeRoute, (route) => false);
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
final shared = await SharedPreferences.getInstance();
|
||||
final bearerString = shared.getString(Constant.bearerName);
|
||||
|
||||
if (bearerString == null || bearerString == "null") {
|
||||
Timer(const Duration(seconds: 3), () {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
loginRoute,
|
||||
(route) => false,
|
||||
);
|
||||
});
|
||||
_goToLogin();
|
||||
return;
|
||||
}
|
||||
|
||||
final xmodel = jsonDecode(bearerString);
|
||||
if (xmodel == null) return;
|
||||
try {
|
||||
final xmodel = jsonDecode(bearerString);
|
||||
if (xmodel == null ||
|
||||
xmodel["token"] == null ||
|
||||
xmodel["model"] == null) {
|
||||
_goToLogin();
|
||||
return;
|
||||
}
|
||||
|
||||
final authModel = AuthModel(
|
||||
host: xmodel["host"],
|
||||
token: xmodel["token"],
|
||||
model: UserModel(
|
||||
userId: xmodel["model"]['M_UserID'],
|
||||
username: xmodel["model"]['M_UserUsername'],
|
||||
groupDashboard: xmodel["model"]['M_UserGroupDashboard'],
|
||||
defaultSampleStationId: xmodel["model"]
|
||||
['M_UserDefaultT_SampleStationID'],
|
||||
staffName: xmodel["model"]['M_StaffName'],
|
||||
isCourier: xmodel["model"]['is_courier'],
|
||||
timeAutoLogout: xmodel["model"]['time_autologout'],
|
||||
ip: xmodel["model"]['ip'],
|
||||
agent: xmodel["model"]['agent'],
|
||||
version: xmodel["model"]['version'],
|
||||
lastLogin: xmodel["model"]['last-login'],
|
||||
satelliteId: xmodel["model"]['M_SatelliteID'],
|
||||
),
|
||||
);
|
||||
|
||||
ref.read(currentUserProvider.notifier).state = authModel;
|
||||
|
||||
Timer(const Duration(seconds: 3), () {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
homeRoute,
|
||||
(route) => false,
|
||||
final authModel = AuthModel(
|
||||
host: xmodel["host"],
|
||||
token: xmodel["token"],
|
||||
model: UserModel(
|
||||
userId: xmodel["model"]['M_UserID'],
|
||||
username: xmodel["model"]['M_UserUsername'],
|
||||
groupDashboard: xmodel["model"]['M_UserGroupDashboard'],
|
||||
defaultSampleStationId: xmodel["model"]
|
||||
['M_UserDefaultT_SampleStationID'],
|
||||
staffName: xmodel["model"]['M_StaffName'],
|
||||
isCourier: xmodel["model"]['is_courier'],
|
||||
timeAutoLogout: xmodel["model"]['time_autologout'],
|
||||
ip: xmodel["model"]['ip'],
|
||||
agent: xmodel["model"]['agent'],
|
||||
version: xmodel["model"]['version'],
|
||||
lastLogin: xmodel["model"]['last-login'],
|
||||
satelliteId: xmodel["model"]['M_SatelliteID'],
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
ref.read(currentUserProvider.notifier).state = authModel;
|
||||
_goToHome();
|
||||
} catch (e) {
|
||||
_goToLogin(); // Jika error parsing, fallback ke login
|
||||
}
|
||||
});
|
||||
|
||||
return () {};
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user