ifp_detector 1.0.0
ifp_detector: ^1.0.0 copied to clipboard
Detect Interactive Flat Panels (IFPs) vs tablets on Android. Analyze screen size, brand, hardware features, and stylus support with confidence scoring for licensing and feature control.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:ifp_detector/ifp_detector.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'IFP Detector Example',
theme: ThemeData(primarySwatch: Colors.blue, useMaterial3: true),
home: const IFPDetectorExample(),
);
}
}
class IFPDetectorExample extends StatefulWidget {
const IFPDetectorExample({super.key});
@override
State<IFPDetectorExample> createState() => _IFPDetectorExampleState();
}
class _IFPDetectorExampleState extends State<IFPDetectorExample> {
IfpDetectionResult? _detectionResult;
bool _isLoading = false;
String? _errorMessage;
Future<void> _detectDevice() async {
setState(() {
_isLoading = true;
_errorMessage = null;
_detectionResult = null;
});
try {
final result = await IfpDetector.detectIfp();
setState(() {
_detectionResult = result;
});
} on PlatformException catch (e) {
setState(() {
_errorMessage = "Detection failed: ${e.message}";
});
} catch (e) {
setState(() {
_errorMessage = "Unexpected error: $e";
});
} finally {
setState(() {
_isLoading = false;
});
}
}
Future<void> _simpleCheck() async {
setState(() {
_isLoading = true;
_errorMessage = null;
_detectionResult = null;
});
try {
final isIFP = await IfpDetector.isIfp();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
isIFP
? 'This is an Interactive Flat Panel'
: 'This is a regular tablet',
),
backgroundColor: isIFP ? Colors.orange : Colors.green,
),
);
} on PlatformException catch (e) {
setState(() {
_errorMessage = "Detection failed: ${e.message}";
});
} catch (e) {
setState(() {
_errorMessage = "Unexpected error: $e";
});
} finally {
setState(() {
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('IFP Detector Plugin Example'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const Icon(Icons.devices, size: 48),
const SizedBox(height: 8),
const Text(
'IFP Detector Plugin',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
const Text(
'Detect whether this device is an Interactive Flat Panel or a regular tablet',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey),
),
],
),
),
),
const SizedBox(height: 20),
ElevatedButton.icon(
onPressed: _isLoading ? null : _detectDevice,
icon: const Icon(Icons.search),
label: const Text('Detailed Detection'),
),
const SizedBox(height: 12),
ElevatedButton.icon(
onPressed: _isLoading ? null : _simpleCheck,
icon: const Icon(Icons.check_circle),
label: const Text('Simple Check'),
),
const SizedBox(height: 20),
if (_isLoading)
const Center(child: CircularProgressIndicator())
else if (_errorMessage != null)
Card(
color: Colors.red.shade50,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const Icon(Icons.error, color: Colors.red),
const SizedBox(height: 8),
Text(
_errorMessage!,
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
),
],
),
),
)
else if (_detectionResult != null)
Expanded(child: _buildResultCard())
else
const Expanded(
child: Center(
child: Text(
'Tap a button above to detect device type',
style: TextStyle(fontSize: 16, color: Colors.grey),
),
),
),
],
),
),
);
}
Widget _buildResultCard() {
final result = _detectionResult!;
final deviceType =
result.isIFP ? 'Interactive Flat Panel (IFP)' : 'Regular Tablet';
final statusColor = result.isIFP ? Colors.orange : Colors.green;
final statusIcon = result.isIFP ? Icons.tv : Icons.tablet_android;
return Card(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(statusIcon, color: statusColor, size: 32),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Detection Result',
style: TextStyle(fontSize: 14, color: Colors.grey),
),
Text(
deviceType,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: statusColor,
),
),
],
),
),
],
),
const SizedBox(height: 16),
Container(
width: double.infinity,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: statusColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: statusColor.withValues(alpha: 0.3)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Confidence: ${result.confidenceLevel} (${(result.confidenceScore * 100).toStringAsFixed(1)}%)',
style: TextStyle(
fontWeight: FontWeight.bold,
color: statusColor,
),
),
const SizedBox(height: 8),
LinearProgressIndicator(
value: result.confidenceScore,
backgroundColor: Colors.grey.withValues(alpha: 0.2),
valueColor: AlwaysStoppedAnimation<Color>(statusColor),
),
],
),
),
const SizedBox(height: 16),
const Text(
'Details:',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
_buildDetailRow(
'Screen Size',
'${result.screenInches.toStringAsFixed(2)}" (${result.screenBucket})',
),
_buildDetailRow(
'Known IFP Brand',
result.matchedKnownIFPBrand ? 'Yes' : 'No',
),
_buildDetailRow('HDMI CEC', result.hasHdmiCec ? 'Yes' : 'No'),
_buildDetailRow('Leanback UI', result.hasLeanback ? 'Yes' : 'No'),
_buildDetailRow('Stylus Support', result.hasStylus ? 'Yes' : 'No'),
_buildDetailRow(
'Screen Size Reliable',
result.screenSizeReliable ? 'Yes' : 'No',
),
],
),
),
);
}
Widget _buildDetailRow(String label, String value) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label, style: const TextStyle(color: Colors.grey)),
Text(value, style: const TextStyle(fontWeight: FontWeight.w500)),
],
),
);
}
}