Bajardi: jumanov ozodbek
Download 142.93 Kb.
|
AMALIY ISH-2
2-AMALIY ISH BAJARDI:JUMANOV OZODBEK MAVZU: QR KOD TASVIRI ORQALI MALUMOT OLISH JUMANOV OZODBEK, [01.12.2022 11:38] import 'dart:developer'; import 'dart:io'; import 'package:animated_text_kit/animated_text_kit.dart'; import 'package:flutter/material.dart'; import 'package:qr_code_scanner/qr_code_scanner.dart'; import 'package:url_launcher/url_launcher.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const HomePage(), ); } } class HomePage extends StatefulWidget { const HomePage({super.key}); @override State } class _HomePageState extends State final qrKey = GlobalKey(debugLabel: 'QR'); Barcode? result; late QRViewController? controller; bool? flashStatus = false; CameraFacing? _currentCameraFacing; bool? isVisible = false; @override
@override void didChangeAppLifecycleState(AppLifecycleState state) async { switch (state) { case AppLifecycleState.inactive: await controller!.pauseCamera(); log('INACTIVE'); break; case AppLifecycleState.paused: await controller!.pauseCamera(); log('PAUSED'); break; case AppLifecycleState.detached: await controller!.pauseCamera(); log('DETACHED'); break; case AppLifecycleState.resumed: await controller!.resumeCamera(); log('RESUMED'); break; } super.didChangeAppLifecycleState(state); } void goToUrl({String? url}) async { try { if (url!.startsWith('https://') || url.startsWith('http://')) { final bool urlLaunched = await launchUrl(Uri.tryParse(url)!); if (urlLaunched) { log('LAUNCH URL'); } } // Clipboard.setData(ClipboardData(text: url)); } catch (e) { log(e.toString()); } } void get changeCamera async { try { _currentCameraFacing = await controller!.flipCamera(); } catch (e) { log(e.toString()); } } @override void reassemble() { if (Platform.isAndroid) { controller!.pauseCamera(); } else { controller!.resumeCamera(); } super.reassemble(); } void _onQRViewCreated(QRViewController controller) { this.controller = controller; controller.resumeCamera(); debugPrint('CAMERA CREATED'); controller.scannedDataStream.listen((scanData) { setState(() { result = scanData; isVisible = true; }); log(result!.code!); }); } void get flashLigth async { try { await controller!.toggleFlash(); flashStatus = await controller!.getFlashStatus(); setState(() {}); } catch (e) { log(e.toString()); } } @override void dispose() { controller?.dispose(); WidgetsBinding.instance.removeObserver(this); controller!.stopCamera(); super.dispose(); } JUMANOV OZODBEK😎, [01.12.2022 11:38] @override Widget build(BuildContext context) { return Scaffold( body: Stack( fit: StackFit.expand, children: QRView( key: qrKey, onQRViewCreated: _onQRViewCreated, cameraFacing: _currentCameraFacing ?? CameraFacing.back, overlay: QrScannerOverlayShape( borderColor: Colors.blue, borderRadius: 10), ), AnimatedPositioned( duration: const Duration(milliseconds: 200), curve: Curves.easeIn, bottom: isVisible! ? 20 : -200, left: .0, right: .0, child: (result != null) ? _myAnimatedText(result!.code, onPress: () => goToUrl(url: result!.code)) : const Text('Scan a code'), ) ], ), floatingActionButtonLocation: FloatingActionButtonLocation.centerTop, floatingActionButton: Row( mainAxisSize: MainAxisSize.min, children: [ FloatingActionButton( heroTag: 'change', onPressed: () => changeCamera, child: const Icon(Icons.camera_front_sharp), ), const SizedBox( width: 20, ), FloatingActionButton( heroTag: 'flash', onPressed: () => flashLigth, child: const Icon(Icons.light), ) ], ), ); } Widget _myAnimatedText(String? text, {VoidCallback? onPress}) { const colors = [Colors.red, Colors.white]; return AnimatedTextKit(onTap: onPress, animatedTexts: [ ColorizeAnimatedText(text!, textAlign: TextAlign.center, textStyle: const TextStyle(fontSize: 30, fontWeight: FontWeight.w600), colors: colors) ]); } Download 142.93 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling