import 'package:barcode_scan2/platform_wrapper.dart'; import 'package:double_back_to_close_app/double_back_to_close_app.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_phoenix/flutter_phoenix.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; import '../providers/auth.dart'; import '../providers/connectivity.dart'; import '../widgets/Global/drawer.dart'; import '../widgets/Global/internet_error.dart'; import 'cycle_result_screen.dart'; import 'label_result_screen.dart'; import 'my_info_screen.dart'; import 'test_result_screen.dart'; import 'test_verify_screen.dart'; class HomePage extends StatelessWidget { // 09338736511 // static const route = '/HomeScreen'; @override Widget build(BuildContext context) { final userData = Provider.of(context, listen: false).user; // print(userData['roles']); return SafeArea( child: Scaffold( // resizeToAvoidBottomPadding: false, drawer: Selector( builder: (ctx, value, _) => value != 'offline' ? AppDrawer() : Container(), selector: (_, connctivity) => connctivity.conStatus, ) // Consumer(builder: (ct, connection, _) { // return connection.conStatus != 'offline' ? AppDrawer() : Container(); // }) , appBar: AppBar( centerTitle: true, title: Text('CSSD'), actions: [ Padding( padding: const EdgeInsets.only(right: 10.0), child: IconButton( icon: Icon( Icons.power_settings_new, ), onPressed: () { showDialog( context: context, builder: (ctx) => AlertDialog( title: Text('LogOut'), content: Text('Are you sure for logout?'), actions: [ TextButton( child: Text('Yes'), onPressed: () { Navigator.of(ctx).pop(); Provider.of(context, listen: false).logout(); Phoenix.rebirth(context); }, ), TextButton( child: Text('No'), onPressed: () { Navigator.of(ctx).pop(); }, ), ], ), ); }, ), ) ], ), body: Consumer( builder: (ct, connection, _) { return connection.conStatus != 'offline' ? DoubleBackToCloseApp( snackBar: SnackBar( duration: Duration(seconds: 2), backgroundColor: Colors.black, content: Text( 'Double tap for exit . . .', style: TextStyle(color: Colors.white), ), ), child: Container( margin: EdgeInsets.only( top: 0, bottom: 10, left: 20, right: 20), child: ListView( // crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( margin: EdgeInsets.only(top: 20, bottom: 10), child: Text( 'WELCOME HOME', style: TextStyle( color: Colors.black, fontSize: 20, letterSpacing: 3.5, fontWeight: FontWeight.w700, ), ), ), SelectionItem( startColor: Color(0xFFFCB8A2), endColor: Color(0xFFFFECD2), firstLine: 'My INFO', secondLine: 'List, Details & Add a one', onTap: () => Navigator.push( context, MaterialPageRoute( builder: (context) { return Consumer( builder: (ctx, auth, _) { return MyInfoScreen(); }, ); }, ), ), ), SelectionItem( startColor: Color(0xFFD5F5FD), endColor: Color(0xFFE9FFF7), firstLine: 'TEST RESULTS', secondLine: 'List, Details & Add a one', onTap: () => Navigator.push( context, MaterialPageRoute( builder: (context) { return Consumer( builder: (ctx, auth, _) { return TestResultScreen(); }, ); }, ), ), // MyTestResult( // isAdmin: false, // ), ), SelectionItem( startColor: Color(0xFFE2D2C4), endColor: Color(0xFFFAF7F5), firstLine: 'LABELS', secondLine: 'List, Details & Add a one', onTap: () => Navigator.push( context, MaterialPageRoute( builder: (context) { return Consumer( builder: (ctx, auth, _) { return LabelResultScreen(); }, ); }, ), ), ), SelectionItem( startColor: Color(0xFFA7CCE1), endColor: Color(0xFFECF7ED), firstLine: 'CYCLES', secondLine: 'List, Details & Add a one', onTap: () => Navigator.push( context, MaterialPageRoute( builder: (context) { return Consumer( builder: (ctx, auth, _) { return CycleResultScreen(); }, ); }, ), ), ), // SelectionItem( // startColor: Color(0xFFA7CCE1), // endColor: Color(0xFFECF7ED), // firstLine: 'image', // secondLine: 'image', // onTap: CaptureImage(), // ), userData['roles'].contains('User') ? Container() : SelectionItem( startColor: Color(0xFFA7CCE1), endColor: Color(0xFFECF7ED), firstLine: 'TEST TO VERIFY', secondLine: 'Verify and reject Test Results', onTap: () => Navigator.push( context, MaterialPageRoute( builder: (context) { return Consumer( builder: (ctx, auth, _) { return TestVerifyScreen(); }, ); }, ), ), ), BarcodeSelectionItem(), ], ), ), ) : ConnectionErrorBox(); }, ), ), ); } } Future scan() async { try { var barcode = await BarcodeScanner.scan(); if (barcode.type.name == 'Cancelled') { return 'cancel'; } else if (barcode.type.name == 'Failed') { return 'error'; } try { var id = barcode.rawContent; return id; } catch (_) { return 'null'; } } on PlatformException catch (_) { return 'access'; } catch (_) { return 'error'; } } class SelectionItem extends StatelessWidget { final Color startColor; final Color endColor; final String firstLine; final String secondLine; final Function onTap; SelectionItem( {this.startColor, this.endColor, this.firstLine, this.secondLine, this.onTap}); @override Widget build(BuildContext context) { final _media = MediaQuery.of(context); // final double _pixelRatio = (_media.size.height / _media.size.width * 7 / 5); final double _devicewidth = _media.size.width; final double _deviceBlockSize = _devicewidth / 100; return Container( margin: EdgeInsets.symmetric(vertical: 10), padding: EdgeInsets.symmetric(vertical: 5), decoration: BoxDecoration( gradient: LinearGradient( colors: [startColor, endColor], ), borderRadius: BorderRadius.all( Radius.circular(3), ), ), child: InkWell( splashColor: Colors.red, onTap: onTap, child: ListTile( title: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text( firstLine, style: TextStyle( color: Colors.black, fontSize: 5 * _deviceBlockSize, letterSpacing: 3.5, ), ), Text( secondLine, style: TextStyle( color: Colors.grey, fontSize: 3.5 * _deviceBlockSize, ), ), ], ), trailing: Icon( Icons.arrow_forward_ios, color: Colors.black, ), ), // Column( // children: [ // ListTile( // title: Text( // firstLine, // textAlign: TextAlign.start, // style: TextStyle(color: Colors.black), // ), // ), // ListTile( // title: Text( // secondLine, // style: TextStyle(color: Colors.black, fontSize: 20), // ), // trailing: Icon( // Icons.arrow_forward_ios, // color: Colors.black, // ), // ), // ], // ), ), ); } } class BarcodeSelectionItem extends StatelessWidget { @override Widget build(BuildContext context) { final _media = MediaQuery.of(context); // final double _pixelRatio = (_media.size.height / _media.size.width * 7 / 5); final double _devicewidth = _media.size.width; final double _deviceBlockSize = _devicewidth / 100; return Container( margin: EdgeInsets.symmetric(vertical: 10), padding: EdgeInsets.symmetric(vertical: 5), decoration: BoxDecoration( gradient: LinearGradient( colors: [Colors.black, Colors.black87], ), borderRadius: BorderRadius.all( Radius.circular(3), ), ), child: InkWell( splashColor: Colors.red, onTap: () => scan().then( (String result) { if (result == 'cancel') { print('cancel'); } else if (result == 'error') { print('error'); } else if (result == 'access') { print('access'); } else { print(result); showDialog( context: context, builder: (_) => AlertDialog( title: Text( 'نتیجه ی اسکن', textDirection: TextDirection.rtl, textAlign: TextAlign.right, style: TextStyle( fontSize: 2.75 * _deviceBlockSize, ), ), content: Text( result, textDirection: TextDirection.rtl, style: TextStyle( fontSize: 4 * _deviceBlockSize, ), ), actions: [ TextButton( onPressed: () async { await launch(result); Navigator.of(context).pop(); }, child: Text( 'بازکردن در مرورگر', style: TextStyle( fontFamily: 'montserrat', ), ), ) ], ), ); } }, ), child: ListTile( title: Row( children: [ Icon( Icons.qr_code_scanner, color: Colors.white, size: 8 * _deviceBlockSize, ), SizedBox( width: 2 * _deviceBlockSize, ), Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text( 'SCANNER', style: TextStyle( color: Colors.white, fontSize: 5 * _deviceBlockSize, letterSpacing: 3.5, ), ), Text( 'Scan a Bar or QR code', style: TextStyle( color: Colors.white, fontSize: 3.5 * _deviceBlockSize, ), ), ], ) ], ), trailing: Icon( Icons.arrow_forward_ios, color: Colors.white, ), ), // Column( // children: [ // ListTile( // title: Text( // firstLine, // textAlign: TextAlign.start, // style: TextStyle(color: Colors.black), // ), // ), // ListTile( // title: Text( // secondLine, // style: TextStyle(color: Colors.black, fontSize: 20), // ), // trailing: Icon( // Icons.arrow_forward_ios, // color: Colors.black, // ), // ), // ], // ), ), ); } }