refactor(splash) : Adjusted splash page and utilized flutter hooks#25
refactor(splash) : Adjusted splash page and utilized flutter hooks#25breadoncee wants to merge 2 commits intomasterfrom
Conversation
|
@gemini-code-assist review this |
There was a problem hiding this comment.
Code Review
This pull request is a great refactoring of the splash screen. It successfully transitions from a StatefulWidget to a HookWidget, which simplifies the code and improves its structure by extracting logic into a custom hook. The file organization has also been improved by moving splash-related files into a dedicated directory. I have a couple of minor suggestions to further enhance the code quality and align with best practices.
| class StackedBoxes extends StatelessWidget { | ||
| const StackedBoxes({super.key}); | ||
| class _StackedBoxes extends StatelessWidget { | ||
| const _StackedBoxes(); |
There was a problem hiding this comment.
| Future<void> checkFirstInstall(BuildContext context) async { | ||
| await Future.delayed(const Duration(seconds: 2)); | ||
| SharedPreferences prefs = await SharedPreferences.getInstance(); | ||
| final firstInstall = prefs.getBool('firstInstall') ?? true; | ||
|
|
||
| if (context.mounted) { | ||
| if (firstInstall) { | ||
| context.pushReplacement(Routes.onboarding); | ||
| prefs.setBool('firstInstall', false); | ||
| } else { | ||
| context.pushReplacement(Routes.authHome); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
The checkFirstInstall function is defined inside the useSplashPage hook, which means it gets recreated on every render. For better performance and code organization, this function should be extracted into a private top-level function within this file (e.g., _checkFirstInstall).
Example:
part of 'splash.dart';
double useSplashPage() {
final context = useContext();
// ... other hooks
useEffect(() {
WidgetsBinding.instance.addPostFrameCallback((_) async {
await _checkFirstInstall(context);
});
return null;
}, []);
return breathe;
}
Future<void> _checkFirstInstall(BuildContext context) async {
// ... implementation
}
No description provided.