【发布时间】:2019-12-14 07:34:50
【问题描述】:
问题是我正在向我使用自定义 appBar 的应用程序添加一个应用程序抽屉,它是一个不同的类,我想从我没有脚手架的 CustomAppBar 类调用一个应用程序抽屉(它去了添加脚手架时到白屏)。
我已经尝试了多种方法,我可以想到用我的 IconButton 的 onPressed 属性来调用它。
这是我的主要课程
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
child: ListView(
children: <Widget>[
FirstHalf(),
SizedBox(
height: 45.0,
),
for (var foodItem in fooditemList.foodItems)
ItemContainer(foodItem: foodItem)
],
),
),
),
);
}
}
这是调用 CustomAppBar 的地方
class FirstHalf extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(35, 25, 0, 0),
child: Column(
children: <Widget>[
CustomAppBar(), //CustomAppBar
SizedBox(
height: 30.0,
),
title(),
SizedBox(
height: 30.0,
),
searchBar(),
SizedBox(
height: 30.0,
),
categories(),
],
),
);
}
这个类的代码并没有到此结束,但是我觉得分享这么多就足够了,而不是分享整个代码
这是我要调用应用抽屉的 CustomAppBar 类
class CustomAppBar extends StatelessWidget {
final CartListBLoc bloc = BlocProvider.getBloc<CartListBLoc>();
CustomAppBar();
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(bottom: 15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(Icons.menu),
onPressed: () {},//want to call app drawer here
),
StreamBuilder(
stream: bloc.listStream,
builder: (context, snapshot) {
List<FoodItem> foodItems = snapshot.data;
int length = foodItems != null ? foodItems.length : 0;
return buildGestureDetector(length, context, foodItems);
},
initialData: <FoodItem>[],
),
],
),
);
}
}
【问题讨论】:
-
您的
Home类未使用CustomAppBar。CustomAppBar是否应该成为Home类的一部分? -
真的很抱歉我犯了一个错误,我不得不再展示一个使用 customappbar 作为 appbar 的课程,我一回到家就会编辑问题。
-
编辑已完成,我是初学者,如果有一点帮助,将不胜感激,谢谢