space_story_sdk 0.0.5
space_story_sdk: ^0.0.5 copied to clipboard
A Flutter plugin for AR functionality using ARKit on iOS.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:space_story_sdk/space_story_sdk.dart';
import 'package:space_story_sdk/src/ar/data/ar_channel.dart';
import 'package:space_story_sdk/src/ar/data/ar_provider.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
// ARProvider 명시적 초기화
ARProvider(); // 팩토리 생성자를 통해 초기화
// AR 뷰 팩토리 초기화
// SpaceStorySdk.registerARViewFactory();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Space Story SDK Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final ARChannel _arChannel = ARChannel();
bool _isPeriodicEventsRunning = false;
@override
void initState() {
super.initState();
// 주기적 이벤트 스트림 리스너 설정
_arChannel.getPeriodicEventStream().listen((event) {
print('📬 받은 이벤트: $event');
}, onError: (error) {
print('❌ 이벤트 스트림 오류: $error');
});
}
void _togglePeriodicEvents() async {
if (_isPeriodicEventsRunning) {
await _arChannel.stopPeriodicEvents();
} else {
await _arChannel.startPeriodicEvents();
}
setState(() {
_isPeriodicEventsRunning = !_isPeriodicEventsRunning;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Space Story SDK Example'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Space Story SDK를 사용한 AR 데모',
style: TextStyle(fontSize: 20),
textAlign: TextAlign.center,
),
const SizedBox(height: 40),
// 주기적 이벤트 토글 버튼
ElevatedButton(
onPressed: _togglePeriodicEvents,
style: ElevatedButton.styleFrom(
backgroundColor: _isPeriodicEventsRunning ? Colors.red : Colors.blue,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 50, vertical: 20),
),
child: Text(_isPeriodicEventsRunning ? '주기적 이벤트 중지' : '주기적 이벤트 시작', style: const TextStyle(fontSize: 22)),
),
// AR 게임 시작 버튼
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SpaceStorySdk.arView(
onCapture: (capturedCount) {
// 포획 성공 시 실행되는 콜백
print('🎉 포획 성공! 총 $capturedCount마리 잡았습니다!');
// 스낵바로 알림
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('🎉 포획 성공! 총 $capturedCount마리'),
backgroundColor: Colors.green,
duration: const Duration(seconds: 2),
),
);
},
),
),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 50, vertical: 20),
),
child: const Text('AR 게임 시작', style: TextStyle(fontSize: 22)),
),
],
),
),
);
}
}