augmented_reality_plugin Flutter Package for Augmented Reality: for iOS & Android Platform
augmented_reality_plugin is an augmented reality flutter ios and android application package for mobile devices that enables to build augmented reality applications.
Thanks to Muhammad Ali from Coding Cafe for the help in making this augmented_reality_plugin.
Features
- Display the Live Camera Preview.
- Customize Camera, Place any object, anywhere on the Screen.
- Choose objects in png or jpg.
- Resize, Drag, Rotate, Zoom In and Out any Object.
- and Much More...
Getting Started
Installing
Add the Flutter package to your project by running:
flutter pub add augmented_reality_plugin
Or manually add this to your pubspec.yaml
file (and run flutter pub get
):
dependencies:
augmented_reality_plugin: ^4.0.1
iOS
augmented_reality_plugin functionality works on iOS 10.0 or higher. If compiling for any version lower than 10.0, make sure to programmatically check the version of iOS running on the device before using any camera plugin features.
Add two rows to the ios/Runner/Info.plist
:
- one with the key
Privacy - Camera Usage Description
and a usage description. - and one with the key
Privacy - Microphone Usage Description
and a usage description.
Or in text format add the key:
<key>NSCameraUsageDescription</key>
<string>Can I use the camera please?</string>
<key>NSMicrophoneUsageDescription</key>
<string>Can I use the mic please?</string>
Android
Change the minimum Android sdk version to 24 (or higher) in your android/app/build.gradle
file.
minSdkVersion 24
Always test app on your real phone and not emulators/simulators.
It's important to note that the MediaRecorder
class is not working properly on emulators, as stated in the documentation: https://developer.android.com/reference/android/media/MediaRecorder. Specifically, when recording a video with sound enabled and trying to play it back, the duration won't be correct and you will only see the first frame.
Importing
Add this to your code:
import 'package:augmented_reality_plugin/augmented_reality_plugin.dart';
Usage or How to Use
Replace your Scaffold to AugmentedRealityPlugin(), and it will handle all your view. if you want to pass an image just pass an image as a constructor.
#Write this code in main
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
List<CameraDescription> allCameras = [];
Future<void> main() async {
try {
WidgetsFlutterBinding.ensureInitialized();
allCameras = await availableCameras();
} on CameraException catch (errorMessage) {
print(errorMessage.description);
}
runApp(const MyApp());
}
Add main class
class AugmentedRealityView extends StatefulWidget {
const AugmentedRealityView({Key? key}) : super(key: key);
@override
_AugmentedRealityViewState createState() => _AugmentedRealityViewState();
}
class _AugmentedRealityViewState extends State<AugmentedRealityView> {
@override
Widget build(BuildContext context) {
return AugmentedRealityPlugin(
'https://www.freepnglogos.com/uploads/furniture-png/furniture-png-transparent-furniture-images-pluspng-15.png'
);
}
}