| 12345678910111213141516171819202122232425262728293031323334 |
- import 'package:flutter/material.dart';
- class SearchBarWidget extends StatelessWidget {
- final String hint;
- final ValueChanged<String> onChanged;
- final VoidCallback? onClear;
- final TextEditingController? controller;
- const SearchBarWidget({
- super.key,
- this.hint = 'Cerca...',
- required this.onChanged,
- this.onClear,
- this.controller,
- });
- @override
- Widget build(BuildContext context) {
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
- child: TextField(
- controller: controller,
- decoration: InputDecoration(
- hintText: hint,
- prefixIcon: const Icon(Icons.search),
- suffixIcon: controller != null && controller!.text.isNotEmpty
- ? IconButton(icon: const Icon(Icons.clear), onPressed: onClear)
- : null,
- ),
- onChanged: onChanged,
- ),
- );
- }
- }
|