A Flutter mobile application that generates and displays 9x9 Latin squares with customizable starting orders.
This app showcases mathematical Latin squares - 9x9 grids where each number from 1 to 9 appears exactly once in every row and column. Users can:
- View a default Latin square on app launch
- Enter a custom starting order (1-9) to generate different Latin square patterns
- See the square displayed in a responsive grid with clear borders
The app uses a row rotation algorithm for generating Latin squares:
- First Row: Starting with the chosen order
k, create a sequence[k, k+1, ..., 9, 1, ..., k-1] - Subsequent Rows: Each row is a left-rotation of the previous row by one position
Row 0: 3 4 5 6 7 8 9 1 2
Row 1: 4 5 6 7 8 9 1 2 3
Row 2: 5 6 7 8 9 1 2 3 4
...
This guarantees:
- ✅ Every row contains 1-9 exactly once
- ✅ Every column contains 1-9 exactly once
- ✅ Deterministic: same starting order always produces the same square
- ✅ Performance: O(81) operations, computed instantly
Default Square: Launches with starting order 1 Custom Starting Order: Input any number 1-9 to regenerate Input Validation: Clear error messages for invalid inputs Responsive Grid: Adapts to different screen sizes and orientations Instant Feedback: Square regenerates immediately on valid input Updated Heading: The blue bar at the top of the page now displays "Latin Squares Demonstration" for clarity
- Flutter SDK 3.0.0 or higher
- Dart SDK 3.0.0 or higher
- iOS 12+ or Android 6.0+ device/emulator
-
Clone the repository:
git clone <repository-url> cd latin_squares
-
Install dependencies:
flutter pub get
-
Run the app:
flutter run
-
Run tests:
flutter test -
Run with coverage:
flutter test --coverage
lib/
├── main.dart # App entry point and UI
├── models/
│ ├── latin_square.dart # Immutable Latin square data model
│ └── latin_square_generator.dart # Generator with row rotation algorithm
├── widgets/
│ └── latin_square_grid.dart # Responsive 9x9 grid widget
└── utils/
└── starting_order_input.dart # Input parsing and validation
test/
├── models/ # Unit tests for models and generator
├── widgets/ # Widget tests for UI components
└── utils/ # Validation logic tests
integration_test/
└── app_test.dart # End-to-end integration tests
The app follows a library-first design principle:
- Pure Dart Models (
lib/models/): Business logic with zero Flutter dependencies - Flutter UI Layer (
lib/widgets/,lib/main.dart): UI components that consume models - TDD Approach: All code test-driven (37 unit/widget tests, 100% pass rate)
test/models/latin_square_test.dart: Model creation, valueAt, getRow, getColumn, equalitytest/models/latin_square_generator_test.dart: Determinism, row/column uniqueness, value range, algorithm correctness
test/widgets/latin_square_grid_test.dart: GridView presence, 81 cells, correct values, borders, responsive sizing
test/utils/starting_order_input_test.dart: Valid inputs (1-9), invalid inputs (0, 10, non-numbers), error messages
integration_test/app_test.dart: Full user flows, default square, custom input, validation, determinism
Test Coverage: >80% (all critical paths covered)
- Grid Size: Fixed 9x9 (not configurable)
- Values: Numbers only (no symbols, letters, or custom values)
- Platforms: Mobile (iOS/Android) and Web (Flutter web)
- Storage: No persistence (squares regenerated on restart)
- App Launch: Latin square displays within <1 second ✅
- Regeneration: Completes within <2 seconds of valid input ✅
- App Size: <50MB ✅
- UI: 60fps smooth scrolling/resizing ✅
All generated squares are mathematically guaranteed to be valid Latin squares through contract tests:
- ✅ Determinism: Same order → same square (always)
- ✅ Row Uniqueness: Each row has 1-9 exactly once
- ✅ Column Uniqueness: Each column has 1-9 exactly once
- ✅ Completeness: All 81 cells populated
- ✅ Value Range: All values in [1,9]
This project follows the Latin Squares Constitution v1.0.0:
- ✅ Principle I: Library-first design (pure Dart models, Flutter UI layer)
- ✅ Principle II: TDD approach (37 tests, Red-Green-Refactor cycles)
- ✅ Principle III: Algorithm correctness (contract tests, mathematical guarantees)
- ✅ Principle IV: Documentation (dartdoc on all public APIs)
- ✅ Principle V: Simplicity (zero external dependencies, <1000 LOC)