This commit is contained in:
erfan
2021-01-06 11:57:21 +03:30
parent 20cc775bc1
commit 2c045f43f1
12 changed files with 302 additions and 119 deletions
+229 -29
View File
@@ -1,7 +1,10 @@
import 'package:barcode_scan/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 './my_info_screen.dart';
import '../providers/auth.dart';
@@ -19,7 +22,8 @@ class HomePage extends StatelessWidget {
// static const route = '/HomeScreen';
@override
Widget build(BuildContext context) {
final userData = Provider.of<Auth>(context,listen: false).user;
final userData = Provider.of<Auth>(context, listen: false).user;
// print(userData['roles']);
return Scaffold(
resizeToAvoidBottomPadding: false,
@@ -53,7 +57,7 @@ class HomePage extends StatelessWidget {
child: Text('Yes'),
onPressed: () {
Navigator.of(ctx).pop();
Provider.of<Auth>(context).logout();
Provider.of<Auth>(context, listen: false).logout();
Phoenix.rebirth(context);
},
),
@@ -106,35 +110,75 @@ class HomePage extends StatelessWidget {
endColor: Color(0xFFFFECD2),
firstLine: 'My INFO',
secondLine: 'List, Details & Add a one',
onTap: Consumer<Auth>(
builder: (ctx, auth, _) {
return MyInfoScreen();
},
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return Consumer<Auth>(
builder: (ctx, auth, _) {
return MyInfoScreen();
},
);
},
),
),
),
SelectionItem(
startColor: Color(0xFFD5F5FD),
endColor: Color(0xFFE9FFF7),
firstLine: 'TEST RESULTS',
secondLine: 'List, Details & Add a one',
onTap: TestResultScreen()
// MyTestResult(
// isAdmin: false,
// ),
startColor: Color(0xFFD5F5FD),
endColor: Color(0xFFE9FFF7),
firstLine: 'TEST RESULTS',
secondLine: 'List, Details & Add a one',
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return Consumer<Auth>(
builder: (ctx, auth, _) {
return TestResultScreen();
},
);
},
),
),
// MyTestResult(
// isAdmin: false,
// ),
),
SelectionItem(
startColor: Color(0xFFE2D2C4),
endColor: Color(0xFFFAF7F5),
firstLine: 'LABELS',
secondLine: 'List, Details & Add a one',
onTap: LabelResultScreen(),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return Consumer<Auth>(
builder: (ctx, auth, _) {
return LabelResultScreen();
},
);
},
),
),
),
SelectionItem(
startColor: Color(0xFFA7CCE1),
endColor: Color(0xFFECF7ED),
firstLine: 'CYCLES',
secondLine: 'List, Details & Add a one',
onTap: CycleResultScreen(),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return Consumer<Auth>(
builder: (ctx, auth, _) {
return CycleResultScreen();
},
);
},
),
),
),
// SelectionItem(
// startColor: Color(0xFFA7CCE1),
@@ -149,9 +193,21 @@ class HomePage extends StatelessWidget {
startColor: Color(0xFFA7CCE1),
endColor: Color(0xFFECF7ED),
firstLine: 'TEST TO VERIFY',
secondLine: 'List, Details & Add a one',
onTap: TestVerifyScreen(),
secondLine: 'Verify and reject Test Results',
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return Consumer<Auth>(
builder: (ctx, auth, _) {
return TestVerifyScreen();
},
);
},
),
),
),
BarcodeSelectionItem(),
],
),
),
@@ -163,12 +219,33 @@ class HomePage extends StatelessWidget {
}
}
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 Color startColor;
final Color endColor;
final String firstLine;
final String secondLine;
final Widget onTap;
final Function onTap;
SelectionItem(
{this.startColor,
@@ -196,16 +273,7 @@ class SelectionItem extends StatelessWidget {
),
child: InkWell(
splashColor: Colors.red,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return onTap;
},
),
);
},
onTap: onTap,
child: ListTile(
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -258,3 +326,135 @@ class SelectionItem extends StatelessWidget {
);
}
}
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,
child: 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>[
FlatButton(
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,
),
),
// Column(
// children: <Widget>[
// 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,
// ),
// ),
// ],
// ),
),
);
}
}