精华内容
下载资源
问答
  • 动画的SearchAppBar小部件,将与Flutter一起使用。 用法 只需将SearchAppBar小部件用作常规AppBar。 小部件中唯一需要的属性称为searcher 。 您必须在您的类(例如Bloc)中实现Searcher接口,以控制数据列表(类型...
  • Flutter - 导航栏搜索框实现

    千次阅读 2020-05-07 17:41:40
    demo 地址: https://github.com/iotjin/jh_flutter_demo 效果图: 代码 import 'package:flutter/material.dart'; import 'package:jh_flutter_demo/configs/...import 'package:jh_flutter_demo/JhTools/JhFo...

    demo 地址: https://github.com/iotjin/jh_flutter_demo

    效果图:

    在这里插入图片描述

    代码

    import 'package:flutter/material.dart';
    import 'package:jh_flutter_demo/configs/colors.dart';
    import 'package:jh_flutter_demo/JhTools/JhForm/jhLoginTextField.dart';
    
    
    class SearchTest3Page extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
    
    
        return Scaffold(
          appBar:
    
    //      cursorColor: Colors.white, //设置光标
          AppBar(
            backgroundColor: kThemeColor,
            titleSpacing:15,
            automaticallyImplyLeading: false,//隐藏返回箭头
            title:
            Container(
              decoration: new BoxDecoration(
                border: Border.all(color: Colors.grey, width: 1.0), //灰色的一层边框
                color: Colors.white,
                borderRadius: BorderRadius.all( Radius.circular(5.0)),
              ),
              alignment: Alignment.center,
              height: 38,
    //           padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
              child: JhLoginTextField(
                leftWidget: Icon(Icons.search,size: 30,),
                hintText: '请输入搜索信息',
                isShowDeleteBtn: true,
                isDense: true,
              ),
            ),
            actions: <Widget>[
    
              InkWell(
                child:
                Container(width: 50,height: 50,
                  child:  Center(child:
                  Text("搜索"),
                  ),
                ),
    
                onTap: () {
                },
              )
    
    
            ],
          ),
          body:
          RaisedButton(child: Text("返回"),
            onPressed: (){
              Navigator.pop(context);
            },
          ),
    
        );
      }
    
    
    
    }
    
    展开全文
  • import 'package:flutter/material.dart' ; import 'package:flutter/cupertino.dart' ; import 'package:ios_search_bar/ios_search_bar.dart' ; class SearchPage extends StatefulWidget { SearchPage (); ...
  • flutter 之顶部搜索栏SearchDelegate

    千次阅读 2020-07-13 11:26:34
    实现flutter搜索栏Flutter为我们提供了这个组件SearchDelegate,先看一下效果图哦。 一、定义SearchDelegate class searchBarDelegate extends SearchDelegate<String> { /*这个方法返回一个控件列表,...

    搜索栏是大部分APP都包括的组件,实际开发中需要这个搜索栏,网上阅读了一些资料后。实现flutter的搜索栏。Flutter为我们提供了这个组件SearchDelegate,先看一下效果图哦。
    在这里插入图片描述
    一、定义SearchDelegate

    class searchBarDelegate extends SearchDelegate<String> {
     /*这个方法返回一个控件列表,显示为搜索框右边的图标按钮,这里设置为一个清除按钮,并且在搜索内容为空的时候显示建议搜索内容,使用的是showSuggestions(context)方法:*/
      @override
      List<Widget> buildActions(BuildContext context) {
        return null;
      }
    /*这个方法返回一个控件,显示为搜索框左侧的按钮,一般设置为返回,这里返回一个具有动态效果的返回按钮:*/
      @override
      Widget buildLeading(BuildContext context) {
        return null;
      }
    
      @override
      Widget buildResults(BuildContext context) {
        return null;
      }
    /*这个方法返回一个控件,显示为搜索内容区域的建议内容。*/
      @override
      Widget buildSuggestions(BuildContext context) {
        return null;
      }
    
    /*这个方法返回一个主题,也就是可以自定义搜索界面的主题样式:*/
      @override
      ThemeData appBarTheme(BuildContext context) {
        // TODO: implement appBarTheme
        return super.appBarTheme(context);
      }
    }
    

    实现代码:

    
    import 'package:flutter/material.dart';
    import 'package:flutter_redux/flutter_redux.dart';
    import 'package:ws/common/dao/expense_dao.dart';
    import 'package:ws/model/expense_model.dart';
    import 'package:ws/redux/ws_state.dart';
    import 'package:ws/widget/ws_no_data.dart';
    
    class ExpenseSearch extends SearchDelegate<String>{
      String searchHint = "请输入搜索内容...";
      var monthList = [
        "一月",
        "二月",
        "三月",
        "四月",
        "五月",
        "六月",
        "七月",
        "八月",
        "九月",
        "十月",
        "十一月",
        "十二月",
      ];
    
      var typeList = [
        "差旅费报销单",
        "一般费用报销单",
        "因公临时出国(境)支出表",
        "药费报销单",
        "合同付款审批表",
        "工资系统专用报销表",
      ];
    
      List<ExpenseList> items = new List<ExpenseList>();
    
      @override
      String get searchFieldLabel => searchHint;
      
      @override
      List<Widget> buildActions(BuildContext context) {
        // TODO: implement buildActions
        return [
          IconButton(
            icon: Icon(Icons.clear),
            onPressed: () {
              query = "";
              showSuggestions(context);
            },
          ),
        ];
      }
    
      @override
      Widget buildLeading(BuildContext context) {
        return IconButton(
          icon: AnimatedIcon(
              icon: AnimatedIcons.menu_arrow, progress: transitionAnimation),
          onPressed: () {
            if (query.isEmpty) {
              close(context, null);
            } else {
              query = "";
              showSuggestions(context);
            }
          },
        );
      }
    
      @override
      Widget buildResults(BuildContext context) {
    
        return FutureBuilder(
          future: _loadData(),
          builder: (context, AsyncSnapshot snapshot) {
            return StoreBuilder<WSState>(
                builder: (context, store) {
                  return ListView.builder(
                      physics: AlwaysScrollableScrollPhysics(),
                      itemCount: items?.length == 0 ? 1 : items.length,
                      itemBuilder: (BuildContext context, int index) {
                        if (items.length > 0) {
                          ExpenseList expenseList = items[index];
                          return ListTile(
                            title:Text(expenseList.title),
                            subtitle: Text(expenseList.content),
                          );
                        } else {
                          return NoData();
                        }
                      });
    
                });
          }
        );
        ///展示搜索结果
    
      }
      @override
      Widget buildSuggestions(BuildContext context) {
        return Container(
          margin: EdgeInsets.only(left: 16.0, right: 16.0),
          child: ListView(
            primary: false,
            shrinkWrap: true,
            children: <Widget>[
              SizedBox(height: 10.0),
              Text(
                "报销月份:",
                style: TextStyle(fontSize: 20),
              ),
              SizedBox(height: 10.0),
              Wrap(
                spacing: 8.0,
                runSpacing: 8.0,
                children: monthList.map((childNode) {
                  return InkWell(
                    child: new ClipRRect(
                      borderRadius: BorderRadius.circular(3.0),
                      child: Container(
                        padding: EdgeInsets.all(3.0),
                        color:Colors.grey,
                        child: Text(
                          childNode,
                          style: TextStyle(
                            fontSize: 16,
                            color: Colors.white,
                            shadows: [
                              BoxShadow(
                                  color: Colors.grey, offset: Offset(0.2, 0.2))
                            ],
                          ),
                        ),
                      ),
                    ),
                    onTap: () {
                      _loadData();
                      Future.delayed( Duration(seconds: 2), () async {
                        searchHint = "";
                        query = childNode;
                        showResults(context);
                      });
                    },
                  );
                }).toList(),
              ),
    
              SizedBox(height: 10.0),
              Text(
                "报销类型:",
                style: TextStyle(fontSize: 18),
              ),
              SizedBox(height: 10.0),
              Wrap(
                spacing: 8.0,
                runSpacing: 8.0,
                children: typeList.map((childNode) {
                  return InkWell(
                    child: new ClipRRect(
                      borderRadius: BorderRadius.circular(3.0),
                      child: Container(
                        padding: EdgeInsets.all(3.0),
                        color:Colors.grey,
                        child: Text(
                          childNode,
                          style: TextStyle(
                            fontSize: 16,
                            color: Colors.white,
                            shadows: [
                              BoxShadow(
                                  color: Colors.grey, offset: Offset(0.2, 0.2))
                            ],
                          ),
                        ),
                      ),
                    ),
                    onTap: () {
                      _loadData();
                      Future.delayed( Duration(seconds: 2), () async {
                        searchHint = "";
                        query = childNode;
                        showResults(context);
                      });
                    },
                  );
                }).toList(),
              ),
            ],
          ),
        );
      }
    
      _loadData() async {
        //网络加载
        var data = await ExpenseDao.getInitExpense(1, 20);
        Expense expense = Expense.fromJson(data);
        items=expense.list;
      }
    }
    
    
    展开全文
  • flutter搜索框

    千次阅读 2019-06-06 15:28:19
    import 'package:flutter/material.dart'; class SearchBarDemo extends StatefulWidget { @override _SearchBarDemoState createState() => _SearchBarDemoState(); } class _SearchBarDemoState extends .....
    import 'package:flutter/material.dart';
    
    class SearchBarDemo extends StatefulWidget {
      @override
      _SearchBarDemoState createState() => _SearchBarDemoState();
    }
    
    class _SearchBarDemoState extends State<SearchBarDemo> {
      //String query="";
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            appBar:AppBar(
                title:Text('SearchBarDemo'),
                actions:<Widget>[
                  IconButton(
                      icon:Icon(Icons.search),
                      onPressed: (){
                        showSearch(context:context,delegate: searchBarDelegate());
                      }
                  ),
                ]
            )
        );
      }
    }
    const searchList = [
      "jiejie-大长腿",
      "jiejie-水蛇腰",
      "gege1-帅气欧巴",
      "gege2-小鲜肉"
    ];
    
    const recentSuggest = [
      "推荐-1",
      "推荐-2"
    ];
    class searchBarDelegate extends SearchDelegate<String>{
      //初始化加载
      @override
      List<Widget> buildActions(BuildContext context) {
        return [
          IconButton(
              icon: Icon(Icons.clear),
              onPressed: ()=>query="",
          )
        ];
      }
      @override
      Widget buildLeading(BuildContext context) {
        return IconButton(
          icon: AnimatedIcon(
              icon: AnimatedIcons.menu_arrow, progress: transitionAnimation),
          onPressed: ()=>close(context, null),
        );
      }
      @override
      Widget buildResults(BuildContext context) {
        return Container(
          width: 100.0,
          height: 100.0,
          child: Card(
            color: Colors.redAccent,
            child: Center(
              child: Text(query),
            ),
          ),
        );
      }
      @override
      Widget buildSuggestions(BuildContext context) {
        final suggestionList = query.isEmpty
            ? recentSuggest
            : searchList.where((input) => input.startsWith(query)).toList();
        return ListView.builder(
          itemCount: suggestionList.length,
          itemBuilder: (context,index) => ListTile(
            title: RichText(
                text: TextSpan(
                  text: suggestionList[index].substring(0, query.length),
                  style: TextStyle(
                      color: Colors.black, fontWeight: FontWeight.bold),
                  children:[
                    TextSpan(
                      text: suggestionList[index].substring(query.length),
                      style: TextStyle(
                        color: Colors.grey
                      )
                    )
                  ]
                )
            ),
          ),
        );
      }
    }
    

    在这里插入图片描述
    在这里插入图片描述

    展开全文
  • flutter学习--搜索框

    千次阅读 2019-05-26 15:13:03
    主入口文件 继承StatelessWidget,然后在home属性中加入SearchBarDemo,这是一个...import 'package:flutter/material.dart'; import 'search_bar_demo.dart'; void main() =>runApp(MyApp()); class MyApp ext...

    主入口文件

    继承StatelessWidget,然后在home属性中加入SearchBarDemo,这是一个自定义的Widget,主要代码都在这个文件中。

    import 'package:flutter/material.dart';
    import 'search_bar_demo.dart';
    
    void main() =>runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title:'Flutter Demo',
          theme: ThemeData.light(),
          home: SearchBarDemo()
        );
      }
    }
    

    数据文件 asset.dart

    asset.dart相当于数据文件,工作中这些数据是后台传递给我们,或者写成配置文件的,这里我们就以List的方式代替了。我们在这个文件中定义了两个List:

    • searchList : 这个相当于数据库中的数据,我们要在这里进行搜索。

    • recentSuggest : 目前的推荐数据,就是搜索时,自动为我们进行推荐。

    const searchList = [
      "jiejie-大长腿",
      "jiejie-水蛇腰",
      "gege1-帅气欧巴",
      "gege2-小鲜肉"
    ];
    
    const recentSuggest = [
      "推荐-1",
      "推荐-2"
    ];
    

    AppBar的样式制作

    import 'package:flutter/material.dart';
    import 'asset.dart';
    
    
    class SearchBarDemo extends StatefulWidget {
      _SearchBarDemoState createState() => _SearchBarDemoState();
    }
    
    class _SearchBarDemoState extends State<SearchBarDemo> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar:AppBar(
            title:Text('SearchBarDemo'),
            actions:<Widget>[
              IconButton(
                icon:Icon(Icons.search),
                onPressed: (){
                   print('开始搜索');
                }
              ),
            ]
          )
        );
      }
    }
    

    重写buildActions方法:

    buildActions方法时搜索条右侧的按钮执行方法,我们在这里方法里放入一个clear图标。 当点击图片时,清空搜索的内容。

     @override
      List<Widget> buildActions(BuildContext context){
        return [
          IconButton(
            icon:Icon(Icons.clear),
            onPressed: ()=>query = "",)
          ];
      }
    

    buildLeading 方法重写

    搜索栏左侧的图标和功能的编写

     @override
      Widget buildLeading(BuildContext context) {
        return IconButton(
            icon: AnimatedIcon(
                icon: AnimatedIcons.menu_arrow, progress: transitionAnimation),
            onPressed: () => close(context, null));
      }
    

    buildResults方法重写

    buildResults方法,是搜到到内容后的展现,

    @override
      Widget buildResults(BuildContext context) {
        return Container(
          width: 100.0,
          height: 100.0,
          child: Card(
            color: Colors.redAccent,
            child: Center(
              child: Text(query),
            ),
          ),
        );
      }
    

    buildSuggestions方法重写

    这个方法主要的作用就是设置推荐,就是我们输入一个字,然后自动为我们推送相关的搜索结果

    @override
      Widget buildSuggestions(BuildContext context) {
        final suggestionList = query.isEmpty
            ? recentSuggest
            : searchList.where((input) => input.startsWith(query)).toList();
        return ListView.builder(
            itemCount: suggestionList.length,
            itemBuilder: (context, index) => ListTile(
                  title: RichText(
                      text: TextSpan(
                          text: suggestionList[index].substring(0, query.length),
                          style: TextStyle(
                              color: Colors.black, fontWeight: FontWeight.bold),
                          children: [
                        TextSpan(
                            text: suggestionList[index].substring(query.length),
                            style: TextStyle(color: Colors.grey))
                      ])),
                ));
      }
    }
    

    在这里插入图片描述
    在这里插入图片描述

    展开全文
  • Flutter搜索框SearchBar

    千次阅读 2020-06-25 15:24:01
    Flutter搜索框
  • There are many flutter widgets to implement search feature just like in Android, yet there is a simpler way to implement this using flutter SearchDelegate class which gives you almost all that you wan...
  • Flutter —— 搜索框

    2021-11-16 16:48:39
    在聊天界面添加一个搜索框。那么就在ListView里面添加一个cell,那么就需要itemCount里面加1。 itemCount: _datas.length + 1, 创建一个chat package,然后将chat_page拖进来并且重新创建一个search_cell文件。 ...
  • flutter 搜索框

    2021-05-20 15:48:27
    import 'package:flutter/material.dart'; class SearchBarWidget extends StatefulWidget { final ValueChanged<String> onchangeValue; final VoidCallback onEditingComplete; const SearchBarWidget...
  • 本来想直接偷懒从flutter pub上找个能用的使用起来,但是看了下发现都与目前ui效果相差很大,于是乎决定自己实现一个。整体的话比较简单,本来也是为了练手而做的。 为了方便处理statusbar的高度适配,于是乎直接...
  • Flutter实现实时搜索框

    千次阅读 2020-08-25 17:42:58
    Flutter实现实时搜索框效果图 最近学习了点flutter,练习下,实现一个普通的实时搜索功能,有些细节还未完善,大体写完了如下: 版本号: IDE: idea 2019 效果图 项目地址
  • Flutter自定义搜索框,解决字体不剧中的问题 效果 高度为40的时候显示: 高度为60显示的 高度为30的显示 代码如下, 创建一个SearchBar.dart文件,吧下面的代码复制进去就可以了 import 'package:flutter/...
  • 颤振搜索面板 一个小部件,允许用户从字符串列表中搜索并进行选择(类似于DropDownButtom)。 正在安装 dependencies : flutter_search_panel : ^1.0.1 进口 import 'package:flutter_search_panel/flutter_search_...
  • 各位同学大家好,有段时间没有给大家更新文章了,趁着有时间就写了一个模仿搜索引擎做的一个flutter版本的模糊搜索框案例,分享给大家,如果有错误和纰漏地方希望大家及时指出,那么废话不多说,我们正式开始 ...
  • flutter_demo,实现的一些效果UI相关ListView相关(上下拉刷新、分组上下拉刷新、分组吸顶)GridView相关弹框封装(中间、底部、toast、自定义弹框)仿微信右上角弹框时间、日期、单列、多列、底部选择器拍照、本地图片...
  • import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; const Color _textColor = Colors.black; const TextStyle _textStyle = TextStyle(fontSize: 15.0,color: _textColor); const...
  • Flutter组件封装 搜索框

    千次阅读 2021-11-10 14:52:55
    相信小白刚刚开始使用Flutter的时候都会感觉自带的组件都好丑,还要自己设置各种样式。接下来就直接上正题:贴代码!! 将下面的代码复制到你工程下组件目录。...//搜索框 class SearchIow extends StatelessWidge...
  • Flutter中SearchDelegate修改搜索框hintText内容

    千次阅读 热门讨论 2019-10-29 17:43:45
    调用Flutter自带的SearchDelegate,发现搜索框里面自带了水印文字“Search”,但是老板肯定要求要改啊!!! 文章目录查看search.dart源码解决方法 查看search.dart源码 Flutter自带的有SearchDelegate委托,从源码...
  • //设置状态透明 if (Platform.isAndroid) { SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle( statusBarColor: Colors.transparent, //设置为透明 最后,面试前该准备哪些资源复习?...
  • 可扩展的浮动搜索栏Flutter实现,也称为持久搜索,类似于Google在自己的应用中广泛使用的实现。 单击查看完整的示例。 正在安装 将其添加到您的pubspec.yaml文件中: dependencies : material_floating_search_...
  • Flutter状态透明

    2020-11-11 22:35:50
    if(Platform.isAndroid) { SystemChrome.setSystemUIOverlayStyle( SystemUiOverlayStyle(statusBarColor: Colors.transparent)); }
  • import 'package:flutter/material.dart'; import 'package:keduo/base/baseSize.dart'; import 'package:keduo/utils/icon_utils.dart'; class SearchBarWidget extends StatefulWidget { final ValueChanged<...
  • Flutter常用插件

    千次阅读 2019-08-16 13:24:21
    1.json to dart (将json在线转成... 2.插件库地址:https://pub.dev/flutter 3.常用插件如下,具体使用可以复制名称到插件库中查询: audio_recorder: any #录音、播放 flutter_sound: ^1.1.5#录音 dropdown_m...
  • flutter搜索

    2019-06-08 00:39:00
    下面这个文件是一个独立的搜索界面,进入搜索的方式:调用 showSearch(context: context, delegate: ...import 'package:flutter/material.dart';class SearchBarDelegate extends SearchDelegate<String> ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 5,032
精华内容 2,012
关键字:

flutter搜索框