-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve speech profile widget handling #871
Changes from 2 commits
c7ff072
10ce9df
9166b51
9e5581c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ class _OnboardingWrapperState extends State<OnboardingWrapper> with TickerProvid | |
SpeechProfileWidget( | ||
goNext: () { | ||
if (context.read<SpeechProfileProvider>().memory == null) { | ||
_controller!.animateTo(_controller!.index + 2); | ||
routeToPage(context, const HomePageWrapper(), replace: true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change from an animation call to a route navigation call could potentially disrupt the user experience. If the - routeToPage(context, const HomePageWrapper(), replace: true);
+ _controller!.animateTo(_controller!.index + 2); |
||
} else { | ||
_goNext(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ class HomeProvider extends ChangeNotifier { | |
final FocusNode chatFieldFocusNode = FocusNode(); | ||
bool isMemoryFieldFocused = false; | ||
bool isChatFieldFocused = false; | ||
bool hasSpeakerProfile = false; | ||
bool isLoading = false; | ||
|
||
HomeProvider() { | ||
memoryFieldFocusNode.addListener(_onFocusChange); | ||
|
@@ -27,10 +29,24 @@ class HomeProvider extends ChangeNotifier { | |
notifyListeners(); | ||
} | ||
|
||
void setIsLoading(bool loading) { | ||
isLoading = loading; | ||
notifyListeners(); | ||
} | ||
|
||
void setSpeakerProfile(bool? value) { | ||
hasSpeakerProfile = value ?? SharedPreferencesUtil().hasSpeakerProfile; | ||
notifyListeners(); | ||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - hasSpeakerProfile = value ?? SharedPreferencesUtil().hasSpeakerProfile;
+ if (value != null) {
+ hasSpeakerProfile = value;
+ } |
||
} | ||
|
||
Future setupHasSpeakerProfile() async { | ||
SharedPreferencesUtil().hasSpeakerProfile = await userHasSpeakerProfile(); | ||
setIsLoading(true); | ||
var res = await userHasSpeakerProfile(); | ||
setSpeakerProfile(res); | ||
SharedPreferencesUtil().hasSpeakerProfile = res; | ||
debugPrint('_setupHasSpeakerProfile: ${SharedPreferencesUtil().hasSpeakerProfile}'); | ||
MixpanelManager().setUserProperty('Speaker Profile', SharedPreferencesUtil().hasSpeakerProfile); | ||
setIsLoading(false); | ||
Comment on lines
42
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The - setIsLoading(true);
- var res = await userHasSpeakerProfile();
- setSpeakerProfile(res);
- SharedPreferencesUtil().hasSpeakerProfile = res;
- debugPrint('_setupHasSpeakerProfile: ${SharedPreferencesUtil().hasSpeakerProfile}');
- MixpanelManager().setUserProperty('Speaker Profile', SharedPreferencesUtil().hasSpeakerProfile);
- setIsLoading(false);
+ try {
+ setIsLoading(true);
+ var res = await userHasSpeakerProfile();
+ setSpeakerProfile(res);
+ SharedPreferencesUtil().hasSpeakerProfile = res;
+ debugPrint('_setupHasSpeakerProfile: ${SharedPreferencesUtil().hasSpeakerProfile}');
+ MixpanelManager().setUserProperty('Speaker Profile', SharedPreferencesUtil().hasSpeakerProfile);
+ } catch (e) {
+ // Handle or log the error as needed
+ } finally {
+ setIsLoading(false);
+ } |
||
notifyListeners(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entelligence.AI
The refactoring from a function to a widget is a good step towards better modularity. However, there's a potential issue with the
SharedPreferencesUtil().hasSpeakerProfile
check. This check is performed twice: once before navigating to theSpeechProfilePage
and once after returning from it. If the value ofhasSpeakerProfile
changes while on theSpeechProfilePage
, the second check will not reflect the updated value becauseSharedPreferencesUtil()
might not have the latest data immediately after the change.To ensure that you always have the most recent value, consider using an async getter method for
hasSpeakerProfile
inSharedPreferencesUtil
and await its result.And similarly,
This way, you're sure to get the most recent value from shared preferences.