diff --git a/README.md b/README.md index eac8989..9e653f8 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,3 @@ # pogdark -A new Flutter project. - -## Getting Started - -This project is a starting point for a Flutter application. - -A few resources to get you started if this is your first Flutter project: - -- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) -- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) - -For help getting started with Flutter development, view the -[online documentation](https://docs.flutter.dev/), which offers tutorials, -samples, guidance on mobile development, and a full API reference. +This is pogdark \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index f56fd48..4a9d2af 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -32,15 +32,18 @@ class MyAppState extends State { @override void initState() { super.initState(); - _prefsReady = - Provider.of(context, listen: false).ready; + + // Retrieve SharedPreferencesProvider instance outside async function + final prefsProvider = + Provider.of(context, listen: false); + _prefsReady = prefsProvider.ready; + _prefsReady!.then((_) { - final prefsProvider = - Provider.of(context, listen: false); - // Check if username is not set; if so, show ProfileScreen initially - if (prefsProvider.getUserName().isEmpty) { + // Ensure the widget is still mounted before updating state + if (mounted) { setState(() { - showProfileInitially = true; + // Check if the username is not set, then show ProfileScreen initially + showProfileInitially = prefsProvider.getUserName().isEmpty; }); } }); @@ -89,8 +92,7 @@ class MyAppState extends State { child: Center( child: ProfileScreen( isEditing: false, - onClose: - closeInitialProfileScreen, // Close after setup + onClose: closeInitialProfileScreen, ), ), ), @@ -103,7 +105,7 @@ class MyAppState extends State { child: Center( child: ProfileScreen( isEditing: true, - onClose: toggleProfileScreen, // Toggle on edit + onClose: toggleProfileScreen, ), ), ),