Skip to content

Commit f810297

Browse files
authored
Fix GestureDetector being absorbed in focused FItems. (#700)
* Fix `GestureDetector` being absorbed in focused `FItem`s. * Prepare Forui for review * Fix failing test --------- Co-authored-by: Pante <[email protected]>
1 parent 08a668e commit f810297

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed

forui/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ We've improved the styles' generated documentation. They should be much easier t
4646
* **Breaking** Add `FFormFieldProperties(onReset: ...)`.
4747

4848

49+
### `FItem`
50+
51+
* Fix `GestureDetector` being absorbed in focused `FItem`s.
52+
53+
4954
### `FPopover` & `FPopoverMenu`
5055
* Add `FPopoverMotion`.
5156

forui/lib/src/widgets/item/item.dart

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -288,22 +288,19 @@ class FItem extends StatelessWidget with FItemMixin {
288288
onSecondaryLongPress: enabled ? (onSecondaryLongPress ?? () {}) : null,
289289
shortcuts: shortcuts,
290290
actions: actions,
291-
builder: (context, states, _) => Stack(
292-
children: [
293-
DecoratedBox(
294-
decoration: style.decoration.maybeResolve(states) ?? const BoxDecoration(),
295-
child: _builder(context, style, top, bottom, states, data.dividerColor, data.dividerWidth, divider),
291+
builder: (context, states, _) => DecoratedBox(
292+
position: DecorationPosition.foreground,
293+
decoration: switch (style.focusedOutlineStyle) {
294+
final outline? when states.contains(WidgetState.focused) => BoxDecoration(
295+
border: Border.all(color: outline.color, width: outline.width),
296+
borderRadius: outline.borderRadius,
296297
),
297-
if (style.focusedOutlineStyle case final outline? when states.contains(WidgetState.focused))
298-
Positioned.fill(
299-
child: DecoratedBox(
300-
decoration: BoxDecoration(
301-
border: Border.all(color: outline.color, width: outline.width),
302-
borderRadius: outline.borderRadius,
303-
),
304-
),
305-
),
306-
],
298+
_ => const BoxDecoration(),
299+
},
300+
child: DecoratedBox(
301+
decoration: style.decoration.maybeResolve(states) ?? const BoxDecoration(),
302+
child: _builder(context, style, top, bottom, states, data.dividerColor, data.dividerWidth, divider),
303+
),
307304
),
308305
),
309306
),

forui/test/src/widgets/item/item_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter/services.dart';
23

34
import 'package:flutter_test/flutter_test.dart';
45

@@ -144,4 +145,29 @@ void main() {
144145

145146
expect(count, 1);
146147
});
148+
149+
testWidgets('focus does not cause inner gesture detector to be ignored', (tester) async {
150+
var outer = 0;
151+
var inner = 0;
152+
final focusNode = autoDispose(FocusNode());
153+
await tester.pumpWidget(
154+
TestScaffold(
155+
child: FItem(
156+
focusNode: focusNode,
157+
title: const Text('Bluetooth'),
158+
onPress: () => outer++,
159+
suffix: FButton.icon(onPress: () => inner++, child: const Icon(FIcons.pencil)),
160+
),
161+
),
162+
);
163+
164+
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
165+
await tester.pumpAndSettle(const Duration(seconds: 1));
166+
167+
await tester.tap(find.byIcon(FIcons.pencil));
168+
await tester.pumpAndSettle(const Duration(seconds: 1));
169+
170+
expect(inner, 1);
171+
expect(outer, 0);
172+
});
147173
}

0 commit comments

Comments
 (0)