-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Make the state class _GNavState public #77
Comments
Exact issue i was looking for. |
@YDA93 Hi there, i would suggest you to change Gnav.selectedIndex instead of modifying the actual navbar state directly. There's an example showing how changing tabpage trigger Gnav to change selectedIndex https://github.com/sooxt98/google_nav_bar/blob/master/example/lib/main_advance.dart |
I control my tabs through router which allows me to change tabs from any widget I want. Normally most drawers and nav bars in flutter uses a key for this purpose. Please consider it as feature request. Thank you! @sooxt98 |
@YDA93 sorry i can't, i won't promoting people to wring bad codes, which is a bad design pattern which use state globally |
@sooxt98 This package is beautifully designed but is limited when it comes to this. convex_bottom_bar has flutter favorite badge and it use global state. It doesn't make sense. |
@sooxt98 That's their source code https://github.com/hacktons/convex_bottom_bar/blob/master/lib/src/bar.dart |
@YDA93 please read this https://softwareengineering.stackexchange.com/questions/148108/why-is-global-state-so-evil |
@sooxt98 If you don't like to introduce new packages, use this instead https://medium.com/flutter-community/stop-using-state-management-libraries-48a81ed7979d |
@sooxt98 When I were saying "Global state" I was wrong. I haven't made any single Global variable, state in the PR. I made the class to be Public which is very different. Meaning I cannot access it globally unless I attach global key to it: Users of this package can decide if they wish to use global key to control the state, Flutter already gave us null safety to check the state existence. Plus I made it possible to access the state through context using https://api.flutter.dev/flutter/widgets/BuildContext/findAncestorStateOfType.html https://stackoverflow.com/questions/46057353/controlling-state-from-outside-of-a-statefulwidget |
Even if you’re not using GlobalKey, but others will, GlobalKey is an
anti-pattern design which allow anything to direct modify Gnav state from
anywhere
…On Thu, 20 Oct 2022 at 3:55 AM, Yousef Almutairi ***@***.***> wrote:
@sooxt98 <https://github.com/sooxt98>
After I have read all your references and understand from what your coming
from.
When I were saying "Global state" I was wrong.
I haven't made any single Global variable, state in the PR.
I made the class to be Public which is very different.
Meaning I cannot access it globally unless I attach global key to it:
static final appBarKey = GlobalKey<GNavState>();
Users of this package can decide if they wish to use global key to control
the state, Flutter already gave us null safety to check the state existence.
Plus I made it possible to access the state through context using
findAncestorStateOfType., which again has null safety and isn't
considered as Global state, it searches for the first existence of such
state otherwise returns null.
https://api.flutter.dev/flutter/widgets/BuildContext/findAncestorStateOfType.html
<http://url>
—
Reply to this email directly, view it on GitHub
<#77 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADGCEC3YKNXVD25BN3BXR4LWEBG3RANCNFSM5TG3ISJQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@sooxt98 It's not in the package code so we have no any anti-pattern design so far. Since we only made the class public what stops this? |
@sooxt98 Using |
I would like to use the state in a Global Key and access it from different widgets like the Navigation Drawer so that when the user clicks on a menu item on the navigation drawer, the bottom navigation drawer can auto animate to the selected menu.
The text was updated successfully, but these errors were encountered: