1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import 'package:flutter/material.dart';
- class VSearchInput extends StatelessWidget {
- /// 占位提示
- final String? placeholder;
- /// 搜索回调
- final ValueChanged<String>? onSearch;
- const VSearchInput({
- super.key,
- this.placeholder,
- this.onSearch,
- });
- @override
- Widget build(BuildContext context) {
- return LayoutBuilder(
- builder: (_, c) {
- final controller = TextEditingController();
- final radius = c.maxHeight / 2;
- final border = OutlineInputBorder(
- borderRadius: BorderRadius.all(Radius.circular(radius)),
- borderSide: BorderSide.none,
- );
- return TextField(
- controller: controller,
- decoration: InputDecoration(
- enabledBorder: border,
- focusedBorder: border,
- fillColor: Colors.grey.shade400,
- filled: true,
- hintText: placeholder,
- hintStyle: const TextStyle(
- fontSize: 20,
- color: Colors.black54,
- ),
- contentPadding: EdgeInsets.symmetric(
- horizontal: radius * 1.2,
- vertical: (c.maxHeight - 24) / 2,
- ),
- // isDense: true,
- isCollapsed: false,
- prefixIcon: IconButton(
- padding: const EdgeInsets.symmetric(horizontal: 18),
- icon: const Icon(Icons.search, size: 36),
- onPressed: () {
- onSearch?.call(controller.text);
- },
- ),
- ),
- onSubmitted: (value) {
- onSearch?.call(value);
- },
- );
- },
- );
- }
- }
|