BilalShahid13 / PersistentBottomNavBar

A highly customizable persistent bottom navigation bar for Flutter
BSD 3-Clause "New" or "Revised" License
528 stars 397 forks source link

Back button shifts to first tab #229

Open Manty-K opened 3 years ago

Manty-K commented 3 years ago

I am using PersistentTabView.custom(). Let's say we are on the second tab. When I press the back button on android, the first tab appears. I want to close the app from the selected tab itself.

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  late PersistentTabController _controller;
  @override
  void initState() {
    super.initState();
    _controller = PersistentTabController(initialIndex: 1);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PersistentTabView.custom(
        context,
        confineInSafeArea: true,
        controller: _controller,
        screens: [
          TestPage('First'),
          TestPage('Second'),
          TestPage('Third'),
        ],
        customWidget: _customBar(),
        itemCount: 3,
      ),
    );
  }

  _customBar() {
    return Container(
      color: Colors.grey[100],
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          IconButton(
              onPressed: () {
                _controller.jumpToTab(0);
              },
              icon: Icon(Icons.add)),
          IconButton(
              onPressed: () {
                _controller.jumpToTab(1);
              },
              icon: Icon(Icons.home)),
          IconButton(
              onPressed: () {
                _controller.jumpToTab(2);
              },
              icon: Icon(Icons.person)),
        ],
      ),
    );
  }
}

class TestPage extends StatelessWidget {
  final String text;

  TestPage(this.text);
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text('Test page : $text'),
    );
  }
}
naimurhasan commented 3 years ago

any update?

rulila52 commented 3 years ago

same issue

ZahraVe commented 1 year ago

Same here, any solution?