roomplan_flutter 0.0.3
roomplan_flutter: ^0.0.3 copied to clipboard
A Flutter plugin for iOS that provides access to Apple's RoomPlan API, allowing you to easily scan an interior room and receive a 3D model with detailed measurements.
Flutter RoomPlan #
A Flutter plugin that allows you to use Apple's RoomPlan API to scan an interior room and get a 3D model and measurements.
Requirements #
- iOS 16.0+
- A device with a LiDAR sensor is required (e.g., iPhone 12 Pro or newer Pro models, iPad Pro).
Installation #
First, add roomplan_flutter to your pubspec.yaml dependencies:
dependencies:
roomplan_flutter: ^0.0.3 # Replace with the latest version
Then, add the required NSCameraUsageDescription to your ios/Runner/Info.plist file to explain why your app needs camera access:
<key>NSCameraUsageDescription</key>
<string>This app uses the camera to scan your room and create a 3D model.</string>
Finally, run flutter pub get.
Usage #
Here's a basic example of how to use the RoomPlanScanner in a Flutter widget.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:roomplan_flutter/roomplan_flutter.dart';
class ScannerWidget extends StatefulWidget {
const ScannerWidget({super.key});
@override
State<ScannerWidget> createState() => _ScannerWidgetState();
}
class _ScannerWidgetState extends State<ScannerWidget> {
late final RoomPlanScanner _roomScanner;
StreamSubscription<ScanResult>? _scanSubscription;
@override
void initState() {
super.initState();
_roomScanner = RoomPlanScanner();
// Listen to real-time updates
_scanSubscription = _roomScanner.onScanResult.listen((result) {
print('Room updated! Walls: ${result.room.walls.length}');
});
}
@override
void dispose() {
// It's important to cancel the subscription and dispose the scanner
_scanSubscription?.cancel();
_roomScanner.dispose();
super.dispose();
}
Future<void> _startScan() async {
try {
final result = await _roomScanner.startScanning();
// Use the final result
print('Scan complete! Room has ${result?.room.walls.length} walls.');
} on ScanCancelledException {
print('Scan was cancelled by the user.');
} catch (e) {
print('Error finishing scan: $e');
}
}
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: _startScan,
child: const Text('Start Scan'),
);
}
}
See the example app for a more detailed implementation.
Data Models #
The plugin returns a ScanResult object, which contains a tree of structured data.
-
ScanResult: The root object containing the full scan details.room: ARoomDataobject with information about the scanned room.metadata: AScanMetadataobject with details about the session.confidence: AScanConfidenceobject indicating the scan's quality.
-
RoomData: Contains the physical properties of the room.dimensions: ARoomDimensionsobject (length,width,height).walls: A list ofWallDataobjects.objects: A list ofObjectDataobjects (e.g., table, chair).doors: A list ofOpeningDatafor doors.windows: A list ofOpeningDatafor windows.
-
WallData,ObjectData,OpeningData: These models describe a physical entity and share common fields:uuid: A unique identifier for the entity.position: APositionobject (Vector3) representing the center point.dimensions/width,height,length: The size of the entity.confidence: An enum (Confidence.low,medium,high) for the detected entity.
-
ScanMetadata: Contains metadata about the scanning session.scanDuration: ADurationobject.scanDate: TheDateTimewhen the scan started.deviceModel: The model of the device (e.g., "iPhone14,3").hasLidar: A boolean indicating if the device has a LiDAR sensor.
-
ScanConfidence: Contains confidence values for different aspects of the scan.overall: Adoublefrom 0.0 to 1.0.wallAccuracy: Adoublefor the accuracy of wall detection.dimensionAccuracy: Adoublefor the accuracy of measurements.
Refer to the source code for detailed information on all fields.