fix: align UI focus and sheet behavior
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../focus/dpad_navigator.dart';
|
||||
import '../focus/input_mode_tracker.dart';
|
||||
import '../focus/key_event_utils.dart';
|
||||
import '../focus/focusable_wrapper.dart';
|
||||
import '../i18n/strings.g.dart';
|
||||
import 'clickable_cursor.dart';
|
||||
|
||||
class CollapsibleText extends StatefulWidget {
|
||||
@@ -54,33 +53,6 @@ class _CollapsibleTextState extends State<CollapsibleText> {
|
||||
});
|
||||
}
|
||||
|
||||
KeyEventResult _handleKeyEvent(FocusNode _, KeyEvent event) {
|
||||
final selectResult = handleOneShotSelect(event, _toggleExpanded);
|
||||
if (selectResult != KeyEventResult.ignored) return selectResult;
|
||||
|
||||
if (!event.isActionable) return KeyEventResult.ignored;
|
||||
|
||||
final key = event.logicalKey;
|
||||
if (key.isUpKey && widget.onNavigateUp != null) {
|
||||
widget.onNavigateUp!();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (key.isDownKey && widget.onNavigateDown != null) {
|
||||
widget.onNavigateDown!();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (key.isLeftKey && widget.onNavigateLeft != null) {
|
||||
widget.onNavigateLeft!();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (key.isRightKey && widget.onNavigateRight != null) {
|
||||
widget.onNavigateRight!();
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final style = widget.style ?? DefaultTextStyle.of(context).style;
|
||||
@@ -123,31 +95,22 @@ class _CollapsibleTextState extends State<CollapsibleText> {
|
||||
),
|
||||
);
|
||||
|
||||
final focusNode = widget.focusNode;
|
||||
if (focusNode != null) {
|
||||
result = Focus(
|
||||
focusNode: focusNode,
|
||||
skipTraversal: widget.skipTraversal,
|
||||
onKeyEvent: _handleKeyEvent,
|
||||
child: ListenableBuilder(
|
||||
listenable: focusNode,
|
||||
builder: (context, child) {
|
||||
final showFocus = focusNode.hasFocus && InputModeTracker.isKeyboardMode(context);
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 150),
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: showFocus
|
||||
? Theme.of(context).colorScheme.primary.withValues(alpha: 0.12)
|
||||
: Colors.transparent,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: result,
|
||||
),
|
||||
);
|
||||
result = FocusableWrapper(
|
||||
focusNode: widget.focusNode,
|
||||
onSelect: _toggleExpanded,
|
||||
onNavigateUp: widget.onNavigateUp,
|
||||
onNavigateDown: widget.onNavigateDown,
|
||||
onNavigateLeft: widget.onNavigateLeft,
|
||||
onNavigateRight: widget.onNavigateRight,
|
||||
semanticLabel: _expanded ? t.accessibility.collapseText : t.accessibility.expandText,
|
||||
descendantsAreFocusable: false,
|
||||
disableScale: true,
|
||||
useBackgroundFocus: true,
|
||||
borderRadius: 8,
|
||||
child: result,
|
||||
);
|
||||
if (widget.skipTraversal) {
|
||||
result = ExcludeFocusTraversal(child: result);
|
||||
}
|
||||
|
||||
return ClickableCursor(
|
||||
|
||||
Reference in New Issue
Block a user