|
| 1 | +# Flutter Widget from HTML |
| 2 | + |
| 3 | +Flutter Widget from HTML is a monorepo containing Flutter/Dart packages that render HTML as Flutter widgets. The repository includes a core package, enhanced wrapper, feature extensions, and a demo app for testing. |
| 4 | + |
| 5 | +Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here. |
| 6 | + |
| 7 | +## Working Effectively |
| 8 | + |
| 9 | +Bootstrap, build, and test the repository: |
| 10 | +- Check Flutter installation: `flutter --version` -- should show Flutter 3.35.2+ and Dart 3.9.0+ |
| 11 | +- Install dependencies: `./tool/pub-get.sh` -- takes 30 seconds. Dependencies are installed across all packages. |
| 12 | +- Run full analysis and tests: `./tool/test.sh` -- takes 3-4 minutes. NEVER CANCEL. Set timeout to 10+ minutes. |
| 13 | +- Run tests with coverage: `./tool/test.sh --coverage` -- takes 2-3 minutes. NEVER CANCEL. Set timeout to 8+ minutes. |
| 14 | +- Format code: `dart format . --output none` -- takes 2-3 seconds. |
| 15 | + |
| 16 | +## Build Commands |
| 17 | + |
| 18 | +Web demo app: |
| 19 | +- Build for web: `cd demo_app && flutter build web --release` -- takes 45 seconds. NEVER CANCEL. Set timeout to 2+ minutes. |
| 20 | +- Run web app: `cd demo_app && flutter run -d web-server --web-port 8080 --web-hostname 0.0.0.0` -- starts development server. |
| 21 | + |
| 22 | +Android demo app: |
| 23 | +- Build debug APK: `cd demo_app && flutter build apk --debug` -- takes 1-2 minutes. NEVER CANCEL. Set timeout to 5+ minutes. |
| 24 | +- Build release APKs: `cd demo_app && flutter build apk --release --split-per-abi` -- takes 2-3 minutes. NEVER CANCEL. Set timeout to 8+ minutes. |
| 25 | + |
| 26 | +## Testing and Validation |
| 27 | + |
| 28 | +Run tests with different options: |
| 29 | +- Run all tests: `./tool/test.sh` -- takes 3-4 minutes. Runs analysis and tests for all packages. |
| 30 | +- Run with coverage: `./tool/test.sh --coverage` -- takes 2-3 minutes. Generates coverage reports. |
| 31 | +- Update golden files: `./tool/test.sh --update-goldens` -- takes 2-3 minutes. Updates visual regression test images. |
| 32 | +- Update goldens only: `./tool/update-goldens.sh` -- convenience script for updating golden files. |
| 33 | + |
| 34 | +Individual package testing: |
| 35 | +- Analyze specific package: `cd packages/core && flutter analyze` -- takes 1-2 seconds. |
| 36 | +- Test specific package: `cd packages/core && flutter test` -- takes 40-45 seconds. |
| 37 | +- Test enhanced package: `cd packages/enhanced && flutter test` -- takes 20-25 seconds. |
| 38 | + |
| 39 | +Integration testing: |
| 40 | +- Web integration tests require chromedriver running on port 4444. |
| 41 | +- Start chromedriver: `chromedriver --port=4444 &` then set `CHROMEDRIVER_PORT_4444=yes`. |
| 42 | + |
| 43 | +## Validation Scenarios |
| 44 | + |
| 45 | +Always test these scenarios after making changes: |
| 46 | +- **Basic HTML rendering**: Run `cd demo_app && flutter test` to verify golden file tests pass -- takes 5-10 seconds. |
| 47 | +- **Web demo functionality**: Build and run the demo app with `cd demo_app && flutter build web && flutter run -d web-server` and verify HTML rendering works. |
| 48 | +- **Core package functionality**: Run `cd packages/core && flutter test` to ensure core widget functionality works. |
| 49 | +- **Enhanced package features**: Run `cd packages/enhanced && flutter test` to verify enhanced features work. |
| 50 | +- **Code formatting**: Run `dart format . --output none` and ensure no files are changed. |
| 51 | + |
| 52 | +## Repository Structure |
| 53 | + |
| 54 | +Key directories and their purposes: |
| 55 | +- `packages/core/`: Core HTML widget package (`flutter_widget_from_html_core`) |
| 56 | +- `packages/enhanced/`: Enhanced wrapper package (`flutter_widget_from_html`) |
| 57 | +- `packages/fwfh_*/`: Feature extension packages (cached images, webview, audio, etc.) |
| 58 | +- `demo_app/`: Example Flutter app for manual testing and screenshots |
| 59 | +- `tool/`: Helper scripts for dependency management, testing, and publishing |
| 60 | +- `test/images/`: Golden file assets for visual regression testing |
| 61 | + |
| 62 | +## Package Dependencies |
| 63 | + |
| 64 | +SDK requirements: |
| 65 | +- Flutter: >=3.32.0 |
| 66 | +- Dart: >=3.4.0 |
| 67 | + |
| 68 | +Main dependencies across packages: |
| 69 | +- `csslib`: CSS parsing |
| 70 | +- `html`: HTML parsing |
| 71 | +- `logging`: Logging framework |
| 72 | +- `flutter_test`, `test`, `golden_toolkit`: Testing frameworks |
| 73 | + |
| 74 | +## Common Tasks |
| 75 | + |
| 76 | +Check for outdated dependencies: |
| 77 | +- `./tool/pub-outdated.sh` -- shows outdated packages across all modules. |
| 78 | + |
| 79 | +Publish packages to pub.dev: |
| 80 | +- `./tool/pub-publish.sh` -- publishes all packages. Requires clean git state and version bumps. |
| 81 | + |
| 82 | +Update demo app platform files: |
| 83 | +- `./tool/update-demo_app-files.sh` -- regenerates iOS, Android, macOS, and web platform files. |
| 84 | + |
| 85 | +## Development Workflow |
| 86 | + |
| 87 | +When making changes: |
| 88 | +1. Run `./tool/pub-get.sh` to ensure all dependencies are current |
| 89 | +2. Make your changes to the appropriate package(s) |
| 90 | +3. Format code with `dart format .` |
| 91 | +4. Run relevant tests: `./tool/test.sh` or individual package tests |
| 92 | +5. For UI changes, verify golden files with `./tool/test.sh --update-goldens` |
| 93 | +6. Build and test the demo app to verify changes work end-to-end |
| 94 | + |
| 95 | +## Key Files |
| 96 | + |
| 97 | +Configuration files: |
| 98 | +- `analysis_options.yaml`: Linting rules in each package directory |
| 99 | +- `pubspec.yaml`: Package configuration in each package directory |
| 100 | +- `dart_test.yaml`: Test configuration in demo_app |
| 101 | + |
| 102 | +Important scripts: |
| 103 | +- `tool/test.sh`: Main test runner with analysis and testing |
| 104 | +- `tool/pub-get.sh`: Dependency installation across all packages |
| 105 | +- `tool/update-goldens.sh`: Golden file update helper |
| 106 | + |
| 107 | +## Known Issues and Workarounds |
| 108 | + |
| 109 | +Format checking in CI: |
| 110 | +- `dart format --set-exit-if-changed` is commented out in CI due to GitHub Actions issues |
| 111 | +- Always run `dart format .` locally before committing |
| 112 | + |
| 113 | +Web integration tests: |
| 114 | +- Require Chrome/chromedriver for JavaScript interop testing |
| 115 | +- Only run when `CHROMEDRIVER_PORT_4444` environment variable is set |
| 116 | + |
| 117 | +Golden file testing: |
| 118 | +- Visual regression tests use `golden_toolkit` framework |
| 119 | +- Golden files stored in `test/images/` directories |
| 120 | +- Regenerate with `--update-goldens` flag when making UI changes |
| 121 | + |
| 122 | +## Timeout Guidelines |
| 123 | + |
| 124 | +**CRITICAL**: Always use appropriate timeouts and NEVER CANCEL long-running commands: |
| 125 | + |
| 126 | +- Dependency installation (`./tool/pub-get.sh`): 30 seconds -- use 2+ minute timeout |
| 127 | +- Full test suite (`./tool/test.sh`): 3-4 minutes -- use 10+ minute timeout, NEVER CANCEL |
| 128 | +- Coverage tests (`./tool/test.sh --coverage`): 2-3 minutes -- use 8+ minute timeout, NEVER CANCEL |
| 129 | +- Golden updates (`./tool/test.sh --update-goldens`): 2-3 minutes -- use 8+ minute timeout, NEVER CANCEL |
| 130 | +- Web build (`flutter build web`): 45 seconds -- use 2+ minute timeout, NEVER CANCEL |
| 131 | +- APK builds (`flutter build apk`): 1-3 minutes -- use 5-8+ minute timeout, NEVER CANCEL |
| 132 | +- Individual package tests: 20-45 seconds -- use 2+ minute timeout |
| 133 | + |
| 134 | +Build and test commands may take longer than expected. This is NORMAL. Always wait for completion. |
0 commit comments