Flutter 颤振:如何仅使用主屏幕中的按钮导航到第二个导航屏幕(底部导航)?

Flutter 颤振:如何仅使用主屏幕中的按钮导航到第二个导航屏幕(底部导航)?,flutter,bottomnavigationview,flutter-routes,Flutter,Bottomnavigationview,Flutter Routes,在我的项目中,我对底部导航栏项使用了索引。它控制了我所有的三个主屏幕(主页、票务和个人资料)。实际上,我只是使用底部的导航按钮在屏幕之间导航。作为替代方法,我想定制一个位于主屏幕上的按钮。因此,当点击时,它将导航到票务(第二个屏幕) 我尝试使用Navigator.pushNamed(上下文,屏幕名),但它将堆叠在所有屏幕上方,不显示底部导航栏。请阅读以下内容: import 'package:flutter/material.dart'; void main() => runAp

在我的项目中,我对底部导航栏项使用了索引。它控制了我所有的三个主屏幕(主页、票务和个人资料)。实际上,我只是使用底部的导航按钮在屏幕之间导航。作为替代方法,我想定制一个位于主屏幕上的按钮。因此,当点击时,它将导航到票务(第二个屏幕)

我尝试使用
Navigator.pushNamed(上下文,屏幕名),但它将堆叠在所有屏幕上方,不显示底部导航栏。

请阅读以下内容:
import 'package:flutter/material.dart';  
  
void main() => runApp(MyApp());  
  
/// This Widget is the main application widget.  
class MyApp extends StatelessWidget {  
  @override  
  Widget build(BuildContext context) {  
    return MaterialApp(  
      home: MyNavigationBar (),  
    );  
  }  
}  
  
class MyNavigationBar extends StatefulWidget {  
  MyNavigationBar ({Key key}) : super(key: key);  
  
  @override  
  _MyNavigationBarState createState() => _MyNavigationBarState();  
}  
  
class _MyNavigationBarState extends State<MyNavigationBar > {  
  int _selectedIndex = 0;  
  static const List<Widget> _widgetOptions = <Widget>[  
    Text('Home Page', style: TextStyle(fontSize: 35, fontWeight: FontWeight.bold)),  
    Text('Search Page', style: TextStyle(fontSize: 35, fontWeight: FontWeight.bold)),  
    Text('Profile Page', style: TextStyle(fontSize: 35, fontWeight: FontWeight.bold)),  
  ];  
  
  void _onItemTapped(int index) {  
    setState(() {  
      _selectedIndex = index;  
    });  
  }  
  
  @override  
  Widget build(BuildContext context) {  
    return Scaffold(  
      appBar: AppBar(  
        title: const Text('Flutter BottomNavigationBar Example'),  
          backgroundColor: Colors.green  
      ),  
      body: Center(  
        child: _widgetOptions.elementAt(_selectedIndex),  
      ),  
      bottomNavigationBar: BottomNavigationBar(  
        items: const <BottomNavigationBarItem>[  
          BottomNavigationBarItem(  
            icon: Icon(Icons.home),  
            title: Text('Home'),  
            backgroundColor: Colors.green  
          ),  
          BottomNavigationBarItem(  
            icon: Icon(Icons.search),  
            title: Text('Search'),  
            backgroundColor: Colors.yellow  
          ),  
          BottomNavigationBarItem(  
            icon: Icon(Icons.person),  
            title: Text('Profile'),  
            backgroundColor: Colors.blue,  
          ),  
        ],  
        type: BottomNavigationBarType.shifting,  
        currentIndex: _selectedIndex,  
        selectedItemColor: Colors.black,  
        iconSize: 40,  
        onTap: _onItemTapped,  
        elevation: 5  
      ),  
    );  
  }  
}  
void _onItemTapped() {  
        setState(() {  
          _selectedIndex = 1;  
        });  
      }