ar_core_new 0.0.1 copy "ar_core_new: ^0.0.1" to clipboard
ar_core_new: ^0.0.1 copied to clipboard

PlatformAndroid

Flutter plugin exposing ARCore Android SDK functionality.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:ar_core_new/ar_core_new.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _status = 'Idle';
  final _arCoreNewPlugin = ArCoreNew();

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    try {
      final version = await _arCoreNewPlugin.getPlatformVersion() ?? 'Unknown';
      final availability = await _arCoreNewPlugin.checkAvailability();
      final supported = await _arCoreNewPlugin.isSupported();
      _status =
          'Version: $version\nAvailability: $availability\nSupported: $supported';
    } on PlatformException {
      _status = 'Failed to query ARCore plugin state.';
    }

    if (!mounted) return;

    setState(() {});
  }

  Future<void> _createAndResumeSession() async {
    try {
      await _arCoreNewPlugin.createSession(
        config: const ArCoreSessionConfig(
          depthMode: ArCoreDepthMode.automatic,
          planeFindingMode: ArCorePlaneFindingMode.horizontalAndVertical,
          lightEstimationMode: ArCoreLightEstimationMode.environmentalHdr,
        ),
      );
      await _arCoreNewPlugin.resumeSession();
      if (!mounted) return;
      setState(() {
        _status = 'ARCore session created and resumed.';
      });
    } on PlatformException catch (e) {
      if (!mounted) return;
      setState(() {
        _status = 'Session start failed: ${e.code} ${e.message}';
      });
    }
  }

  Future<void> _pauseAndCloseSession() async {
    try {
      await _arCoreNewPlugin.pauseSession();
      await _arCoreNewPlugin.closeSession();
      if (!mounted) return;
      setState(() {
        _status = 'ARCore session paused and closed.';
      });
    } on PlatformException catch (e) {
      if (!mounted) return;
      setState(() {
        _status = 'Session stop failed: ${e.code} ${e.message}';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(16),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(_status, textAlign: TextAlign.center),
                const SizedBox(height: 24),
                ElevatedButton(
                  onPressed: _createAndResumeSession,
                  child: const Text('Create + Resume Session'),
                ),
                const SizedBox(height: 12),
                ElevatedButton(
                  onPressed: _pauseAndCloseSession,
                  child: const Text('Pause + Close Session'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
0
likes
140
points
67
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin exposing ARCore Android SDK functionality.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on ar_core_new

Packages that implement ar_core_new