簡體   English   中英

如何創建 class Searchp 擴展 StatelessWidget 實現 SearchDelegate<an_object> 從頭開始</an_object>

[英]how to create class Searchp extends StatelessWidget implements SearchDelegate <an_object> from scratch

我是 flutter 的新手,現在我正在嘗試根據完成餐廳應用程序所需的內容來實現搜索委托欄。 Flutter 的搜索支持(The Boring Flutter Development Show,Ep. 10)的默認搜索代理不夠靈活,因為我的“購物車”是一個可滾動的 BottomSheet,當我點擊搜索圖標時,我的搜索代理帶頭我添加了我的購物車在期望滾動底部表的頁面上滾動時占據整個屏幕,但工作表無法滾動搜索委托 appBar。 自 4 天以來一直堅持這一點,我想實現孔搜索委托以訪問構建(BuildContext 上下文)以將堆棧放在那里,但我不知道如何從頭開始實現它(只知道來自Flutter 的搜索支持的 flutter 搜索(無聊的 Flutter 開發展,第 10 集) )。 如果您有其他方法可以解決我的問題,謝謝。 這些是圖像:搜索欄和工作表初始 position初始 position

搜索卡住的應用程序欄搜索委托不允許工作表滾動

我需要什么

這是我現在用於搜索代理的代碼:

    @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 實現它以擁有構建方法小部件。 這就是我想要做的,但我不知道如何實現要求使其像默認應用欄一樣工作的 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;

    }

finally 不需要從 StatelessWidget 擴展。 src/material/search.dart覆蓋 _SearchPageState class 解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM