flutter 的TextField复杂使用和设置左右图标

效果:
在这里插入图片描述

 Expanded(
                child: Container(
              height: 32,
              margin: EdgeInsets.only(right: 10),
              decoration: BoxDecoration(
                  color: Colours.bg_gray,
                  borderRadius: BorderRadius.circular(5)),
              child: TextField(
                //输入框一行
                maxLines: 1,
                controller: _controller,
                autofocus: false,
                decoration: InputDecoration(
                  //输入里面输入文字内边距设置
                    contentPadding: const EdgeInsets.only(
                        top: 8.0, left: -19.0, right: -15.0, bottom: 8.0),
                    hintText: widget.hintText,
                    //不需要输入框下划线
                    border: InputBorder.none,
                    //左边图标设置
                    icon: Padding(
                      padding: EdgeInsets.all(8),
                      child: LoadAssetImage(
                        "order/order_search",
                        color: Colours.text_gray_c,
                      ),
                    ),
                    //右边图标设置
                    suffixIcon: GestureDetector(
                      onTap: () {
                        //addPostFrameCallback是 StatefulWidge 渲染结束的回调,只会被调用一次
                        SchedulerBinding.instance.addPostFrameCallback((_) {
                          _controller.text = "";
                        });
                      },
                      child: Padding(
                        padding: EdgeInsets.all(8),
                        child: LoadAssetImage(
                          'order/order_delete',
                          color: Colours.text_gray_c,
                        ),
                      ),
                    )),
              ),
            ))

你可能感兴趣的:(flutter开发)