flutter_r2u 0.0.2 flutter_r2u: ^0.0.2 copied to clipboard
A new flutter plugin project.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_r2u/flutter_r2u.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final String customerId = '5e8e7580404328000882f4ae';
final String sku = 'RE000001';
bool init = false;
bool isActive = false;
bool supportsAR = false;
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
try {
await R2U.init(customerId: customerId);
init = true;
supportsAR = await R2U.deviceSupportsAR();
print("supportsAR " + supportsAR.toString());
isActive = await R2U.isActive(sku);
print("isActive " + isActive.toString());
} on PlatformException {
print('Failed to init R2U Flutter SDK');
}
if (!mounted) return;
}
void onPressed() {
R2U.openAR(sku: sku);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('R2U Flutter SDK'),
),
body: Center(
child: Column(children: <Widget>[
Container(
margin: EdgeInsets.all(25),
child: ElevatedButton(
child: Text(
'View in your space',
style: TextStyle(fontSize: 20.0),
),
onPressed: init && supportsAR && isActive ? onPressed : null,
),
),
]))),
);
}
}