Overview
The adaptive_number package provides a number type that adapts to the runtime environment. On JavaScript platforms, it uses a 64-bit signed fixed-width integer for consistent precision, while on all other platforms it defaults to Dart's native int. This ensures reliable behavior across web and native environments, particularly when handling large integers or requiring cross-platform consistency in numerical operations.
Use cases
- Cross-platform integer handling
- Web-based applications with large numbers
- Consistent arithmetic across platforms
- Data serialization involving integers
- Numerical computations in Flutter web apps
Key features
- Adaptive integer size based on platform
- 64-bit fixed-width integers on JS
- Native int fallback on non-JS platforms
- Consistent behavior across runtimes
- Simple integration with existing code
Suitable for
- Developers targeting web and native platforms
- Apps requiring precise integer arithmetic
- Projects needing portability of numeric logic
- Teams avoiding JS-specific number limitations
- Flutter apps with shared business logic
Considerations
- Limited to integer values only
- No support for floating-point numbers
- Performance overhead on non-JS platforms
- May not be needed for simple use cases
- Requires careful testing on JS targets