mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 20:28:54 +03:30
510 lines
20 KiB
Dart
Executable File
510 lines
20 KiB
Dart
Executable File
import 'package:barcode_scan2/platform_wrapper.dart';
|
|
import 'package:cssd/config/colors.dart';
|
|
import 'package:cssd/pages/ItemPages/item_result_screen.dart';
|
|
import 'package:cssd/pages/MyItemsPages/Result/my_items_result_screen.dart';
|
|
import 'package:cssd/pages/MyPackagesPages/Result/my_packages_result_screen.dart';
|
|
import 'package:cssd/pages/PackagePages/package_result_screen.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 'CyclePages/cycle_result_screen.dart';
|
|
import 'LabelPages/label_result_screen.dart';
|
|
import 'my_info_screen.dart';
|
|
import 'TestPages/test_result_screen.dart';
|
|
import 'TestPages/test_verify_screen.dart';
|
|
|
|
class HomePage extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final userData = Provider.of<Auth>(context, listen: false).user;
|
|
return SafeArea(
|
|
child: Scaffold(
|
|
drawer: Selector<ConnectivityProvider, String>(
|
|
builder: (ctx, value, _) =>
|
|
value != 'offline' ? AppDrawer() : Container(),
|
|
selector: (_, connectivity) => connectivity.conStatus,
|
|
),
|
|
appBar: AppBar(
|
|
centerTitle: true,
|
|
title: Text(
|
|
'CSSD',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
backgroundColor: Colors.black,
|
|
iconTheme: IconThemeData(color: Colors.white),
|
|
actions: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 10.0),
|
|
child: IconButton(
|
|
icon: Icon(
|
|
Icons.power_settings_new,
|
|
color: Colors.white,
|
|
),
|
|
onPressed: () {
|
|
showDialog(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: Text('LogOut'),
|
|
content: Text('Are you sure for logout?'),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
child: Text('Yes'),
|
|
onPressed: () {
|
|
Navigator.of(ctx).pop();
|
|
Provider.of<Auth>(context, listen: false).logout();
|
|
Phoenix.rebirth(context);
|
|
},
|
|
),
|
|
TextButton(
|
|
child: Text('No'),
|
|
onPressed: () {
|
|
Navigator.of(ctx).pop();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
)
|
|
],
|
|
),
|
|
body: Consumer<ConnectivityProvider>(
|
|
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: <Widget>[
|
|
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(
|
|
firstLine: 'MY INFO',
|
|
secondLine: 'Personal Details',
|
|
firstLineColor: Colors.black,
|
|
secondLineColor: Colors.grey,
|
|
backgroundColor: kLightGreyBackground,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return Consumer<Auth>(
|
|
builder: (ctx, auth, _) {
|
|
return MyInfoScreen();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
Divider(
|
|
height: 15,
|
|
),
|
|
SelectionItem(
|
|
firstLine: 'TEST RESULTS',
|
|
secondLine: 'List, Details & Add a one',
|
|
firstLineColor: Colors.black,
|
|
secondLineColor: Colors.grey,
|
|
backgroundColor: kLightGreyBackground,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return Consumer<Auth>(
|
|
builder: (ctx, auth, _) {
|
|
return TestResultScreen();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
if (!userData['roles'].contains('User'))
|
|
SelectionItem(
|
|
firstLine: 'TEST TO VERIFY',
|
|
secondLine: 'Verify and reject Test Results',
|
|
firstLineColor: Colors.black,
|
|
secondLineColor: Colors.grey,
|
|
backgroundColor: kLightGreyBackground,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return Consumer<Auth>(
|
|
builder: (ctx, auth, _) {
|
|
return TestVerifyScreen();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
Divider(
|
|
height: 15,
|
|
),
|
|
SelectionItem(
|
|
firstLine: 'ITEMS',
|
|
secondLine: 'List, Details & Add a one',
|
|
firstLineColor: kBlue,
|
|
secondLineColor: kBlueSub,
|
|
backgroundColor: kBlueBackground,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return Consumer<Auth>(
|
|
builder: (ctx, auth, _) {
|
|
return ItemResultScreen();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
SelectionItem(
|
|
firstLine: 'MY ITEMS',
|
|
secondLine: 'The Items that i possess',
|
|
firstLineColor: kDarkBlue,
|
|
secondLineColor: kDarkBlueSub,
|
|
backgroundColor: kDarkBlueBackground,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return Consumer<Auth>(
|
|
builder: (ctx, auth, _) {
|
|
return MyItemsResultScreen();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
Divider(
|
|
height: 15,
|
|
),
|
|
SelectionItem(
|
|
firstLine: 'PACKAGES',
|
|
secondLine: 'List, Details & Add a one',
|
|
firstLineColor: kPurple,
|
|
secondLineColor: kPurpleSub,
|
|
backgroundColor: kPurpleBackground,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return Consumer<Auth>(
|
|
builder: (ctx, auth, _) {
|
|
return PackageResultScreen();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
SelectionItem(
|
|
firstLine: 'MY PACKAGES',
|
|
secondLine: 'The Package that i possess',
|
|
firstLineColor: kDarkPurple,
|
|
secondLineColor: kDarkPurpleSub,
|
|
backgroundColor: kDarkPurpleBackground,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return Consumer<Auth>(
|
|
builder: (ctx, auth, _) {
|
|
return MyPackagesResultScreen();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
Divider(
|
|
height: 15,
|
|
),
|
|
SelectionItem(
|
|
firstLine: 'LABELS',
|
|
secondLine: 'List, Details & Add a one',
|
|
firstLineColor: kLightBlue,
|
|
secondLineColor: kLightBlueSub,
|
|
backgroundColor: kLightBlueBackground,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return Consumer<Auth>(
|
|
builder: (ctx, auth, _) {
|
|
return LabelResultScreen();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
SelectionItem(
|
|
firstLine: 'CYCLES',
|
|
secondLine: 'List, Details & Add a one',
|
|
firstLineColor: kPink,
|
|
secondLineColor: kPinkSub,
|
|
backgroundColor: kPinkBackground,
|
|
onTap: () => Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) {
|
|
return Consumer<Auth>(
|
|
builder: (ctx, auth, _) {
|
|
return CycleResultScreen();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
// Divider(height: 2),
|
|
SizedBox(
|
|
height: 5,
|
|
),
|
|
BarcodeSelectionItem(),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: ConnectionErrorBox();
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<String> 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 String? firstLine;
|
|
final String? secondLine;
|
|
final Color? firstLineColor;
|
|
final Color? secondLineColor;
|
|
final Color? backgroundColor;
|
|
final VoidCallback? onTap;
|
|
|
|
SelectionItem(
|
|
{this.firstLine,
|
|
this.secondLine,
|
|
this.onTap,
|
|
this.firstLineColor,
|
|
this.secondLineColor,
|
|
this.backgroundColor});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final _media = MediaQuery.of(context);
|
|
final double _devicewidth = _media.size.width;
|
|
final double _deviceBlockSize = _devicewidth / 100;
|
|
return Container(
|
|
margin: EdgeInsets.symmetric(vertical: 3),
|
|
padding: EdgeInsets.symmetric(vertical: 5),
|
|
decoration: BoxDecoration(
|
|
color: backgroundColor,
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(3),
|
|
),
|
|
),
|
|
child: InkWell(
|
|
splashColor: Colors.grey[350],
|
|
onTap: onTap,
|
|
child: ListTile(
|
|
title: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[
|
|
Text(
|
|
firstLine!,
|
|
style: TextStyle(
|
|
color: firstLineColor,
|
|
fontSize: 5 * _deviceBlockSize,
|
|
// letterSpacing: 3.5,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
Text(
|
|
secondLine!,
|
|
style: TextStyle(
|
|
color: firstLineColor,
|
|
fontSize: 3.5 * _deviceBlockSize,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
trailing: Icon(
|
|
Icons.arrow_forward_ios,
|
|
color: firstLineColor ?? 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: <Widget>[
|
|
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: <Widget>[
|
|
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,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|