Why is the navigation stack hidden in Flutter?

Viewed 328

Why is the navigation stack private in Flutter? I am curious as to why the Flutter authors decided to make it hidden as a design choice.

For those interested, the navigation history is referenced as '_history' within NavigtorState.

class NavigatorState extends State<Navigator> with TickerProviderStateMixin, RestorationMixin {
    late GlobalKey<OverlayState> _overlayKey;
    List<_RouteEntry> _history = <_RouteEntry>[];
    final _HistoryProperty _serializableHistory = _HistoryProperty();

Side notes (looking for a response to above question):

Right now I am making a navigation observer that keeps track of the navigation stack using a queue. When push, pop, or remove are called, I update my queue accordingly. I solely use this to keep track of the depth of the navigation stack. This stack depth, combined with WillPopScope allows for me to fine tune when I want a user to be able to pop or not. Without getting into too much detail, I want my selected tab to not be popable to the root route (route: '/'). By knowing the depth is of length 1, I can use WillPopScope to stop a user from popping.

This circles me back to the original question; is keeping track of the stack a bad design choice for Flutter?

I have found limit resources as to WHY the flutter devs chose to make it private.

My one thought is to prevent users from manually editing the history. So why not allow for a public function such as getHistoryLength()?

Many thanks,

-Flutter Newbie

0 Answers
Related