Files
notas/lib/widgets/search_app_bar.dart
T
Marcos f4bb5104e2 Refactor theme colors and styles across the application
- Introduced AppColors class to centralize color definitions for better maintainability and consistency.
- Updated various screens (Settings, Vault Access, Note Card, etc.) to use AppColors for styling instead of hardcoded colors.
- Enhanced UI elements with improved color contrast and accessibility.
- Replaced gradient backgrounds with defined color schemes for a cohesive look.
- Refactored button styles and text colors to align with the new theme structure.
2026-05-23 09:38:26 +02:00

176 lines
6.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:notas/theme/app_colors.dart';
class SearchAppBar extends StatefulWidget {
const SearchAppBar({
super.key,
this.onMenuPressed,
this.onLeadingPressed,
this.leadingIcon = Icons.menu,
this.leadingTooltip = 'Menú',
this.leadingWidget,
this.trailingWidget,
this.onSearchChanged,
this.searchHint = 'Buscar notas...',
this.showSearch = true,
this.titleText,
});
final VoidCallback? onMenuPressed;
final VoidCallback? onLeadingPressed;
final IconData leadingIcon;
final String leadingTooltip;
final Widget? leadingWidget;
final Widget? trailingWidget;
final ValueChanged<String>? onSearchChanged;
final String searchHint;
final bool showSearch;
final String? titleText;
@override
State<SearchAppBar> createState() => _SearchAppBarState();
}
class _SearchAppBarState extends State<SearchAppBar> {
late TextEditingController _searchController;
void _onSearchChanged() {
setState(() {});
}
@override
void initState() {
super.initState();
_searchController = TextEditingController()..addListener(_onSearchChanged);
}
@override
void dispose() {
_searchController.removeListener(_onSearchChanged);
_searchController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: AppColors.transparent,
border: Border(bottom: BorderSide(color: AppColors.border, width: 0.5)),
),
padding: const EdgeInsets.only(left: 8, right: 20, top: 7, bottom: 7),
child: Row(
children: [
IconButton(
onPressed: widget.onLeadingPressed ?? widget.onMenuPressed,
icon: Icon(
widget.leadingIcon,
color: AppColors.textSecondary,
size: 20,
),
tooltip: widget.leadingTooltip,
splashRadius: 18,
constraints: const BoxConstraints(minWidth: 40, minHeight: 40),
),
if (widget.leadingWidget != null) ...[
const SizedBox(width: 8),
Center(child: widget.leadingWidget!),
],
const SizedBox(width: 8),
Expanded(
child: widget.showSearch
? Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: TextField(
controller: _searchController,
onChanged: widget.onSearchChanged,
style: const TextStyle(
color: AppColors.textPrimary,
fontSize: 13,
),
cursorColor: AppColors.textSecondary,
decoration: InputDecoration(
hintText: widget.searchHint,
hintStyle: TextStyle(
color: AppColors.textSecondary.withValues(
alpha: 0.5,
),
),
suffixIcon: _searchController.text.isNotEmpty
? IconButton(
icon: const Icon(
Icons.clear,
color: AppColors.textSecondary,
size: 18,
),
onPressed: () {
_searchController.clear();
widget.onSearchChanged?.call('');
},
constraints: const BoxConstraints(
minWidth: 36,
minHeight: 36,
),
)
: const Padding(
padding: EdgeInsets.only(right: 8),
child: Icon(
Icons.search,
color: AppColors.textSecondary,
size: 18,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: AppColors.borderStrong,
width: 0.5,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: AppColors.borderStrong,
width: 0.5,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: AppColors.searchFocusBorder,
width: 0.5,
),
),
filled: true,
fillColor: AppColors.fill,
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
isDense: true,
),
),
),
)
: Align(
alignment: Alignment.centerLeft,
child: Text(
widget.titleText ?? '',
style: const TextStyle(
color: AppColors.textPrimary,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
),
),
if (widget.trailingWidget != null) ...[
const SizedBox(width: 16),
Center(child: widget.trailingWidget!),
],
],
),
);
}
}