Open Manty-K opened 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'), ); } }
any update?
same issue
Same here, any solution?
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.