truthinscanner 0.0.4-dev1
truthinscanner: ^0.0.4-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();
// Initialize TruthInScanner with your API key
// This must be called before using any scanner functionality
TruthInScanner.initialize(
apiKey: 'xxxxxxx', // Replace with your API key
);
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 MyHomePage(title: 'Truthin Scanner'),
);
}
}
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),
// Button 1: Scan Barcode
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,
),
),
),
],
),
),
),
);
}
}