diff --git a/lib/launch_screen.dart b/lib/launch_screen.dart index 82cccbf..ee8da96 100644 --- a/lib/launch_screen.dart +++ b/lib/launch_screen.dart @@ -14,7 +14,6 @@ class LaunchScreen extends StatefulWidget { } class _LaunchScreenState extends State { - late Timer _timer; @override void initState() { super.initState(); @@ -50,7 +49,7 @@ class _LaunchScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - 'TeleMedNet', + 'TelemedNet', style: Theme.of(context).textTheme.titleLarge, ), StreamBuilder( @@ -61,26 +60,7 @@ class _LaunchScreenState extends State { ConnectionState.waiting) { return const CircularProgressIndicator(); } else if (snapshot.hasData) { - _timer = - Timer(const Duration(seconds: 3), () { - try { - DataService.getProfile() - .then((profile) { - if (profile == null) { - // ignore: use_build_context_synchronously - Navigator.of(context) - .pushReplacementNamed( - RouteNames.userProfile); - } else { - // ignore: use_build_context_synchronously - Navigator.of(context) - .pushReplacementNamed( - RouteNames.userHome); - } - }); - } finally {} - _timer.cancel(); - }); + _fetchProfileAndNavigate(context); return _buildProceedingWidget(context); } else { return _buildSignInSignUpRow(context); @@ -94,6 +74,19 @@ class _LaunchScreenState extends State { ))); } + Future _fetchProfileAndNavigate(BuildContext context) async { + var profile = await DataService.getProfile(); + if (mounted) { + setState(() { + if (profile == null) { + Navigator.of(context).pushReplacementNamed(RouteNames.userProfile); + } else { + Navigator.of(context).pushReplacementNamed(RouteNames.userHome); + } + }); + } + } + Widget _buildProceedingWidget(BuildContext context) { return const Column( children: [