truthinscanner 0.0.12-dev1
truthinscanner: ^0.0.12-dev1 copied to clipboard
A Flutter package for barcode scanning with TruthIn product database integration. Supports multiple barcode formats and provides real-time product information.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:truthinscanner/truthinscanner.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(
const MyApp(),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Truthin Scanner',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const InitializeScreen(),
);
}
}
class InitializeScreen extends StatefulWidget {
const InitializeScreen({super.key});
@override
State<InitializeScreen> createState() => _InitializeScreenState();
}
class _InitializeScreenState extends State<InitializeScreen> {
final _apiKeyController = TextEditingController(
text: 'api key get it from truthin',
);
final _userIdentityController = TextEditingController(
text: 'user@example.com',
);
final _baseUrlController = TextEditingController(
text: 'http://xxxxxxxxx:xxx/nfapi/',
);
@override
void dispose() {
_apiKeyController.dispose();
_userIdentityController.dispose();
_baseUrlController.dispose();
super.dispose();
}
void _initialize() {
final apiKey = _apiKeyController.text.trim();
final userIdentity = _userIdentityController.text.trim();
final baseUrl = _baseUrlController.text.trim();
if (apiKey.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('API Key is required')),
);
return;
}
TruthInScanner.initialize(
apiKey: apiKey,
userIdentity: userIdentity.isNotEmpty ? userIdentity : null,
baseUrl: baseUrl,
);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const MyHomePage(title: 'Truthin Scanner'),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('Configure Scanner'),
centerTitle: true,
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(24.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Icon(
Icons.settings,
size: 80,
color: Colors.blue,
),
const SizedBox(height: 24),
const Text(
'Setup Configuration',
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
const SizedBox(height: 32),
TextField(
controller: _apiKeyController,
decoration: InputDecoration(
labelText: 'API Key *',
hintText: 'Enter your API key',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
prefixIcon: const Icon(Icons.key),
),
),
const SizedBox(height: 16),
TextField(
controller: _userIdentityController,
decoration: InputDecoration(
labelText: 'User Identity',
hintText: 'e.g. user@example.com',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
prefixIcon: const Icon(Icons.person),
),
keyboardType: TextInputType.emailAddress,
),
const SizedBox(height: 16),
TextField(
controller: _baseUrlController,
decoration: InputDecoration(
labelText: 'Base URL',
hintText: 'Enter base URL',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
prefixIcon: const Icon(Icons.link),
),
keyboardType: TextInputType.url,
),
const SizedBox(height: 32),
SizedBox(
height: 56,
child: ElevatedButton.icon(
onPressed: _initialize,
icon: const Icon(Icons.check_circle, size: 24),
label: const Text(
'Initialize & Continue',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
elevation: 2,
),
),
),
],
),
),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key, required this.title});
final String title;
void _navigateToScanner(BuildContext context) {
Navigator.of(context).push(
MaterialPageRoute(builder: (context) => const BarcodeScannerView()),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(title),
centerTitle: true,
),
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 40.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.qr_code_scanner,
size: 100,
color: Colors.blue,
),
const SizedBox(height: 40),
const Text(
'Welcome to Truthin Scanner',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 60),
SizedBox(
width: double.infinity,
height: 56,
child: ElevatedButton.icon(
onPressed: () => _navigateToScanner(context),
icon: const Icon(Icons.qr_code_scanner, size: 24),
label: const Text(
'Scan Barcode',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
elevation: 2,
),
),
),
],
),
),
),
);
}
}