Skip to content

Commit f425be5

Browse files
committed
Add .gitattributes and menu example enhancements
Add a .gitattributes file to normalize text files to LF and mark common binary types. Update examples/menu_example/lib/main.dart to add disabled menu items (including a disabled checkbox), adjust menu item indexing for the dynamic label, renumber comments, and include a new _openBugReproMenu method that reproduces issue #4 (checked/disabled item behavior on Windows). Also add a compact button in the UI to open the bug reproduction menu. These changes improve repo consistency and extend the example app for testing menu state/behavior.
1 parent 78ab039 commit f425be5

2 files changed

Lines changed: 110 additions & 9 deletions

File tree

‎.gitattributes‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Auto-detect text files and normalize to LF in the repository
2+
* text=auto
3+
4+
# Explicitly declare source file types as text (LF normalized)
5+
*.cc text
6+
*.cmake text
7+
*.cpp text
8+
*.c text
9+
*.h text
10+
*.dart text
11+
*.swift text
12+
*.yaml text
13+
*.yml text
14+
*.json text
15+
*.md text
16+
*.sh text
17+
*.bat text
18+
*.ps1 text
19+
*.cmake text
20+
21+
# Binary files should remain untouched
22+
*.png binary
23+
*.jpg binary
24+
*.jpeg binary
25+
*.gif binary
26+
*.ico binary
27+
*.icns binary
28+
*.ttf binary
29+
*.woff binary
30+
*.woff2 binary

‎examples/menu_example/lib/main.dart‎

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class _MenuExamplePageState extends State<MenuExamplePage> {
5353
late final MenuItem _radio1;
5454
late final MenuItem _radio2;
5555
late final MenuItem _radio3;
56+
late final MenuItem _disabledItem;
57+
late final MenuItem _disabledCheckbox;
5658
late final MenuItem _submenuItem;
5759
late final Menu _submenu;
5860

@@ -223,18 +225,36 @@ class _MenuExamplePageState extends State<MenuExamplePage> {
223225
_contextMenu.addItem(_radio3);
224226
_menuItems.add(_radio3);
225227

226-
// 5. Separator
228+
// 5. Disabled menu items
229+
_disabledItem = MenuItem('Disabled Item');
230+
_disabledItem.enabled = false;
231+
_disabledItem.on<MenuItemClickedEvent>((event) {
232+
_addToHistory('Disabled item clicked (should not fire!)');
233+
});
234+
_contextMenu.addItem(_disabledItem);
235+
_menuItems.add(_disabledItem);
236+
237+
_disabledCheckbox = MenuItem('Disabled Checkbox', MenuItemType.checkbox);
238+
_disabledCheckbox.state = MenuItemState.checked;
239+
_disabledCheckbox.enabled = false;
240+
_disabledCheckbox.on<MenuItemClickedEvent>((event) {
241+
_addToHistory('Disabled checkbox clicked (should not fire!)');
242+
});
243+
_contextMenu.addItem(_disabledCheckbox);
244+
_menuItems.add(_disabledCheckbox);
245+
246+
// 7. Separator
227247
_contextMenu.addSeparator();
228248

229-
// 6. Menu item with dynamic label
249+
// 8. Menu item with dynamic label
230250
final dynamicLabelItem = MenuItem(_currentLabel);
231251
dynamicLabelItem.on<MenuItemClickedEvent>((event) {
232252
_addToHistory('Dynamic label item clicked (ID: ${event.menuItemId})');
233253
});
234254
_contextMenu.addItem(dynamicLabelItem);
235255
_menuItems.add(dynamicLabelItem);
236256

237-
// 7. Menu item with tooltip
257+
// 9. Menu item with tooltip
238258
final tooltipItem = MenuItem('Item with Tooltip');
239259
tooltipItem.tooltip = 'This is a helpful tooltip message';
240260
tooltipItem.on<MenuItemClickedEvent>((event) {
@@ -243,10 +263,10 @@ class _MenuExamplePageState extends State<MenuExamplePage> {
243263
_contextMenu.addItem(tooltipItem);
244264
_menuItems.add(tooltipItem);
245265

246-
// 8. Separator
266+
// 10. Separator
247267
_contextMenu.addSeparator();
248268

249-
// 9. Submenu
269+
// 11. Submenu
250270
_submenu = Menu();
251271
_submenuItem = MenuItem('Submenu', MenuItemType.submenu);
252272

@@ -284,10 +304,10 @@ class _MenuExamplePageState extends State<MenuExamplePage> {
284304
_contextMenu.addItem(_submenuItem);
285305
_menuItems.add(_submenuItem);
286306

287-
// 10. Separator
307+
// 12. Separator
288308
_contextMenu.addSeparator();
289309

290-
// 11. Menu items with special characters
310+
// 13. Menu items with special characters
291311
final specialCharsItem = MenuItem('Special: 中文 日本語 🎉 @#\$%');
292312
specialCharsItem.on<MenuItemClickedEvent>((event) {
293313
_addToHistory('Special chars item clicked (ID: ${event.menuItemId})');
@@ -348,8 +368,9 @@ class _MenuExamplePageState extends State<MenuExamplePage> {
348368
setState(() {
349369
_currentLabel =
350370
'Updated at ${DateTime.now().toString().substring(11, 19)}';
351-
if (_menuItems.length > 5) {
352-
_menuItems[5].label = _currentLabel;
371+
// Dynamic label item is now at index 7 due to added disabled items
372+
if (_menuItems.length > 7) {
373+
_menuItems[7].label = _currentLabel;
353374
}
354375
});
355376
_addToHistory('Menu item label changed to: $_currentLabel');
@@ -620,6 +641,51 @@ class _MenuExamplePageState extends State<MenuExamplePage> {
620641
_addToHistory('Opened menu at cursor position');
621642
}
622643

644+
/// Reproduce issue #4: checked/disabled menu item states not working on Windows
645+
void _openBugReproMenu(Offset position) {
646+
// This directly reproduces the code from the issue:
647+
// https://github.com/libnativeapi/nativeapi-flutter/issues/4
648+
final menu = Menu();
649+
650+
// Checkable item with Checked state
651+
final checkableItem = MenuItem('Checkable', MenuItemType.checkbox);
652+
checkableItem.state = MenuItemState.checked;
653+
checkableItem.on<MenuItemClickedEvent>((event) {
654+
_addToHistory('Checkable item clicked (ID: ${event.menuItemId})');
655+
});
656+
menu.addItem(checkableItem);
657+
658+
// Disabled item
659+
final disabledItem = MenuItem('Disabled');
660+
disabledItem.enabled = false;
661+
disabledItem.on<MenuItemClickedEvent>((event) {
662+
_addToHistory('Disabled item clicked (should not fire!)');
663+
});
664+
menu.addItem(disabledItem);
665+
666+
// Add a few more items for context
667+
menu.addSeparator();
668+
final exitItem = MenuItem('Close Menu');
669+
exitItem.on<MenuItemClickedEvent>((event) {
670+
menu.close();
671+
});
672+
menu.addItem(exitItem);
673+
674+
menu.open(PositioningStrategy.absolute(position));
675+
676+
_addToHistory('');
677+
_addToHistory('=== BUG REPRODUCTION (Issue #4) ===');
678+
_addToHistory('Menu opened at ${position}');
679+
_addToHistory('Checkable item initial state: ${checkableItem.state}');
680+
_addToHistory('Disabled item enabled: ${disabledItem.enabled}');
681+
_addToHistory('');
682+
_addToHistory('EXPECTED: Checkbox shows checkmark; Disabled item grayed');
683+
_addToHistory(
684+
'BUG (Windows only): Checkmark missing; Disabled item active',
685+
);
686+
_addToHistory('');
687+
}
688+
623689
@override
624690
Widget build(BuildContext context) {
625691
return Scaffold(
@@ -976,6 +1042,11 @@ class _MenuExamplePageState extends State<MenuExamplePage> {
9761042
);
9771043
},
9781044
),
1045+
_buildCompactButton(
1046+
Icons.bug_report,
1047+
'Bug #4 (Win)',
1048+
() => _openBugReproMenu(const Offset(200, 200)),
1049+
),
9791050
],
9801051
),
9811052
]),

0 commit comments

Comments
 (0)