Remove Cupertino UI branches
Keep the public Cupertino-compatible parameters while retaining only the Material implementations and tests. The app is Material-only, so deleting unreachable Cupertino branches reduces dead code without changing the active path.
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../adaptive/host.dart';
|
||||
import 'cupertino_web_search_field.dart';
|
||||
|
||||
/// The app's one search field per platform.
|
||||
/// The app's one search field.
|
||||
///
|
||||
/// Cupertino uses the stock [CupertinoSearchTextField]. Material uses a
|
||||
/// [TextField] shaped like it: a stadium with a leading search icon, a clear
|
||||
/// button once there is text, no underline and no elevation. On a page it is
|
||||
/// filled with the host's raised surface; [inBar] drops the fill (and the
|
||||
/// Cupertino grey) because a bar's glass pill is already its background.
|
||||
/// A [TextField] shaped like the stock iOS field: a stadium with a leading
|
||||
/// search icon, a clear button once there is text, no underline and no
|
||||
/// elevation. On a page it is filled with the host's raised surface; [inBar]
|
||||
/// drops the fill because a bar's glass pill is already its background.
|
||||
class AppSearchField extends StatelessWidget {
|
||||
const AppSearchField({
|
||||
super.key,
|
||||
@@ -58,32 +52,6 @@ class AppSearchField extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (cupertino ?? usesCupertinoHost(context)) {
|
||||
if (kIsWeb) {
|
||||
return CupertinoWebSearchField(
|
||||
controller: controller,
|
||||
placeholder: placeholder,
|
||||
fieldKey: fieldKey,
|
||||
focusNode: focusNode,
|
||||
autofocus: autofocus,
|
||||
inBar: inBar,
|
||||
onChanged: onChanged,
|
||||
onSubmitted: onSubmitted,
|
||||
onCleared: _clear,
|
||||
);
|
||||
}
|
||||
return CupertinoSearchTextField(
|
||||
key: fieldKey,
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
autofocus: autofocus,
|
||||
placeholder: placeholder,
|
||||
backgroundColor: inBar ? const Color(0x00000000) : null,
|
||||
onChanged: onChanged,
|
||||
onSubmitted: onSubmitted,
|
||||
onSuffixTap: _clear,
|
||||
);
|
||||
}
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
const radius = BorderRadius.all(Radius.circular(28));
|
||||
const stadium = OutlineInputBorder(
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
/// Keeps the web input's semantics stable when its clear action appears.
|
||||
/// Nesting the clear button in CupertinoSearchTextField changes its merged
|
||||
/// editable node into a disabled child node on web. Native sibling controls
|
||||
/// retain both an enabled input and an independently accessible clear action.
|
||||
class CupertinoWebSearchField extends StatefulWidget {
|
||||
const CupertinoWebSearchField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.placeholder,
|
||||
required this.onCleared,
|
||||
this.fieldKey,
|
||||
this.focusNode,
|
||||
this.autofocus = false,
|
||||
this.inBar = false,
|
||||
this.onChanged,
|
||||
this.onSubmitted,
|
||||
});
|
||||
|
||||
final TextEditingController controller;
|
||||
final String placeholder;
|
||||
final VoidCallback onCleared;
|
||||
final Key? fieldKey;
|
||||
final FocusNode? focusNode;
|
||||
final bool autofocus;
|
||||
final bool inBar;
|
||||
final ValueChanged<String>? onChanged;
|
||||
final ValueChanged<String>? onSubmitted;
|
||||
|
||||
@override
|
||||
State<CupertinoWebSearchField> createState() =>
|
||||
_CupertinoWebSearchFieldState();
|
||||
}
|
||||
|
||||
class _CupertinoWebSearchFieldState extends State<CupertinoWebSearchField> {
|
||||
FocusNode? _localFocus;
|
||||
FocusNode get _focus => widget.focusNode ?? (_localFocus ??= FocusNode());
|
||||
|
||||
void _clear() {
|
||||
final focus = _focus;
|
||||
// The browser can keep the old editing session focused on the semantic
|
||||
// clear button after it is removed. This explicit action ends that edit,
|
||||
// then hands focus back after layout; ordinary query changes never refocus.
|
||||
focus.unfocus();
|
||||
widget.onCleared();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted || !identical(focus, _focus)) return;
|
||||
final current = FocusManager.instance.primaryFocus;
|
||||
if (current == null || current == focus || current is FocusScopeNode) {
|
||||
focus.requestFocus();
|
||||
}
|
||||
});
|
||||
WidgetsBinding.instance.ensureVisualUpdate();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_localFocus?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: widget.inBar
|
||||
? const Color(0x00000000)
|
||||
: CupertinoColors.tertiarySystemFill.resolveFrom(context),
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
minHeight: kMinInteractiveDimensionCupertino,
|
||||
),
|
||||
child: TextFieldTapRegion(
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: CupertinoSearchTextField(
|
||||
key: widget.fieldKey,
|
||||
controller: widget.controller,
|
||||
focusNode: _focus,
|
||||
autofocus: widget.autofocus,
|
||||
placeholder: widget.placeholder,
|
||||
backgroundColor: const Color(0x00000000),
|
||||
suffixMode: OverlayVisibilityMode.never,
|
||||
onChanged: widget.onChanged,
|
||||
onSubmitted: widget.onSubmitted,
|
||||
),
|
||||
),
|
||||
ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: widget.controller,
|
||||
builder: (context, value, _) => value.text.isEmpty
|
||||
? const SizedBox.shrink()
|
||||
: CupertinoButton(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
onPressed: _clear,
|
||||
child: Icon(
|
||||
CupertinoIcons.clear_thick_circled,
|
||||
color: CupertinoColors.secondaryLabel.resolveFrom(
|
||||
context,
|
||||
),
|
||||
size: 20,
|
||||
semanticLabel: CupertinoLocalizations.of(
|
||||
context,
|
||||
).clearButtonLabel,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user