The Search Bar to Replicate

我想在搜索栏中添加图标.到目前为止,我的代码如下:

new TextField(
     decoration: new InputDecoration(
     icon: new Icon(Icons.search)
     labelText: "Describe Your Issue...",
     enabledBorder: const OutlineInputBorder(
     borderRadius: BorderRadius.all(Radius.circular(20.0)),
     borderSide: const BorderSide(
       color: Colors.grey,
      ),
    ),
    focusedBorder: OutlineInputBorder(
      borderRadius: BorderRadius.all(Radius.circular(10.0)),
      borderSide: BorderSide(color: Colors.blue),
    ),
   ),
  ),

这是上面代码的结果(这不是我想要的):

Output of my code (this is not what i want)

推荐答案

Edited Answer

将答案更新为我的原始答案实际上并不包括问题的原始上下文.

您可以使用TextField中的prefixIconTextFormField中的某个小部件作为TextField中的前导.

实例

    TextField(
//    ...,other fields
      decoration: InputDecoration(
        prefixIcon: prefixIcon??Icon(Icons.done),
      ),
    ),

注:不要混淆prefixIconprefix,因为这是两个

另外,如果你想实现像浮动应用程序栏这样的功能,那么你可以参考我最初的答案.

Original answer

您可以使用我的Flutter 包在应用程序中实现Floating AppBar.

您需要在您的wine 吧中添加以下套餐.

rounded_floating_app_bar: ^0.1.0

从命令行运行$ flutter packages get.

现在,在您的DART代码中,您可以使用:

import 'package:rounded_floating_app_bar/rounded_floating_app_bar.dart';
...
NestedScrollView(
  headerSliverBuilder: (context, isInnerBoxScroll) {
    return [
      RoundedFloatingAppBar(
        floating: true,
        snap: true,
        title: TextField(
          decoration: InputDecoration(
            prefixIcon: Icon(Icons.search),
            border: InputBorder.none,
          ),
        ),
      ),
    ];
  },
  body: Container(),
),

输出:

Image Output

Flutter相关问答推荐

下拉图标未居中

从底部开始固定,然后使其可拖曳Flutter

我如何才能动态地将小部件排成一排进行排列呢?

如何知道当前屏幕是否处于抖动状态?

Flutter OpenID Connect无效参数:redirect_uri using Keycloak

升级到Ffltter 3.16后,应用程序栏、背景 colored颜色 、按钮大小和间距都会发生变化

如何在抖动中将PNG图像转换为WebP

在Ffltter中,我已经使用了Ffltter_BLOC Cupit和Pusher,但当获得新数据时,UI没有更新

从Firestore流式传输单个文档还是整个集合更好?

未处理的异常:第1行第5列出现错误:无效的媒体类型:应为/&;.从API获取数据时在Flutter中

Riverpod Provider.family 和 HookConsumerWidget 不刷新 UI

打开键盘时屏幕组件会被压扁

没有固定宽度的小部件可以约束文本小部件吗?

网页浏览器不支持鼠标滚动的行项目

Flutter url_launcher 插件抛出java.lang.IllegalArgumentException:接收器未注册:io.flutter.plugins.urllauncher.WebViewActivity

为什么我们使用 RiverpodGenerator

应用程序和应用程序内的 webview 之间的单点登录

如何在 flutter 中创建渐变按钮

Firestore:缓存和读取数据

Textfield 和 MasonryGrid 给出错误(垂直视口的高度没有限制)