mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 19:19:17 +03:30
345 lines
14 KiB
Dart
Executable File
345 lines
14 KiB
Dart
Executable File
import 'package:cssd/config/colors.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
import '../../config/routes.dart';
|
|
|
|
import '../../providers/auth.dart';
|
|
import '../../providers/connectivity.dart';
|
|
import '../../widgets/CycleScreens/Result/banner.dart';
|
|
import '../../widgets/CycleScreens/Result/data_box.dart';
|
|
import '../../widgets/CycleScreens/Result/filter_objects.dart';
|
|
import '../../widgets/CycleScreens/Result/search_box.dart';
|
|
import '../../widgets/Global/internet_error.dart';
|
|
|
|
import '../../providers/cycles.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class CycleResultScreen extends StatefulWidget {
|
|
// static const route = '/CycleResultScreen';
|
|
final bool? isAdmin;
|
|
|
|
CycleResultScreen({this.isAdmin});
|
|
|
|
@override
|
|
_CycleResultScreenState createState() => _CycleResultScreenState();
|
|
}
|
|
|
|
class _CycleResultScreenState extends State<CycleResultScreen> {
|
|
bool _isInit = true;
|
|
ScrollController? sc;
|
|
TextEditingController searchCTRL = new TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
sc = new ScrollController();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
if (_isInit) {
|
|
var testResults = Provider.of<CyclesProvider>(context);
|
|
testResults.setLoading();
|
|
testResults.resetPageNumber();
|
|
testResults.getCycleResults().then((_) {
|
|
testResults.resetLoading();
|
|
sc!.addListener(
|
|
() {
|
|
if (sc!.position.pixels == sc!.position.maxScrollExtent &&
|
|
searchCTRL.text == '') {
|
|
var testResults = Provider.of<CyclesProvider>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
testResults.getCycleResults();
|
|
}
|
|
},
|
|
);
|
|
});
|
|
}
|
|
_isInit = false;
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final _media = MediaQuery.of(context);
|
|
final double _devicewidth = _media.size.width;
|
|
final double _deviceBlockSize = _devicewidth / 100;
|
|
return SafeArea(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
},
|
|
child: Scaffold(
|
|
floatingActionButton: CycleResultFloatingButton(
|
|
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, right: 20, bottom: 60, left: 20),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
ResultBanner(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
text: 'Cycles',
|
|
push: Routes.cycleFilterScreen,
|
|
),
|
|
Consumer<CyclesProvider>(builder: (ctx, cycle, _) {
|
|
return Container(
|
|
height: 50,
|
|
child: ListView(
|
|
scrollDirection: Axis.horizontal,
|
|
shrinkWrap: true,
|
|
children: <Widget>[
|
|
cycle.filters!.id != ''
|
|
? CycleFilterChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'ID',
|
|
id: '',
|
|
cycleNumber:
|
|
cycle.filters!.cycleNumber,
|
|
sterilizerId:
|
|
cycle.filters!.sterilizerId,
|
|
hospital: cycle.filters!.hospital,
|
|
date: cycle.filters!.date,
|
|
)
|
|
: Container(),
|
|
cycle.filters!.cycleNumber != ''
|
|
? CycleFilterChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Cycle Number',
|
|
id: cycle.filters!.id,
|
|
cycleNumber: '',
|
|
sterilizerId:
|
|
cycle.filters!.sterilizerId,
|
|
hospital: cycle.filters!.hospital,
|
|
date: cycle.filters!.date,
|
|
)
|
|
: Container(),
|
|
cycle.filters!.sterilizerId != ''
|
|
? CycleFilterChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Sterilizer ID',
|
|
id: cycle.filters!.id,
|
|
cycleNumber:
|
|
cycle.filters!.cycleNumber,
|
|
sterilizerId: '',
|
|
hospital: cycle.filters!.hospital,
|
|
date: cycle.filters!.date,
|
|
)
|
|
: Container(),
|
|
cycle.filters!.hospital != ''
|
|
? CycleFilterChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Hospital',
|
|
id: cycle.filters!.id,
|
|
cycleNumber:
|
|
cycle.filters!.cycleNumber,
|
|
sterilizerId:
|
|
cycle.filters!.sterilizerId,
|
|
hospital: '',
|
|
date: cycle.filters!.date,
|
|
)
|
|
: Container(),
|
|
cycle.filters!.date != ''
|
|
? CycleFilterChip(
|
|
deviceBlockSize: _deviceBlockSize,
|
|
label: 'Date',
|
|
id: cycle.filters!.id,
|
|
cycleNumber:
|
|
cycle.filters!.cycleNumber,
|
|
sterilizerId:
|
|
cycle.filters!.sterilizerId,
|
|
hospital: cycle.filters!.hospital,
|
|
date: '',
|
|
)
|
|
: Container(),
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
ResultSearchBox(
|
|
searchCTRL: searchCTRL,
|
|
deviceBlockSize: _deviceBlockSize,
|
|
text: 'cycle',
|
|
onChanged: (value) {
|
|
Provider.of<CyclesProvider>(context,
|
|
listen: false)
|
|
.search(value);
|
|
},
|
|
),
|
|
SizedBox(
|
|
height: 20,
|
|
),
|
|
Expanded(
|
|
child: Consumer<CyclesProvider>(
|
|
builder: (context, cycleResults, _) {
|
|
return cycleResults.isloading
|
|
? Center(
|
|
child: CircularProgressIndicator(
|
|
color: Colors.black,
|
|
),
|
|
)
|
|
: cycleResults.items?.length != 0
|
|
? ListView.builder(
|
|
controller: sc,
|
|
itemBuilder: (context, index) {
|
|
String labels = '';
|
|
List<String> labelList;
|
|
labelList = cycleResults
|
|
.items![index].label.reversed
|
|
.toList();
|
|
for (var label in labelList) {
|
|
labels += label;
|
|
labels += ' , ';
|
|
}
|
|
if (labels.length >= 3) {
|
|
labels = labels.substring(
|
|
0,
|
|
labels.length -
|
|
3); // remove extra ,
|
|
}
|
|
return CycleItemBox(
|
|
deviceBlockSize:
|
|
_deviceBlockSize,
|
|
item:
|
|
cycleResults.items?[index],
|
|
labels: labels,
|
|
);
|
|
},
|
|
itemCount:
|
|
cycleResults.items?.length,
|
|
shrinkWrap: true,
|
|
)
|
|
: Container(
|
|
child: Center(
|
|
child: Text(
|
|
"There is no item to show."),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
: ConnectionErrorBox();
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class CycleResultFloatingButton extends StatelessWidget {
|
|
const CycleResultFloatingButton({
|
|
Key? key,
|
|
required double deviceBlockSize,
|
|
}) : _deviceBlockSize = deviceBlockSize,
|
|
super(key: key);
|
|
|
|
final double _deviceBlockSize;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final userData = Provider.of<Auth>(context, listen: false).user;
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: <Widget>[
|
|
// if (userData['roles'].contains('Supervisor') ||
|
|
// userData['roles'].contains('Admin'))
|
|
InkWell(
|
|
customBorder: CircleBorder(),
|
|
onTap: () async {
|
|
var status = await Permission.storage.request();
|
|
if (status.isGranted) {
|
|
Provider.of<CyclesProvider>(context, listen: false)
|
|
.exportCycles();
|
|
}
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.all(_deviceBlockSize),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Colors.black,
|
|
),
|
|
child: Icon(
|
|
Icons.import_export,
|
|
size: 10 * _deviceBlockSize,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 2 * _deviceBlockSize,
|
|
),
|
|
InkWell(
|
|
customBorder: CircleBorder(),
|
|
onTap: () {
|
|
Navigator.of(context).pushNamed(Routes.cycleScanScreen);
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.all(2.5 * _deviceBlockSize),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Colors.black,
|
|
),
|
|
child: Icon(
|
|
Icons.qr_code_scanner,
|
|
size: 7.1 * _deviceBlockSize,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 2 * _deviceBlockSize,
|
|
),
|
|
InkWell(
|
|
customBorder: CircleBorder(),
|
|
onTap: () {
|
|
Navigator.of(context).pushNamed(Routes.cycleAddScreen);
|
|
},
|
|
child: Container(
|
|
padding: EdgeInsets.all(_deviceBlockSize),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: kPink,
|
|
),
|
|
child: Icon(
|
|
Icons.add,
|
|
size: 10 * _deviceBlockSize,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|