如何创建类 Searchp 扩展 StatelessWidget 从头开始实现 SearchDelegate <an_object>



我是flutter的新手,现在我正试图根据完成餐厅应用程序所需的内容来实现搜索代理栏。Flutter搜索支持(The Boring Flutter Development Show,Ep.10(的默认搜索代表不够灵活,因为我的"购物车"是一个可滚动的BottomSheet,当我点击搜索图标时,我的搜索代表带头,我在页面上添加了我的购物车,希望滚动时BottomSheet会占据整个屏幕,但表单无法在搜索上滚动委派appBar。自从4天以来,我一直被困在这个问题上,我想实现孔搜索委托来访问构建(BuildContext上下文(,以便在那里放置堆栈,但我不知道如何从头开始实现它(只知道flutter的搜索支持(the Boring flutter Development Show,Ep.10(中的flutter搜索(。如果你有其他方法来解决我的问题,谢谢。这些是图像:搜索条和纸张在其初始位置的初始位置

搜索阻塞的appbar搜索代理不允许在上滚动工作表

我需要什么纸

这是我现在有权搜索延迟门的代码:

@override
List<Widget> buildActions(BuildContext context) {
// TODO: implement buildActions
return [
IconButton(
icon: Icon(Icons.clear),
onPressed:(){
query = "";
}
)
];
}
@override
Widget buildLeading(BuildContext context) {
// TODO: implement buildLeading
return IconButton(icon: AnimatedIcon(
icon:AnimatedIcons.menu_arrow,
progress: transitionAnimation,
),
onPressed:(){
close(context,null);
}
);
}
@override
Widget buildResults(BuildContext context) {
// TODO: implement buildResults
final suggestionList =query.isEmpty?food_recent:data.where((p)=> p.toString().contains(query)).toList();
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return  Stack(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// SizedBox(height: 8),
AspectRatio(
aspectRatio: 0.8,
child: Opacity(
opacity: 1,
child:ListView.builder(
//padding: EdgeInsets.only(right: 32, top: 128),
//controller: scrollController,
itemCount: suggestionList?.length ?? 0, //20,
itemBuilder: (context, index) {
//Event event = events[index % 3];
Produit event = suggestionList[index];
return MyEventItemProduct(
event: event,
percentageCompleted:0.15,
);
},
),
),
)
//Tabs(),
//SizedBox(height: 8),
//SlidingCardsView(),
],
),
ScrollableExhibitionSheet(),//use this or ScrollableExhibitionSheet
],
);
});
}
@override
Widget buildSuggestions(BuildContext context) {
// TODO: implement buildSuggestions
//new Text(suggestionList[index]["colis"]["libelle_coli"]),
final suggestionList =query.isEmpty?food_recent:data.where((p)=> p.toString().contains(query)).toList();
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return  Stack(
overflow: Overflow.clip,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// SizedBox(height: 8),
AspectRatio(
aspectRatio: 0.8,
child: Opacity(
opacity: 1,
child:ListView.builder(
//padding: EdgeInsets.only(right: 32, top: 128),
//controller: scrollController,
itemCount: suggestionList?.length ?? 0, //20,
itemBuilder: (context, index) {
//Event event = events[index % 3];
Produit event = suggestionList[index];
return MyEventItemProduct(
event: event,
percentageCompleted:0.15,
);
},
),
),
)
//Tabs(),
//SizedBox(height: 8),
//SlidingCardsView(),
],
),
ScrollableExhibitionSheet(),//use this or ScrollableExhibitionSheet
],
);
});
}

由于我不知道如何解决我的问题,我决定从srcatch实现它,以获得构建方法小部件。这就是我正在尝试做的,但我不知道如何实现要求它像默认的appbar一样工作的其他10个方法。

class Searchp extends StatelessWidget implements SearchDelegate <Produit>{
@override
String query;
@override
ThemeData appBarTheme(BuildContext context) {
// TODO: implement appBarTheme
return null;
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return null;
}
@override
List<Widget> buildActions(BuildContext context) {
// TODO: implement buildActions

return null;
}
@override
Widget buildLeading(BuildContext context) {
// TODO: implement buildLeading
return null;
}
@override
Widget buildResults(BuildContext context) {
// TODO: implement buildResults
return null;
}
@override
Widget buildSuggestions(BuildContext context) {
// TODO: implement buildSuggestions
return null;
}
@override
void close(BuildContext context, Produit result) {
// TODO: implement close
}
@override
// TODO: implement keyboardType
TextInputType get keyboardType => null;
@override
// TODO: implement searchFieldLabel
String get searchFieldLabel => null;
@override
void showResults(BuildContext context) {
// TODO: implement showResults
}
@override
void showSuggestions(BuildContext context) {
// TODO: implement showSuggestions
}
@override
// TODO: implement textInputAction
TextInputAction get textInputAction => null;
@override
// TODO: implement transitionAnimation
Animation<double> get transitionAnimation => null;
}

最终不需要从StatelessWidget进行扩展。重写src/material/search.dart中的_SearchPageState类解决了我的问题。

相关内容

最新更新