feat(flutter): 剧场页搜索与吸顶筛选精致化
This commit is contained in:
1 parent
f9d4f982f0
commit
5283ab2549
3 files changed
+204
-33
No files matched your search
@@ -6,10 +6,11 @@ import '../../../core/theme/app_colors.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
const double _searchHeight = 40;
|
||||
const double _searchRadius = 18;
|
||||
const double _searchRadius = 20;
|
||||
const Duration _focusTransition = Duration(milliseconds: 160);
|
||||
|
||||
/// 剧场顶部整行搜索框。
|
||||
class DiscoverSearchField extends StatelessWidget {
|
||||
/// 剧场顶部整行搜索框:白底细边,聚焦时主题色描边与更深的阴影。
|
||||
class DiscoverSearchField extends StatefulWidget {
|
||||
const DiscoverSearchField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
@@ -25,32 +26,84 @@ class DiscoverSearchField extends StatelessWidget {
|
||||
final bool loading;
|
||||
final double horizontalPadding;
|
||||
|
||||
@override
|
||||
State<DiscoverSearchField> createState() => _DiscoverSearchFieldState();
|
||||
}
|
||||
|
||||
class _DiscoverSearchFieldState extends State<DiscoverSearchField> {
|
||||
bool _focused = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.focusNode.addListener(_onFocusChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant DiscoverSearchField oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.focusNode != widget.focusNode) {
|
||||
oldWidget.focusNode.removeListener(_onFocusChanged);
|
||||
widget.focusNode.addListener(_onFocusChanged);
|
||||
_focused = widget.focusNode.hasFocus;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.focusNode.removeListener(_onFocusChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onFocusChanged() {
|
||||
final focused = widget.focusNode.hasFocus;
|
||||
if (focused != _focused) setState(() => _focused = focused);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
child: SizedBox(
|
||||
padding: EdgeInsets.symmetric(horizontal: widget.horizontalPadding),
|
||||
child: AnimatedContainer(
|
||||
key: const Key('discover-search-shell'),
|
||||
duration: _focusTransition,
|
||||
curve: Curves.easeOut,
|
||||
height: _searchHeight,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.card,
|
||||
borderRadius: BorderRadius.circular(_searchRadius),
|
||||
border: Border.all(
|
||||
color: _focused ? AppColors.blue : AppColors.border,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _focused
|
||||
? AppColors.blue.withValues(alpha: 0.18)
|
||||
: Colors.black.withValues(alpha: 0.04),
|
||||
blurRadius: _focused ? 10 : 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TextField(
|
||||
key: const Key('discover-search'),
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
onChanged: onChanged,
|
||||
onTapOutside: (_) => focusNode.unfocus(),
|
||||
controller: widget.controller,
|
||||
focusNode: widget.focusNode,
|
||||
onChanged: widget.onChanged,
|
||||
onTapOutside: (_) => widget.focusNode.unfocus(),
|
||||
textInputAction: TextInputAction.search,
|
||||
style: const TextStyle(color: AppColors.onSurface, fontSize: 14),
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
filled: true,
|
||||
fillColor: AppColors.card,
|
||||
filled: false,
|
||||
hintText: AppLocalizations.of(context)!.searchDiscover,
|
||||
hintStyle: const TextStyle(color: AppColors.subtle, fontSize: 12),
|
||||
hintStyle: const TextStyle(color: AppColors.subtle, fontSize: 13.5),
|
||||
prefixIcon: const Icon(
|
||||
Icons.search_rounded,
|
||||
color: AppColors.subtle,
|
||||
size: 17,
|
||||
),
|
||||
suffixIcon: loading
|
||||
suffixIcon: widget.loading
|
||||
? const SizedBox.square(
|
||||
dimension: 18,
|
||||
child: Center(
|
||||
@@ -63,14 +116,9 @@ class DiscoverSearchField extends StatelessWidget {
|
||||
minHeight: 0,
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(_searchRadius),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(_searchRadius),
|
||||
borderSide: const BorderSide(color: AppColors.blue, width: 1),
|
||||
),
|
||||
border: InputBorder.none,
|
||||
enabledBorder: InputBorder.none,
|
||||
focusedBorder: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user