Frontend first draft
This commit is contained in:
52
frontend/pweb/lib/widgets/search.dart
Normal file
52
frontend/pweb/lib/widgets/search.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class SearchBox extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
final String hintText;
|
||||
final ValueChanged<String> onChanged;
|
||||
final VoidCallback? onClear;
|
||||
final String? Function(String?)? validator;
|
||||
final String? labelText;
|
||||
final String? helperText;
|
||||
|
||||
const SearchBox({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.hintText,
|
||||
required this.onChanged,
|
||||
this.onClear,
|
||||
this.validator,
|
||||
this.labelText,
|
||||
this.helperText,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => TextFormField(
|
||||
controller: controller,
|
||||
onChanged: onChanged,
|
||||
validator: validator,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: controller,
|
||||
builder: (context, value, child) => value.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
controller.clear();
|
||||
if (onClear != null) {
|
||||
onClear!();
|
||||
}
|
||||
onChanged('');
|
||||
},
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
hintText: hintText,
|
||||
labelText: labelText,
|
||||
helperText: helperText,
|
||||
border: const UnderlineInputBorder(),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user