Flutter 菜单绘制一直返回两个应用程序栏。如何只返回一个?
我现在有一个折叠的抽屉菜单,可以很容易地在页面之间切换。一切似乎都正常,除了当我进入指定页面时,它返回两个应用程序条 正如你们所看到的(看图片), 有两个应用程序栏正在显示我想完全删除蓝色的一个,并在白色的应用程序栏上的图标切换控制器(查看提供的代码) 我怎样才能做到这一点?我知道它与return scaffold和appbar有关,但我不知道如何在不破坏应用程序的情况下删除它 谢谢 斯特凡 代码:Flutter 菜单绘制一直返回两个应用程序栏。如何只返回一个?,flutter,Flutter,我现在有一个折叠的抽屉菜单,可以很容易地在页面之间切换。一切似乎都正常,除了当我进入指定页面时,它返回两个应用程序条 正如你们所看到的(看图片), 有两个应用程序栏正在显示我想完全删除蓝色的一个,并在白色的应用程序栏上的图标切换控制器(查看提供的代码) 我怎样才能做到这一点?我知道它与return scaffold和appbar有关,但我不知道如何在不破坏应用程序的情况下删除它 谢谢 斯特凡 代码: import 'package:mykitchen/Main Controllers/My R
import 'package:mykitchen/Main Controllers/My Recipes/My Recipes.dart';
import 'hidden_drawer_menu.dart';
import 'package:mykitchen/Main Controllers/Settings+Acount/Settings.dart';
import 'package:mykitchen/Main Controllers/GroceryList/GroceryList.dart';
import 'package:mykitchen/Main Controllers/Pantry/Pantry.dart';
import 'package:mykitchen/Main Controllers/Meal Plan/MealPlan.dart';
import 'package:mykitchen/Main Controllers/Recipets/Recipets.dart';
class ExampleCustomMenu extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SimpleHiddenDrawer(
menu: Menu(),
screenSelectedBuilder: (position, controller) {
Widget screenCurrent;
switch (position) {
case 0:
screenCurrent = Settings();
break;
case 1:
screenCurrent = MyRecipes();
break;
case 2:
screenCurrent = GroceryList();
break;
case 3:
screenCurrent = Pantry();
break;
case 4:
screenCurrent = MealPlan();
break;
case 5:
screenCurrent = Recipets();
break;
}
return Scaffold(
appBar: AppBar(
title: Text("Look at this "),
leading: IconButton(
icon: Icon(Icons.menu),
onPressed: () {
controller.toggle();
}),
),
backgroundColor: Color(0xFFFF1744),
body: screenCurrent,
);
},
);
}
}
class Menu extends StatefulWidget {
@override
_MenuState createState() => _MenuState();
}
class _MenuState extends State<Menu> with TickerProviderStateMixin {
AnimationController _animationController;
bool initConfigState = false;
@override
void initState() {
_animationController =
AnimationController(vsync: this, duration: Duration(milliseconds: 100));
super.initState();
}
@override
Widget build(BuildContext context) {
confListenerState(context);
return Container(
width: double.maxFinite,
height: double.maxFinite,
color: Colors.red,
child: Stack(
children: <Widget>[
Container(
width: double.maxFinite,
height: double.maxFinite,
),
FadeTransition(
opacity: _animationController,
child: Padding(
padding: const EdgeInsets.all(50.0),
child: Align(
alignment: Alignment.centerLeft,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
width: 200.0,
height: 150,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(0);
},
child: Text(
"Settings",
style: TextStyle(color: Colors.black),
),
),
),
SizedBox(
width: 200.0,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(1);
},
child: Text(
"My Recipes",
style: TextStyle(color: Colors.black),
)),
),
SizedBox(
width: 200.0,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(2);
},
child: Text(
"Grocery List",
style: TextStyle(color: Colors.black),
)),
),
SizedBox(
width: 200.0,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(3);
},
child: Text(
"Pantry",
style: TextStyle(color: Colors.black),
)),
),
SizedBox(
width: 200.0,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(4);
},
child: Text(
"Meal Plan",
style: TextStyle(color: Colors.black),
)),
),
SizedBox(
width: 200.0,
child: RaisedButton(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
onPressed: () {
SimpleHiddenDrawerProvider.of(context)
.setSelectedMenuPosition(5);
},
child: Text(
"Recipets",
style: TextStyle(color: Colors.black),
)),
),
],
),
),
),
),
],
),
);
}
void confListenerState(BuildContext context) {
if (!initConfigState) {
initConfigState = true;
SimpleHiddenDrawerProvider.of(context)
.getMenuStateListener()
.listen((state) {
if (state == MenuState.open) {
_animationController.forward();
}
if (state == MenuState.closing) {
_animationController.reverse();
}
});
}
}
}```
import'程序包:mykitchen/Main Controller/My Recipes/My Recipes.dart';
导入“隐藏的抽屉菜单.省道”;
导入“package:mykitchen/Main Controllers/Settings+Acount/Settings.dart”;
导入“包:mykitchen/Main Controllers/GroceryList/GroceryList.dart”;
进口“包装:mykitchen/主控制器/餐具室/餐具室.dart”;
导入“包:我的厨房/主控制器/用餐计划/MealPlan.dart”;
导入“包:mykitchen/主控制器/Recipets/Recipets.dart”;
类示例CustomMenu扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回SimpleHiddenDrawer(
菜单:菜单(),
screenSelectedBuilder:(位置、控制器){
小部件屏幕电流;
开关(位置){
案例0:
screenCurrent=设置();
打破
案例1:
screenCurrent=MyRecipes();
打破
案例2:
screenCurrent=GroceryList();
打破
案例3:
屏幕电流=餐具室();
打破
案例4:
screenCurrent=MealPlan();
打破
案例5:
屏幕电流=Recipets();
打破
}
返回脚手架(
appBar:appBar(
标题:文本(“看看这个”),
领先:IconButton(
图标:图标(图标菜单),
已按下:(){
controller.toggle();
}),
),
背景颜色:颜色(0xFFFF1744),
正文:屏幕电流,
);
},
);
}
}
类菜单扩展了StatefulWidget{
@凌驾
_MenuState createState()=>\u MenuState();
}
类_MenuState使用TickerProviderStateMixin扩展状态{
AnimationController _AnimationController;
bool initConfigState=false;
@凌驾
void initState(){
_动画控制器=
AnimationController(vsync:this,duration:duration(毫秒:100));
super.initState();
}
@凌驾
小部件构建(构建上下文){
冲突状态(上下文);
返回容器(
宽度:double.maxFinite,
高度:double.maxFinite,
颜色:颜色,红色,
子:堆栈(
儿童:[
容器(
宽度:double.maxFinite,
高度:double.maxFinite,
),
衰减转换(
不透明度:_animationController,
孩子:填充(
填充:常数边集全部(50.0),
子对象:对齐(
对齐:alignment.centerLeft,
子:列(
mainAxisSize:mainAxisSize.min,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
大小盒子(
宽度:200.0,
身高:150,
孩子:升起按钮(
颜色:颜色,白色,
形状:圆形矩形边框(
边界半径:
边界半径所有(半径圆形(10.0)),
已按下:(){
SimpleHidderWaverProvider.of(上下文)
.setSelectedMenuPosition(0);
},
子:文本(
“设置”,
样式:TextStyle(颜色:Colors.black),
),
),
),
大小盒子(
宽度:200.0,
孩子:升起按钮(
颜色:颜色,白色,
形状:圆形矩形边框(
边界半径:
边界半径所有(半径圆形(10.0)),
已按下:(){
SimpleHidderWaverProvider.of(上下文)
.设置选定的位置(1);
},
子:文本(
“我的食谱”,
样式:TextStyle(颜色:Colors.black),
)),
),
大小盒子(
宽度:200.0,
孩子:升起按钮(
颜色:颜色,白色,
形状:圆形矩形边框(
边界半径:
边界半径所有(半径圆形(10.0)),
已按下:(){
SimpleHidderWaverProvider.of(上下文)
.设置选定的位置(2);
},
子:文本(
“杂货清单”,
样式:TextStyle(颜色:Colors.black),
)),
),
大小盒子(
宽度:200.0,
孩子:升起按钮(
颜色:颜色,白色,
形状:圆形矩形边框(
边界半径:
边界半径所有(半径圆形(10.0)),
按下按钮:
Scaffold(
// AppBar used to be here. Now it's not.
backgroundColor: Color(0xFFFF1744),
body: screenCurrent,
);