lukepighetti / salomon_bottom_bar

Yet another bottom navigation bar, but with a few key promises.
https://pub.dev/packages/salomon_bottom_bar
MIT License
258 stars 55 forks source link

Please add controller support. #30

Closed lt692 closed 2 years ago

lt692 commented 2 years ago

Add named parameter controller (like in TabBar widget) that we could prove a custom controller and controll its index.

lukepighetti commented 2 years ago

If BottomNavigationBar adds one, we will too.

lt692 commented 2 years ago

It would be really good to be able to controll your bottom bar with controller. Then we could sync TabBarView with SalomonBottomBar

Like we can do in TabBar + TabBarView

example:

 class _TabLayoutExampleState extends State<TabLayoutExample>
    with TickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();

    _tabController = TabController(length: 6, vsync: this);

    _tabController.animateTo(2);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          bottom: TabBar(
            controller: _tabController,
            tabs: [
              // Put Tabs here
            ],
          ),
          title: const Text('Flutter'),
          backgroundColor: Colors.teal,
        ),
        body: TabBarView(
          controller: _tabController,
          children: [
            // Put widgets here
          ],
        ),
      ),
    );
  }
} 

so equivalent could be

 class _TabLayoutExampleState extends State<TabLayoutExample>
    with TickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();

    _tabController = TabController(length: 6, vsync: this);

    _tabController.animateTo(2);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          bottom: SalomonBottomBar (
            controller: _tabController,
            items: [
              // Put items here
            ],
          ),
          title: const Text('Flutter'),
          backgroundColor: Colors.teal,
        ),
        body: TabBarView(
          controller: _tabController,
          children: [
            // Put widgets here
          ],
        ),
      ),
    );
  }
} 
lukepighetti commented 2 years ago

Try wrapping SalomonBottomBar in an AnimatedBuilder, subscribing to TabController, then drive the index off TabController's page value rounded