Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在底部导航上方制作颤振抽屉_Flutter_Navigation Drawer_Flutter Layout_Flutter Animation_Slidingdrawer - Fatal编程技术网

Flutter 如何在底部导航上方制作颤振抽屉

Flutter 如何在底部导航上方制作颤振抽屉,flutter,navigation-drawer,flutter-layout,flutter-animation,slidingdrawer,Flutter,Navigation Drawer,Flutter Layout,Flutter Animation,Slidingdrawer,我在颤振项目中有一个简单的抽屉,我希望当用户滑动/打开时,抽屉始终位于底部导航栏上方。我玩弄我的代码,但还找不到任何解决方案 导入“包装:颤振/材料.省道”; 导入“包:testing2/pages/ChannelsPage.dart”; 导入“包:testing2/pages/HomePage.dart”; 导入“package:testing2/pages/ExplorePage.dart”; 导入“package:testing2/fragments/first_fragment.dar

我在颤振项目中有一个简单的抽屉,我希望当用户滑动/打开时,抽屉始终位于底部导航栏上方。我玩弄我的代码,但还找不到任何解决方案

导入“包装:颤振/材料.省道”;
导入“包:testing2/pages/ChannelsPage.dart”;
导入“包:testing2/pages/HomePage.dart”;
导入“package:testing2/pages/ExplorePage.dart”;
导入“package:testing2/fragments/first_fragment.dart”;
导入“package:testing2/fragments/second_fragment.dart”;
导入“package:testing2/fragments/third_fragment.dart”;
导入“包:testing2/Shared/drawer.dart”;
类MyHomePage扩展StatefulWidget{
@凌驾
_MyBottomNavigationBarState createState()=>\u MyBottomNavigationBarState();
}
类_MyBottomNavigationBarState扩展状态{
最终GlobalKey _scaffoldKey=新的GlobalKey();
int _currentSelected=0;
GlobalKey _drawerKey=GlobalKey();
最终列表_子项=[
首页(),
setingspage(),
ContactPage(),
主页()
];
void onTappedBar(整数索引){
指数=3
?_drawerKey.currentState.openDrawer()
:setState(){
_currentSelected=索引;
});
}
@凌驾
小部件构建(构建上下文){
归还新脚手架(
钥匙:_-drawerKey,
抽屉:新抽屉(
子:ListView(
儿童:[
新型抽屉阅读器(
儿童:新文本(“Jonathan”),
装饰:新盒子装饰(颜色:Colors.orange),),
新ListTile(
前导:常量图标(图标、通知),
标题:新文本(“通知”),
onTap:(){
Navigator.pop(上下文);
push(context,newmaterialpage(builder:(context)=>newfirstfragment());
},
),
新ListTile(
前导:常量图标(Icons.list),
标题:新文本(“首选项”),
onTap:(){
Navigator.pop(上下文);
push(context,newmaterialpage(builder:(context)=>newsecondfragment());
},
),
新ListTile(
前导:常量图标(Icons.help),
标题:新文本(“帮助”),
onTap:(){
Navigator.pop(上下文);
push(context,newmaterialpage(builder:(context)=>newthirdfragment());
},
),
新ListTile(
前导:常量图标(图标、轮廓标志),
标题:新文本(“注销”),
onTap:(){
Navigator.pop(上下文);
push(context,newmaterialpage(builder:(context)=>newfirstfragment());
},
),
],
)
),
正文:_children[_currentSelected],
底部导航栏:底部导航栏(
背景颜色:颜色。蓝灰色[900],
类型:BottomNavigationBarType.fixed,
onTap:onTappedBar,
currentIndex:\u currentSelected,
showUnselectedLabels:true,
unselectedItemColor:Colors.white,
选择EditemColor:Color.fromRGBO(10、135、255、1),
项目:[
BottomNavigationBarItem(图标:新图标(Icons.home),标题:新文本(“home”),
BottomNavigationBarItem(图标:新图标(Icons.search),标题:新文本('Explore'),
BottomNavigationBarItem(图标:新图标(Icons.device_hub),标题:新文本(“频道”),
BottomNavigationBarItem(图标:新图标(Icons.dehaze),标题:新文本(“更多”),
],
),     
);
}
}
类页面扩展了无状态小部件{
常量页({Key}):超级(Key:Key);
@凌驾
小部件构建(构建上下文){
返回容器();
}

}
您可以通过以下方式执行此操作

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

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

class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 0;
  static const TextStyle optionStyle =
      TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
  static const List<Widget> _widgetOptions = <Widget>[
    Text(
      'Index 0: Home',
      style: optionStyle,
    ),
    Text(
      'Index 1: Business',
      style: optionStyle,
    ),
    Text(
      'Index 2: School',
      style: optionStyle,
    ),
  ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Scaffold(
        body: Center(
          child: _widgetOptions.elementAt(_selectedIndex),
        ),
        appBar: AppBar(
          title: Text("data"),
        ),
        drawer: Drawer(
          child: Center(
            child: RaisedButton(
              child: Text("Press"),
              onPressed: () {
                Navigator.push(
                    context, MaterialPageRoute(builder: (context) => Hello1()));
              },
            ),
          ),
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            title: Text('Home'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.business),
            title: Text('Business'),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.school),
            title: Text('School'),
          ),
        ],
        currentIndex: _selectedIndex,
        selectedItemColor: Colors.amber[800],
        onTap: _onItemTapped,
      ),
    );
  }
}

class Hello1 extends StatelessWidget {
  const Hello1({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: Center(
          child: Text("data"),
        ),
      ),
    );
  }
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key}):超级(Key:Key);
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
int _selectedIndex=0;
静态常量文本样式选项样式=
TextStyle(fontSize:30,fontWeight:fontWeight.bold);
静态常量列表_widgetOptions=[
正文(
'索引0:主',
样式:可选样式,
),
正文(
"指数1:业务",,
样式:可选样式,
),
正文(
"索引2:学校",,
样式:可选样式,
),
];
void\u未映射(整数索引){
设置状态(){
_selectedIndex=索引;
});
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:脚手架(
正文:中(
子项:_widgetOptions.elementAt(_selectedIndex),
),
appBar:appBar(
标题:文本(“数据”),
),
抽屉(
儿童:中心(
孩子:升起按钮(
子:文本(“按”),
已按下:(){
导航器。推(
context,materialpage(builder:(context)=>Hello1());
},
),
),
),
),
底部导航栏:底部导航栏(
项目:常数[
底部导航气压计(
图标:图标(Icons.home),
标题:文本(“主页”),
),
底部导航气压计(
图标:图标(Icons.business),
标题:文本(“业务”),
),
底部导航气压计(
图标:图标(Icons.school),
标题:文本(“学校”),
),
],
currentIndex:_selectedIndex,
selectedItemColor:Colors.amber[800],
onTap:\u未映射,
),
);
}
}
类Hello1扩展了无状态小部件{
常量Hello1({Key}):超级(Key:Key);
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:容器(
子女:行政长官
widget.globalScaffoldKey.currentState.openDrawer();