import 'dart:io'; import 'package:flutter_test/flutter_test.dart'; /// Window content takes input only inside its window (see `WindowNavigator`), /// so a `MenuAnchor` panel, which may extend past the window, must be in the /// root overlay. Any content can end up in a window, so every `MenuAnchor` in /// the app opts in. void main() { test('every MenuAnchor targets the root overlay', () { final offenders = []; for (final file in Directory('lib').listSync(recursive: true)) { if (file is! File || !file.path.endsWith('.dart')) continue; final source = file.readAsStringSync(); for (final match in RegExp(r'\bMenuAnchor\(').allMatches(source)) { final end = (match.end + 400).clamp(0, source.length); if (!source .substring(match.end, end) .contains('useRootOverlay: true')) { final line = '\n'.allMatches(source.substring(0, match.start)).length; offenders.add('${file.path}:${line + 1}'); } } } expect(offenders, isEmpty); }); }