57 lines
1.8 KiB
Dart
57 lines
1.8 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
|
||
|
|
class SearchBar extends StatelessWidget {
|
||
|
|
final TextEditingController controller;
|
||
|
|
final bool extensionMode;
|
||
|
|
final VoidCallback onClear;
|
||
|
|
|
||
|
|
const SearchBar({
|
||
|
|
super.key,
|
||
|
|
required this.controller,
|
||
|
|
required this.extensionMode,
|
||
|
|
required this.onClear,
|
||
|
|
});
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return TextField(
|
||
|
|
controller: controller,
|
||
|
|
decoration: InputDecoration(
|
||
|
|
hintText: extensionMode
|
||
|
|
? 'Search tracked tabs...'
|
||
|
|
: 'Search tabs, bookmarks, and history...',
|
||
|
|
prefixIcon: const Icon(Icons.search),
|
||
|
|
suffixIcon: controller.text.isNotEmpty
|
||
|
|
? IconButton(
|
||
|
|
icon: const Icon(Icons.clear),
|
||
|
|
onPressed: onClear,
|
||
|
|
)
|
||
|
|
: null,
|
||
|
|
border: OutlineInputBorder(
|
||
|
|
borderRadius: BorderRadius.circular(12),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// This widget provides the search input field for filtering tabs, bookmarks, and history.
|
||
|
|
//
|
||
|
|
// It is a stateless widget that receives a TextEditingController from the parent to manage the text input.
|
||
|
|
//
|
||
|
|
// The hint text changes based on whether extension mode is active or not.
|
||
|
|
//
|
||
|
|
// In extension mode it says Search tracked tabs and in normal mode it says Search tabs, bookmarks, and history.
|
||
|
|
//
|
||
|
|
// A search icon appears on the left side of the input field.
|
||
|
|
//
|
||
|
|
// When the user types text, a clear button appears on the right side to quickly empty the search.
|
||
|
|
//
|
||
|
|
// Clicking the clear button triggers the onClear callback which clears the controller text.
|
||
|
|
//
|
||
|
|
// The text field has rounded corners for a modern appearance.
|
||
|
|
//
|
||
|
|
// As the user types, the parent widget filters the displayed items in real-time.
|
||
|
|
//
|
||
|
|
// This provides a fast and intuitive way to find specific tabs or bookmarks in large lists.
|