Skip to content

Commit

Permalink
Refactor auth check into initState
Browse files Browse the repository at this point in the history
  • Loading branch information
MillerAdulu committed Jul 31, 2024
1 parent 55315f3 commit a60cc3e
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions lib/features/splash/splash_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:flutter/material.dart';
import 'package:fluttercon/common/repository/hive_repository.dart';
import 'package:fluttercon/common/utils/constants/app_assets.dart';
import 'package:fluttercon/common/utils/env/flavor_config.dart';
import 'package:fluttercon/common/utils/router.dart';
import 'package:fluttercon/core/di/injectable.dart';
import 'package:go_router/go_router.dart';
import 'package:hive_flutter/hive_flutter.dart';

class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
Expand All @@ -25,33 +23,32 @@ class _SplashScreenState extends State<SplashScreen> {
}

@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable:
Hive.box<dynamic>(FlutterConConfig.instance!.values.hiveBox)
.listenable(),
builder: (context, _, __) {
final accessToken = getIt<HiveRepository>().retrieveToken();
void initState() {
final accessToken = getIt<HiveRepository>().retrieveToken();

if (accessToken == null) {
_redirectToPage(
context,
FlutterConRouter.signInRoute,
);
} else {
_redirectToPage(
context,
FlutterConRouter.dashboardRoute,
);
}

super.initState();
}

if (accessToken == null) {
_redirectToPage(
context,
FlutterConRouter.signInRoute,
);
} else {
_redirectToPage(
context,
FlutterConRouter.dashboardRoute,
);
}
return const Scaffold(
body: Center(
child: Image(
image: AssetImage(AppAssets.imgDroidcon),
),
),
);
},
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Center(
child: Image(
image: AssetImage(AppAssets.imgDroidcon),
),
),
);
}
}

0 comments on commit a60cc3e

Please sign in to comment.