mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 22:48:55 +03:30
580 lines
28 KiB
Dart
Executable File
580 lines
28 KiB
Dart
Executable File
// import 'package:cssd/providers/test_result.dart';
|
|
import 'package:cssd/config/colors.dart';
|
|
import 'package:cssd/providers/auth.dart';
|
|
import 'package:cssd/providers/test_results.dart';
|
|
import 'package:cssd/widgets/Global/internet_error.dart';
|
|
import 'package:cssd/widgets/TestResultScreens/Main/filter_chip_box.dart';
|
|
import 'package:cssd/widgets/TestResultScreens/Main/floating_button.dart';
|
|
import 'package:cssd/widgets/TestResultScreens/Main/search_box.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../config/routes.dart';
|
|
import '../../models/test_result_models.dart';
|
|
import '../../providers/connectivity.dart';
|
|
|
|
class TestResultScreen extends StatefulWidget {
|
|
// static const route = '/TestResultScreen';
|
|
final bool? isAdmin;
|
|
|
|
TestResultScreen({this.isAdmin});
|
|
|
|
@override
|
|
_TestResultScreenState createState() => _TestResultScreenState();
|
|
}
|
|
|
|
class _TestResultScreenState extends State<TestResultScreen> {
|
|
TextEditingController searchCTRL = new TextEditingController();
|
|
ScrollController? sc;
|
|
|
|
bool _isInit = true;
|
|
|
|
// List<TestResult> _data = [];
|
|
|
|
@override
|
|
void initState() {
|
|
sc = new ScrollController();
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
if (_isInit) {
|
|
var testResults =
|
|
Provider.of<TestResultsProvider>(context, listen: false);
|
|
// testResults.resetFilters();
|
|
testResults.setLoading();
|
|
testResults.resetPageNumber();
|
|
testResults.getTestResults().then((_) {
|
|
testResults.resetLoading();
|
|
sc!.addListener(() {
|
|
if (sc!.position.pixels == sc!.position.maxScrollExtent &&
|
|
searchCTRL.text == '') {
|
|
var labelProviderObject =
|
|
Provider.of<TestResultsProvider>(context, listen: false);
|
|
labelProviderObject.getTestResults();
|
|
}
|
|
});
|
|
|
|
// setState(() {
|
|
// _isLoading = false;
|
|
// });
|
|
});
|
|
_isInit = false;
|
|
}
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@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 SafeArea(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
},
|
|
child: Scaffold(
|
|
floatingActionButton:
|
|
TestResultFloatingButton(deviceBlockSize: _deviceBlockSize),
|
|
appBar: AppBar(
|
|
titleSpacing: -10,
|
|
title: Text(
|
|
'Home',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
backgroundColor: Colors.black,
|
|
leading: IconButton(
|
|
icon: Icon(
|
|
Icons.keyboard_arrow_left,
|
|
color: Colors.white,
|
|
size: 35,
|
|
),
|
|
onPressed: () => Navigator.of(context).pushNamed(Routes.homePage),
|
|
),
|
|
),
|
|
body: Consumer<ConnectivityProvider>(
|
|
builder: (ct, connection, _) {
|
|
return connection.conStatus != 'offline'
|
|
? Padding(
|
|
padding: EdgeInsets.only(
|
|
top: 20, left: 20, right: 20, bottom: 60),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Row(
|
|
// crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: <Widget>[
|
|
Container(
|
|
// padding: EdgeInsets.only(top: 20, bottom: 40),
|
|
child: Text(
|
|
'My Test Results',
|
|
// textAlign: TextAlign.left,
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 6 * _deviceBlockSize,
|
|
fontWeight: FontWeight.w700,
|
|
letterSpacing: 2,
|
|
),
|
|
),
|
|
),
|
|
Spacer(),
|
|
InkWell(
|
|
onTap: () {
|
|
Navigator.of(context)
|
|
.pushNamed(Routes.testFilterScreen);
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.all(7),
|
|
child: Icon(
|
|
FontAwesomeIcons.filter,
|
|
size: 7 * _deviceBlockSize,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Consumer<TestResultsProvider>(
|
|
builder: (context, testResult, _) {
|
|
return Container(
|
|
height: 50,
|
|
child: ListView(
|
|
scrollDirection: Axis.horizontal,
|
|
shrinkWrap: true,
|
|
children: <Widget>[
|
|
testResult.filters.id != ''
|
|
? TestResultChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'ID',
|
|
id: '',
|
|
labelID: testResult.filters.labelID,
|
|
testType:
|
|
testResult.filters.testType,
|
|
hospital:
|
|
testResult.filters.hospital,
|
|
username:
|
|
testResult.filters.userName,
|
|
fDate: testResult.filters.fDate,
|
|
uDate: testResult.filters.uDate,
|
|
)
|
|
: Container(),
|
|
testResult.filters.labelID != ''
|
|
? TestResultChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Label ID',
|
|
id: testResult.filters.id,
|
|
labelID: '',
|
|
testType:
|
|
testResult.filters.testType,
|
|
hospital:
|
|
testResult.filters.hospital,
|
|
username:
|
|
testResult.filters.userName,
|
|
fDate: testResult.filters.fDate,
|
|
uDate: testResult.filters.uDate,
|
|
)
|
|
: Container(),
|
|
testResult.filters.testType != ''
|
|
? TestResultChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Test Type',
|
|
id: testResult.filters.id,
|
|
labelID: testResult.filters.labelID,
|
|
testType: '',
|
|
hospital:
|
|
testResult.filters.hospital,
|
|
username:
|
|
testResult.filters.userName,
|
|
fDate: testResult.filters.fDate,
|
|
uDate: testResult.filters.uDate,
|
|
)
|
|
: Container(),
|
|
testResult.filters.hospital != ''
|
|
? TestResultChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Hospital',
|
|
id: testResult.filters.id,
|
|
labelID: testResult.filters.labelID,
|
|
testType:
|
|
testResult.filters.testType,
|
|
hospital: '',
|
|
username:
|
|
testResult.filters.userName,
|
|
fDate: testResult.filters.fDate,
|
|
uDate: testResult.filters.uDate,
|
|
)
|
|
: Container(),
|
|
testResult.filters.userName != ''
|
|
? TestResultChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Username',
|
|
id: testResult.filters.id,
|
|
labelID: testResult.filters.labelID,
|
|
testType:
|
|
testResult.filters.testType,
|
|
hospital:
|
|
testResult.filters.hospital,
|
|
username: '',
|
|
fDate: testResult.filters.fDate,
|
|
uDate: testResult.filters.uDate,
|
|
)
|
|
: Container(),
|
|
testResult.filters.fDate != ''
|
|
? TestResultChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'From Date',
|
|
id: testResult.filters.id,
|
|
labelID: testResult.filters.labelID,
|
|
testType:
|
|
testResult.filters.testType,
|
|
hospital:
|
|
testResult.filters.hospital,
|
|
username:
|
|
testResult.filters.userName,
|
|
fDate: '',
|
|
uDate: testResult.filters.uDate,
|
|
)
|
|
: Container(),
|
|
testResult.filters.uDate != ''
|
|
? TestResultChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Until Date',
|
|
id: testResult.filters.id,
|
|
labelID: testResult.filters.labelID,
|
|
testType:
|
|
testResult.filters.testType,
|
|
hospital:
|
|
testResult.filters.hospital,
|
|
username:
|
|
testResult.filters.userName,
|
|
fDate: testResult.filters.fDate,
|
|
uDate: '',
|
|
)
|
|
: Container(),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
TestResultSearchBox(
|
|
searchCTRL: searchCTRL,
|
|
deviceBlockSize: _deviceBlockSize,
|
|
),
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
Expanded(
|
|
child: Consumer<TestResultsProvider>(
|
|
builder: (context, testResults, _) {
|
|
return testResults.isloading
|
|
? Center(
|
|
child: CircularProgressIndicator(
|
|
color: Colors.black,
|
|
),
|
|
)
|
|
: testResults.items?.length != 0
|
|
? ListView.builder(
|
|
controller: sc,
|
|
itemBuilder: (context, index) =>
|
|
TestItemBox(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
item: testResults.items![index],
|
|
),
|
|
itemCount:
|
|
testResults.items?.length,
|
|
shrinkWrap: true,
|
|
)
|
|
: Container(
|
|
child: Center(
|
|
child: Text(
|
|
"There is no item to show."),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: ConnectionErrorBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class TestItemBox extends StatelessWidget {
|
|
final TestResultObject? item;
|
|
|
|
const TestItemBox({
|
|
Key? key,
|
|
required double deviceBlockSize,
|
|
required this.item,
|
|
}) : _deviceBlockSize = deviceBlockSize,
|
|
super(key: key);
|
|
|
|
final double _deviceBlockSize;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// print(item.result);
|
|
final userData = Provider.of<Auth>(context, listen: false).user;
|
|
return GestureDetector(
|
|
onTap: () => Navigator.of(context).pushNamed(
|
|
Routes.testDetailsScreen,
|
|
arguments: item!.id,
|
|
),
|
|
child: Card(
|
|
child: Container(
|
|
padding: EdgeInsets.all(8),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Container(
|
|
width: 57 * _deviceBlockSize,
|
|
child: Text(
|
|
item!.name,
|
|
overflow: TextOverflow.ellipsis,
|
|
// style: TextStyle(fontSize: 20),
|
|
),
|
|
),
|
|
Container(
|
|
width: 57 * _deviceBlockSize,
|
|
child: Text(
|
|
item!.hospital,
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontSize: 3 * _deviceBlockSize,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 15,
|
|
),
|
|
(item!.verified == 'NotVerified')
|
|
? Text(
|
|
'Rejected',
|
|
style: TextStyle(
|
|
color: kPink,
|
|
),
|
|
)
|
|
: (item!.verified == 'Verified')
|
|
? Text(
|
|
'Accepted',
|
|
style: TextStyle(
|
|
color: kLightBlue,
|
|
),
|
|
)
|
|
: Text(
|
|
'Pending..',
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
),
|
|
)
|
|
],
|
|
),
|
|
Spacer(),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: <Widget>[
|
|
Text(item!.date),
|
|
SizedBox(
|
|
height: 15,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: <Widget>[
|
|
(userData['roles']?.contains('User') &&
|
|
item!.verified == 'NotVerified' &&
|
|
item!.hospital
|
|
.contains(userData['medical_center']))
|
|
? InkWell(
|
|
customBorder: CircleBorder(),
|
|
onTap: () {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return AlertDialog(
|
|
title: Text('Delete'),
|
|
content: Text(
|
|
'Are you sure you want delete this Test?'),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
child: Text('Yes'),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
Provider.of<TestResultsProvider>(
|
|
context,
|
|
listen: false)
|
|
.removeTestResult(item!.id);
|
|
},
|
|
),
|
|
TextButton(
|
|
child: Text('No'),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.all(7),
|
|
width: 8 * _deviceBlockSize,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: kPink,
|
|
),
|
|
child: Icon(
|
|
Icons.delete_outlined,
|
|
size: 4 * _deviceBlockSize,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
)
|
|
: (userData['roles']?.contains('Supervisor') &&
|
|
item!.verified == 'NotVerified')
|
|
? InkWell(
|
|
customBorder: CircleBorder(),
|
|
onTap: () {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return AlertDialog(
|
|
title: Text('Delete'),
|
|
content: Text(
|
|
'Are you sure you want delete this Test?'),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
child: Text('Yes'),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
Provider.of<TestResultsProvider>(
|
|
context,
|
|
listen: false)
|
|
.removeTestResult(item!.id);
|
|
},
|
|
),
|
|
TextButton(
|
|
child: Text('No'),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.all(7),
|
|
width: 8 * _deviceBlockSize,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: kPink,
|
|
),
|
|
child: Icon(
|
|
Icons.delete_outlined,
|
|
size: 4 * _deviceBlockSize,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
)
|
|
: userData['roles']?.contains('Admin') ?? false
|
|
? InkWell(
|
|
customBorder: CircleBorder(),
|
|
onTap: () {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return AlertDialog(
|
|
title: Text('Delete'),
|
|
content: Text(
|
|
'Are you sure you want delete this Test?'),
|
|
actions: <Widget>[
|
|
TextButton(
|
|
child: Text('Yes'),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
Provider.of<TestResultsProvider>(
|
|
context,
|
|
listen: false)
|
|
.removeTestResult(
|
|
item!.id);
|
|
},
|
|
),
|
|
TextButton(
|
|
child: Text('No'),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.all(7),
|
|
width: 8 * _deviceBlockSize,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: kPink,
|
|
),
|
|
child: Icon(
|
|
Icons.delete_outlined,
|
|
size: 4 * _deviceBlockSize,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
)
|
|
: Container(),
|
|
SizedBox(
|
|
width: 7.5,
|
|
),
|
|
// InkWell(
|
|
// onTap: () {
|
|
// Navigator.of(context).pushNamed(
|
|
// Routes.testDetailsScreen,
|
|
// arguments: item!.id,
|
|
// );
|
|
// },
|
|
// child: Container(
|
|
// padding: EdgeInsets.all(7),
|
|
// width: 9 * _deviceBlockSize,
|
|
// decoration: BoxDecoration(
|
|
// shape: BoxShape.circle,
|
|
// color: Colors.black,
|
|
// ),
|
|
// child: Icon(
|
|
// FontAwesomeIcons.fileAlt,
|
|
// size: 5 * _deviceBlockSize,
|
|
// color: Colors.white,
|
|
// ),
|
|
// ),
|
|
// ),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|