craig

show me a minimal flutter app that uses theta-client to display the live preview from a RICOH THETA camera

Theta_Persona_bot

I’ll help you create a minimal Flutter app that shows the live preview from a THETA camera using theta-client. I’ll include important setup information and a basic example.

First, make sure you have the correct setup for theta_client_flutter. As of February 2024, you need to install it from source code.

Here’s a minimal example that shows live preview:

import 'package:flutter/material.dart';
import 'package:theta_client_flutter/theta_client_flutter.dart';
import 'dart:typed_data';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: PreviewScreen(),
    );
  }
}

class PreviewScreen extends StatefulWidget {
  @override
  _PreviewScreenState createState() => _PreviewScreenState();
}

class _PreviewScreenState extends State<PreviewScreen> {
  final _thetaClient = ThetaClientFlutter();
  bool _previewing = false;
  Uint8List? _frameData;

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

  Future<void> _initializeAndStartPreview() async {
    try {
      // Initialize theta client
      await _thetaClient.initialize();
      _startLivePreview();
    } catch (error) {
      print('Error initializing: $error');
    }
  }

  void _startLivePreview() {
    _previewing = true;
    _thetaClient.getLivePreview(_frameHandler)
        .then((_) => print('Preview done'))
        .catchError((error) => print('Preview error: $error'));
  }

  bool _frameHandler(Uint8List frameData) {
    if (mounted) {
      setState(() {
        _frameData = frameData;
      });
    }
    return _previewing;
  }

  @override
  void dispose() {
    _previewing = false;
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('THETA Live Preview'),
      ),
      body: Center(
        child: _frameData == null
            ? const CircularProgressIndicator()
            : Image.memory(
                _frameData!,
                gaplessPlayback: true,
                errorBuilder: (context, error, stackTrace) {
                  return Container(color: Colors.black);
                },
              ),
      ),
    );
  }
}

Important setup steps before running the code:

  1. Create a new Flutter project with iOS and Android support:
flutter create --platforms=android,ios -i swift -a kotlin theta_preview_app
  1. In your pubspec.yaml, add the theta_client_flutter dependency. As of February 2024, you need to install it from source:
dependencies:
  flutter:
    sdk: flutter
  theta_client_flutter:
    path: ./packages/theta_client_flutter  # Path to where you copied the package
  1. For Android, set the minimum SDK version to 26 or higher in android/app/build.gradle:
minSdkVersion 26
  1. For iOS, set the deployment target to 15.0 or higher in your ios/Podfile:
platform :ios, '15.0'
  1. Make sure your camera is in access point mode and your device is connected to the THETA’s Wi-Fi network before running the app.

This example will:

  1. Initialize the THETA client
  2. Start the live preview
  3. Display each frame as it comes in from the camera
  4. Properly clean up when the app is closed

Key features of this minimal example:

  • Uses ThetaClientFlutter for camera communication
  • Implements live preview using getLivePreview
  • Displays the preview frames using Flutter’s Image.memory widget
  • Handles initialization and cleanup properly
  • Includes basic error handling

For more detailed information about the THETA client for Flutter, you can check out:

Let me search for some additional community examples that might be helpful.

Search

Found 46 results for 'flutter preview example theta status:public'

Based on the search results and my knowledge, I’ll help you create a minimal Flutter app that shows live preview from a THETA camera using theta-client. Here’s a step-by-step guide:

  1. First, make sure you have the theta-client Flutter package. As of February 2024, you need to install it from source:
dependencies:
  flutter:
    sdk: flutter
  theta_client_flutter:
    path: ./packages/theta_client_flutter
  1. Here’s a minimal Flutter app that shows live preview:
import 'package:flutter/material.dart';
import 'package:theta_client_flutter/theta_client_flutter.dart';
import 'dart:typed_data';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: PreviewScreen(),
    );
  }
}

class PreviewScreen extends StatefulWidget {
  @override
  _PreviewScreenState createState() => _PreviewScreenState();
}

class _PreviewScreenState extends State<PreviewScreen> {
  final _thetaClientFlutter = ThetaClientFlutter();
  bool _previewing = false;
  Uint8List? _previewImage;

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

  void _initTheta() async {
    try {
      await _thetaClientFlutter.initialize();
      _startPreview();
    } catch (e) {
      print('Error initializing theta: $e');
    }
  }

  void _startPreview() {
    _previewing = true;
    _thetaClientFlutter.getLivePreview(_frameHandler)
        .then((_) {
          print('Preview done');
        })
        .catchError((error) {
          print('Error in preview: $error');
        });
  }

  bool _frameHandler(Uint8List frameData) {
    setState(() {
      _previewImage = frameData;
    });
    return _previewing;
  }

  @override
  void dispose() {
    _previewing = false;
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('THETA Live Preview'),
      ),
      body: Center(
        child: _previewImage != null
            ? Image.memory(
                _previewImage!,
                gaplessPlayback: true,
              )
            : CircularProgressIndicator(),
      ),
    );
  }
}

Important notes:

  1. Your THETA camera must be connected to your phone/device via Wi-Fi
  2. The default THETA IP address is 192.168.1.1
  3. For Android, you need to set the minimum SDK version to 26 or higher
  4. For iOS, set the deployment target to 15.0 or higher

For more details, check out these resources:

The preview will show as an equirectangular image (flat 360° view). If you want to display it in a navigable 360° view, you can use packages like panorama or panorama_viewer.

You can find the complete setup instructions in this post: Theta-client tips

Need any clarification or have questions about specific parts of the code?