123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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(
- style: const TextStyle(fontSize: 20),
- controller: controller,
- decoration: InputDecoration(
- enabledBorder: border,
- focusedBorder: border,
- fillColor: const Color.fromRGBO(238, 238, 238, 1),
- 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);
- },
- );
- },
- );
- }
- }
|