Comments (12)
Exact issue i was looking for.
from google_nav_bar.
@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
from google_nav_bar.
I control my tabs through router which allows me to change tabs from any widget I want.
The problem with this package is I can't change the nav bar state from another deep widgets unless I use some notifiers which is requesting more work for a simple thing.
Normally most drawers and nav bars in flutter uses a key for this purpose.
Please consider it as feature request.
Thank you! @sooxt98
from google_nav_bar.
@YDA93 sorry i can't, i won't promoting people to wring bad codes, which is a bad design pattern which use state globally
from google_nav_bar.
@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.
from google_nav_bar.
@sooxt98 That's their source code https://github.com/hacktons/convex_bottom_bar/blob/master/lib/src/bar.dart
from google_nav_bar.
@YDA93 please read this https://softwareengineering.stackexchange.com/questions/148108/why-is-global-state-so-evil
If you want this feature, you may fork it yourself, or use some hack like getx, get_it, bloc, flutter_redux, mobx
from google_nav_bar.
@sooxt98 If you don't like to introduce new packages, use this instead https://medium.com/flutter-community/stop-using-state-management-libraries-48a81ed7979d
from google_nav_bar.
@sooxt98
After I have read all your references and understand from where you're 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
https://api.flutter.dev/flutter/widgets/GlobalKey-class.html
https://stackoverflow.com/questions/46057353/controlling-state-from-outside-of-a-statefulwidget
from google_nav_bar.
from google_nav_bar.
@sooxt98
At the end of the day it's the user option to evaluate the case and decides to create global key or not.
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?
from google_nav_bar.
@sooxt98
We only made it possible to control the state from two methods:
Using GlobalKey
or through findAncestorStateOfType
from google_nav_bar.
Related Issues (20)
- Set the height of the navigation bar
- how to remove elevation from the nav bar HOT 3
- how to make resize screen ? HOT 3
- Feature request : Add color/gradient for unselected tab background HOT 1
- Debug console shows this message "ensureControlAlpha: for ITYPE_NAVIGATION_BAR" when GNav does not show? HOT 1
- Change icon type; use Widget instead of IconData HOT 1
- How to stop clicking and changing status HOT 1
- How to me Floating action Button center docked with this Bottom AppBar HOT 2
- Could you add elevation for the selected tab? HOT 1
- The bar overflows on small screens and throws error HOT 3
- how to navigate between pages HOT 3
- Nothing Find For Implement for own coustom icon
- GNav
- How can I set the fixed length of the activated GButton? HOT 2
- How can i disable tabs? HOT 2
- Create Vertical nav bar using google_nav_bar
- Icon and text mis-allign HOT 1
- Use leading instead icon, but icon is required
- setState() called after dispose()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google_nav_bar.