mirror of
https://git.meshkee.com/applications/cssd.git
synced 2026-10-10 19:28:56 +03:30
bog fix
This commit is contained in:
+1
-2
@@ -66,7 +66,6 @@ import 'providers/labels.dart';
|
||||
import 'providers/my_info.dart';
|
||||
import 'providers/test_results.dart';
|
||||
import 'widgets/Global/splash_screen.dart';
|
||||
import 'widgets/TestResultScreens/Add/capture_image.dart';
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -165,7 +164,7 @@ class MyApp extends StatelessWidget {
|
||||
Routes.testScanScreen: (ctx) => TestScanScreen(),
|
||||
Routes.sendCodeScreen: (ctx) => VerifyPassScreen(),
|
||||
Routes.rePassScreen: (ctx) => RePassScreen(),
|
||||
Routes.captureImageScreen: (ctx) => CaptureImage(),
|
||||
// Routes.captureImageScreen: (ctx) => CaptureImage(),
|
||||
Routes.packageAddScreen: (ctx) => PackageAddScreen(),
|
||||
Routes.packageResultScreen: (ctx) => PackageResultScreen(),
|
||||
Routes.packageDetailScreen: (ctx) => PackageDetailScreen(),
|
||||
|
||||
@@ -9,6 +9,7 @@ class ItemResultObject extends Equatable {
|
||||
final int status;
|
||||
final String? batchId;
|
||||
final String? udi;
|
||||
final String? udi_name;
|
||||
|
||||
ItemResultObject({
|
||||
required this.id,
|
||||
@@ -18,6 +19,7 @@ class ItemResultObject extends Equatable {
|
||||
required this.status,
|
||||
this.batchId,
|
||||
this.udi,
|
||||
this.udi_name,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -29,6 +31,7 @@ class ItemResultObject extends Equatable {
|
||||
status,
|
||||
batchId!,
|
||||
udi!,
|
||||
udi_name!,
|
||||
];
|
||||
|
||||
@override
|
||||
|
||||
@@ -5,6 +5,7 @@ class MyItemResultObject extends Equatable {
|
||||
final String id;
|
||||
final String name;
|
||||
final String size;
|
||||
final String? udi;
|
||||
final String? userName;
|
||||
final String? requestId;
|
||||
|
||||
@@ -14,6 +15,7 @@ class MyItemResultObject extends Equatable {
|
||||
required this.size,
|
||||
this.userName,
|
||||
this.requestId,
|
||||
this.udi,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -23,6 +25,7 @@ class MyItemResultObject extends Equatable {
|
||||
size,
|
||||
userName!,
|
||||
requestId!,
|
||||
udi!,
|
||||
];
|
||||
|
||||
@override
|
||||
|
||||
@@ -324,6 +324,7 @@ class _ItemAddScreenState extends State<ItemAddScreen> {
|
||||
batchId: batchId,
|
||||
dateValue: dateCTRL.text,
|
||||
deviceBlockSize: _deviceBlockSize,
|
||||
isLoading: isInit,
|
||||
),
|
||||
SizedBox(
|
||||
height: 100,
|
||||
|
||||
@@ -118,7 +118,7 @@ class ItemProvider extends ChangeNotifier {
|
||||
return 'Added';
|
||||
}
|
||||
|
||||
Future<void> createItemResult(
|
||||
Future<String> createItemResult(
|
||||
name,
|
||||
size,
|
||||
specific,
|
||||
@@ -149,6 +149,12 @@ class ItemProvider extends ChangeNotifier {
|
||||
"Accept": "application/json"
|
||||
});
|
||||
print(response.body);
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
catchImages = [];
|
||||
return 'done';
|
||||
} else {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateItemResult(
|
||||
@@ -281,6 +287,7 @@ class ItemProvider extends ChangeNotifier {
|
||||
size: item['size'].toString(),
|
||||
userName: item['user'] != null ? item['user']['name'] : '',
|
||||
status: item['status'],
|
||||
udi: item['udi'],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,6 +126,7 @@ class MyItemProvider extends ChangeNotifier {
|
||||
name: item['name'],
|
||||
id: item['id'].toString(),
|
||||
size: item['size'].toString(),
|
||||
udi: item['udi'],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -170,6 +171,7 @@ class MyItemProvider extends ChangeNotifier {
|
||||
id: item['id'].toString(),
|
||||
size: item['size'].toString(),
|
||||
userName: item['user'] != null ? item['user']['name'] : '',
|
||||
udi: item['udi'],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
+11
-10
@@ -41,7 +41,11 @@ class PackageProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
changeItemVal(String value, int index) {
|
||||
itemValues[index].text = value;
|
||||
for (var item in filteredItems!) {
|
||||
if (item.udi_name == value) {
|
||||
itemValues[index].text = item.id;
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -104,18 +108,12 @@ class PackageProvider extends ChangeNotifier {
|
||||
'Authorization': User.token,
|
||||
},
|
||||
);
|
||||
// List<Map<String, dynamic>> result = [];
|
||||
List<String> result = [];
|
||||
filteredItems = [];
|
||||
var filterData = json.decode(response.body);
|
||||
for (var item in filterData['data']) {
|
||||
// result.add("${item['name']} - ${item['udi'] != null ? item['udi'] : ''}");
|
||||
result.add(item['id'].toString());
|
||||
// result.add({
|
||||
// 'name-udi':
|
||||
// "${item['name']} - ${item['udi'] != null ? item['udi'] : ''}",
|
||||
// 'id': item['id'].toString()
|
||||
// });
|
||||
result.add("${item['name']} - ${item['udi'] != null ? item['udi'] : ''}");
|
||||
// result.add(item['id'].toString());
|
||||
filteredItems!.add(
|
||||
ItemResultObject(
|
||||
name: item['name'],
|
||||
@@ -124,6 +122,8 @@ class PackageProvider extends ChangeNotifier {
|
||||
userName: item['user'] != null ? item['user']['name'] : '',
|
||||
status: item['status'],
|
||||
udi: item['udi'] != null ? item['udi'] : '',
|
||||
udi_name:
|
||||
"${item['name']} - ${item['udi'] != null ? item['udi'] : ''}",
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -312,7 +312,8 @@ class PackageProvider extends ChangeNotifier {
|
||||
var data = json.decode(response.body)['data'];
|
||||
List<String> itemsList = [];
|
||||
for (var item in data['items']) {
|
||||
itemsList.add(item['id'].toString());
|
||||
itemsList
|
||||
.add("${item['name']} - ${item['udi'] != null ? item['udi'] : ''}");
|
||||
}
|
||||
print(data);
|
||||
result = PackageDetailObject(
|
||||
|
||||
@@ -37,19 +37,19 @@ class CycleItemBox extends StatelessWidget {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: Text(
|
||||
item!.id,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 5 * _deviceBlockSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 3 * _deviceBlockSize,
|
||||
),
|
||||
// Container(
|
||||
// padding: const EdgeInsets.all(6),
|
||||
// child: Text(
|
||||
// item!.id,
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.w700,
|
||||
// fontSize: 5 * _deviceBlockSize,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// SizedBox(
|
||||
// width: 3 * _deviceBlockSize,
|
||||
// ),
|
||||
// Spacer(),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -34,21 +34,27 @@ class _AppDrawerState extends State<AppDrawer> {
|
||||
color: Colors.black,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: kLightBlue,
|
||||
child: Icon(
|
||||
Icons.person,
|
||||
color: Colors.white,
|
||||
),
|
||||
Text(
|
||||
'WELCOME',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
title: Text(
|
||||
user?['name'] != null ? user!['name'] : '',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
SizedBox(
|
||||
height: 5.0,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
user?['name'] != null ? user!['name'] : '',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Divider(
|
||||
color: Colors.white,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// ignore_for_file: must_be_immutable
|
||||
|
||||
import 'package:cssd/config/colors.dart';
|
||||
import 'package:cssd/providers/items.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -5,8 +7,8 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../config/routes.dart';
|
||||
|
||||
class ItemAddSaveButton extends StatelessWidget {
|
||||
const ItemAddSaveButton({
|
||||
class ItemAddSaveButton extends StatefulWidget {
|
||||
ItemAddSaveButton({
|
||||
Key? key,
|
||||
required GlobalKey<FormState> form,
|
||||
this.batchId,
|
||||
@@ -17,6 +19,7 @@ class ItemAddSaveButton extends StatelessWidget {
|
||||
required this.sizeCTRL,
|
||||
required this.specificCTRL,
|
||||
required this.dateValue,
|
||||
required this.isLoading,
|
||||
}) : _form = form,
|
||||
_deviceBlockSize = deviceBlockSize,
|
||||
super(key: key);
|
||||
@@ -30,21 +33,55 @@ class ItemAddSaveButton extends StatelessWidget {
|
||||
final String dateValue;
|
||||
final String? batchId;
|
||||
final double _deviceBlockSize;
|
||||
bool isLoading;
|
||||
|
||||
@override
|
||||
State<ItemAddSaveButton> createState() => _ItemAddSaveButtonState();
|
||||
}
|
||||
|
||||
class _ItemAddSaveButtonState extends State<ItemAddSaveButton> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
if (!_form.currentState!.validate()) {
|
||||
if (!widget._form.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
Provider.of<ItemProvider>(context, listen: false).createItemResult(
|
||||
nameCTRL.text,
|
||||
sizeCTRL.text,
|
||||
specificCTRL.text,
|
||||
udiCTRL.text,
|
||||
descriptionCTRL.text,
|
||||
batchId,
|
||||
setState(() {
|
||||
widget.isLoading = true;
|
||||
});
|
||||
Provider.of<ItemProvider>(context, listen: false)
|
||||
.createItemResult(
|
||||
widget.nameCTRL.text,
|
||||
widget.sizeCTRL.text,
|
||||
widget.specificCTRL.text,
|
||||
widget.udiCTRL.text,
|
||||
widget.descriptionCTRL.text,
|
||||
widget.batchId,
|
||||
)
|
||||
.then(
|
||||
(result) {
|
||||
setState(() {
|
||||
widget.isLoading = false;
|
||||
});
|
||||
if (result == 'done') {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
content: Text('Item added.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
},
|
||||
child: Text('Ok'),
|
||||
)
|
||||
],
|
||||
),
|
||||
).then((value) => Navigator.of(context)
|
||||
.popAndPushNamed(Routes.testResultScreen));
|
||||
}
|
||||
},
|
||||
);
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -65,7 +102,7 @@ class ItemAddSaveButton extends StatelessWidget {
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 5 * _deviceBlockSize,
|
||||
horizontal: 5 * widget._deviceBlockSize,
|
||||
vertical: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
@@ -80,7 +117,7 @@ class ItemAddSaveButton extends StatelessWidget {
|
||||
'Save',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 5 * _deviceBlockSize,
|
||||
fontSize: 5 * widget._deviceBlockSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -108,7 +108,7 @@ class _UploaderImageState extends State<UploaderImage> {
|
||||
|
||||
Future<void> loadAssetsFromCamera(BuildContext context) async {
|
||||
var providerObject = Provider.of<ItemProvider>(context, listen: false);
|
||||
List<PlatformFile> _catchImages = [];
|
||||
List<PlatformFile> _catchImages = providerObject.catchImages;
|
||||
var image = await ImagePicker.platform.pickImage(
|
||||
source: ImageSource.camera,
|
||||
);
|
||||
|
||||
@@ -35,19 +35,21 @@ class ItemItemBox extends StatelessWidget {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Text(
|
||||
item!.id,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 5 * _deviceBlockSize,
|
||||
if (item!.udi != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Text(
|
||||
item!.udi!,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 3 * _deviceBlockSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 3 * _deviceBlockSize,
|
||||
),
|
||||
if (item!.udi != null)
|
||||
SizedBox(
|
||||
width: 3 * _deviceBlockSize,
|
||||
),
|
||||
// Spacer(),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -33,19 +33,19 @@ class LabelItemBox extends StatelessWidget {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: Text(
|
||||
item!.id,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 5 * _deviceBlockSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 3 * _deviceBlockSize,
|
||||
),
|
||||
// Container(
|
||||
// padding: const EdgeInsets.all(6),
|
||||
// child: Text(
|
||||
// item!.id,
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.w700,
|
||||
// fontSize: 5 * _deviceBlockSize,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// SizedBox(
|
||||
// width: 3 * _deviceBlockSize,
|
||||
// ),
|
||||
// Spacer(),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -65,6 +65,10 @@ class LabelItemBox extends StatelessWidget {
|
||||
child: Text(
|
||||
item!.package,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 3 * _deviceBlockSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
|
||||
@@ -37,19 +37,21 @@ class MyItemsItemDataBox extends StatelessWidget {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Text(
|
||||
items!.id,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 5 * _deviceBlockSize,
|
||||
if (items!.udi != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Text(
|
||||
items!.udi!,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 3 * _deviceBlockSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 3 * _deviceBlockSize,
|
||||
),
|
||||
if (items!.udi != null)
|
||||
SizedBox(
|
||||
width: 3 * _deviceBlockSize,
|
||||
),
|
||||
// Spacer(),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -38,19 +38,19 @@ class MyPackagesItemDataBox extends StatelessWidget {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Text(
|
||||
packages!.id,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 5 * _deviceBlockSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 3 * _deviceBlockSize,
|
||||
),
|
||||
// Container(
|
||||
// padding: const EdgeInsets.all(6.0),
|
||||
// child: Text(
|
||||
// packages!.id,
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.w700,
|
||||
// fontSize: 5 * _deviceBlockSize,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// SizedBox(
|
||||
// width: 3 * _deviceBlockSize,
|
||||
// ),
|
||||
// Spacer(),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -235,7 +235,7 @@ class PackageDetailsDataBox extends StatelessWidget {
|
||||
shrinkWrap: true,
|
||||
itemBuilder: (ctx, index) => RichText(
|
||||
text: TextSpan(
|
||||
text: 'Item ID ',
|
||||
text: 'Item ',
|
||||
style: TextStyle(
|
||||
color: Colors.grey,
|
||||
fontFamily: 'montserrat',
|
||||
|
||||
@@ -35,19 +35,19 @@ class PackageItemBox extends StatelessWidget {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(6.0),
|
||||
child: Text(
|
||||
item!.id,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 5 * _deviceBlockSize,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 3 * _deviceBlockSize,
|
||||
),
|
||||
// Container(
|
||||
// padding: const EdgeInsets.all(6.0),
|
||||
// child: Text(
|
||||
// item!.id,
|
||||
// style: TextStyle(
|
||||
// fontWeight: FontWeight.w700,
|
||||
// fontSize: 5 * _deviceBlockSize,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// SizedBox(
|
||||
// width: 3 * _deviceBlockSize,
|
||||
// ),
|
||||
// Spacer(),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -1,328 +1,328 @@
|
||||
// ignore_for_file: dead_code
|
||||
// // ignore_for_file: dead_code
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
// import 'dart:async';
|
||||
// import 'dart:io';
|
||||
|
||||
import 'package:camera/camera.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
// import 'package:camera/camera.dart';
|
||||
// import 'package:file_picker/file_picker.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:path_provider/path_provider.dart';
|
||||
// import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../providers/test_results.dart';
|
||||
// import '../../../providers/test_results.dart';
|
||||
|
||||
class CaptureImage extends StatefulWidget {
|
||||
@override
|
||||
_CaptureImageState createState() {
|
||||
return _CaptureImageState();
|
||||
}
|
||||
}
|
||||
// class CaptureImage extends StatefulWidget {
|
||||
// @override
|
||||
// _CaptureImageState createState() {
|
||||
// return _CaptureImageState();
|
||||
// }
|
||||
// }
|
||||
|
||||
/// Returns a suitable camera icon for [direction].
|
||||
IconData getCameraLensIcon(CameraLensDirection direction) {
|
||||
switch (direction) {
|
||||
case CameraLensDirection.back:
|
||||
return Icons.camera_rear;
|
||||
case CameraLensDirection.front:
|
||||
return Icons.camera_front;
|
||||
case CameraLensDirection.external:
|
||||
return Icons.camera;
|
||||
}
|
||||
throw ArgumentError('Unknown lens direction');
|
||||
}
|
||||
// /// Returns a suitable camera icon for [direction].
|
||||
// IconData getCameraLensIcon(CameraLensDirection direction) {
|
||||
// switch (direction) {
|
||||
// case CameraLensDirection.back:
|
||||
// return Icons.camera_rear;
|
||||
// case CameraLensDirection.front:
|
||||
// return Icons.camera_front;
|
||||
// case CameraLensDirection.external:
|
||||
// return Icons.camera;
|
||||
// }
|
||||
// throw ArgumentError('Unknown lens direction');
|
||||
// }
|
||||
|
||||
void logError(String code, String message) =>
|
||||
print('Error: $code\nError Message: $message');
|
||||
// void logError(String code, String message) =>
|
||||
// print('Error: $code\nError Message: $message');
|
||||
|
||||
class _CaptureImageState extends State<CaptureImage>
|
||||
with WidgetsBindingObserver {
|
||||
CameraController? controller;
|
||||
String? imagePath;
|
||||
// String videoPath;
|
||||
VoidCallback? videoPlayerListener;
|
||||
bool isInit = true;
|
||||
int curCamera = 0;
|
||||
var cameras;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
}
|
||||
// class _CaptureImageState extends State<CaptureImage>
|
||||
// with WidgetsBindingObserver {
|
||||
// CameraController? controller;
|
||||
// String? imagePath;
|
||||
// // String videoPath;
|
||||
// VoidCallback? videoPlayerListener;
|
||||
// bool isInit = true;
|
||||
// int curCamera = 0;
|
||||
// var cameras;
|
||||
// @override
|
||||
// void initState() {
|
||||
// super.initState();
|
||||
// WidgetsBinding.instance.addObserver(this);
|
||||
// }
|
||||
|
||||
@override
|
||||
void didChangeDependencies() async {
|
||||
if (isInit) {
|
||||
cameras = await availableCameras();
|
||||
onNewCameraSelected(cameras[curCamera]);
|
||||
setState(() {
|
||||
isInit = false;
|
||||
});
|
||||
}
|
||||
super.didChangeDependencies();
|
||||
}
|
||||
// @override
|
||||
// void didChangeDependencies() async {
|
||||
// if (isInit) {
|
||||
// cameras = await availableCameras();
|
||||
// onNewCameraSelected(cameras[curCamera]);
|
||||
// setState(() {
|
||||
// isInit = false;
|
||||
// });
|
||||
// }
|
||||
// super.didChangeDependencies();
|
||||
// }
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
// @override
|
||||
// void dispose() {
|
||||
// WidgetsBinding.instance.removeObserver(this);
|
||||
// super.dispose();
|
||||
// }
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
// App state changed before we got the chance to initialize.
|
||||
if (controller == null || !controller!.value.isInitialized) {
|
||||
return;
|
||||
}
|
||||
if (state == AppLifecycleState.inactive) {
|
||||
controller?.dispose();
|
||||
} else if (state == AppLifecycleState.resumed) {
|
||||
if (controller != null) {
|
||||
onNewCameraSelected(controller!.description);
|
||||
}
|
||||
}
|
||||
}
|
||||
// @override
|
||||
// void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
// // App state changed before we got the chance to initialize.
|
||||
// if (controller == null || !controller!.value.isInitialized) {
|
||||
// return;
|
||||
// }
|
||||
// if (state == AppLifecycleState.inactive) {
|
||||
// controller?.dispose();
|
||||
// } else if (state == AppLifecycleState.resumed) {
|
||||
// if (controller != null) {
|
||||
// onNewCameraSelected(controller!.description);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
// final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
key: _scaffoldKey,
|
||||
// appBar: AppBar(
|
||||
// title: const Text('Take Picture'),
|
||||
// ),
|
||||
body: isInit
|
||||
? Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.black,
|
||||
),
|
||||
)
|
||||
: Stack(children: <Widget>[
|
||||
_cameraPreviewWidget(),
|
||||
Positioned(
|
||||
bottom: 100, left: 100, child: _captureControlRowWidget()),
|
||||
Positioned(
|
||||
bottom: 100,
|
||||
right: 100,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (curCamera == 0) {
|
||||
try {
|
||||
onNewCameraSelected(cameras[1]);
|
||||
setState(() {
|
||||
curCamera = 1;
|
||||
});
|
||||
} catch (e) {}
|
||||
} else {
|
||||
onNewCameraSelected(cameras[0]);
|
||||
setState(() {
|
||||
curCamera = 0;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Icon(
|
||||
curCamera == 0 ? Icons.camera_rear : Icons.camera_front,
|
||||
size: 40,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
// _cameraTogglesRowWidget(cameras),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Display the preview from the camera (or a message if the preview is not available).
|
||||
Widget _cameraPreviewWidget() {
|
||||
if (controller == null || !controller!.value.isInitialized) {
|
||||
return const Text(
|
||||
'Tap a camera',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 24.0,
|
||||
fontWeight: FontWeight.w900,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
child: CameraPreview(controller!),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Toggle recording audio
|
||||
|
||||
/// Display the control bar with buttons to take pictures and record videos.
|
||||
Widget _captureControlRowWidget() {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.camera_alt,
|
||||
size: 40,
|
||||
color: Colors.white,
|
||||
),
|
||||
// color: Colors.blue,
|
||||
onPressed: controller != null &&
|
||||
controller!.value.isInitialized &&
|
||||
!controller!.value.isRecordingVideo
|
||||
? onTakePictureButtonPressed
|
||||
: null,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
getCameras() async {
|
||||
return await availableCameras();
|
||||
}
|
||||
|
||||
/// Display a row of toggle to select the camera (or a message if no camera is available).
|
||||
// Widget _cameraTogglesRowWidget(var cameras) {
|
||||
// final List<Widget> toggles = <Widget>[];
|
||||
|
||||
// if (cameras.isEmpty) {
|
||||
// return const Text('No camera found');
|
||||
// } else {
|
||||
// for (CameraDescription cameraDescription in cameras) {
|
||||
// print("${cameraDescription.name}");
|
||||
// toggles.add(
|
||||
// SizedBox(
|
||||
// width: 90.0,
|
||||
// child: RadioListTile<CameraDescription>(
|
||||
// title: Icon(getCameraLensIcon(cameraDescription.lensDirection)),
|
||||
// groupValue: controller?.description,
|
||||
// value: cameraDescription,
|
||||
// onChanged: controller != null && controller.value.isRecordingVideo
|
||||
// ? null
|
||||
// : onNewCameraSelected,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// return Row(children: toggles);
|
||||
// }
|
||||
|
||||
String timestamp() => DateTime.now().millisecondsSinceEpoch.toString();
|
||||
|
||||
void showInSnackBar(String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void onNewCameraSelected(CameraDescription cameraDescription) async {
|
||||
print(cameraDescription.lensDirection.toString());
|
||||
if (controller != null) {
|
||||
await controller!.dispose();
|
||||
}
|
||||
controller = CameraController(
|
||||
cameraDescription,
|
||||
ResolutionPreset.medium,
|
||||
// enableAudio: enableAudio,
|
||||
);
|
||||
|
||||
// If the controller is updated then update the UI.
|
||||
controller!.addListener(() {
|
||||
if (mounted) setState(() {});
|
||||
if (controller!.value.hasError) {
|
||||
showInSnackBar('Camera error ${controller!.value.errorDescription}');
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await controller!.initialize();
|
||||
} on CameraException catch (e) {
|
||||
_showCameraException(e);
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
void onTakePictureButtonPressed() {
|
||||
takePicture().then((String? filePath) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
imagePath = filePath;
|
||||
var profileProviderObject =
|
||||
Provider.of<TestResultsProvider>(context, listen: false);
|
||||
List<PlatformFile> files = profileProviderObject.catchImages;
|
||||
print(imagePath);
|
||||
files.add(PlatformFile(
|
||||
name: 'test',
|
||||
size: 0,
|
||||
path: imagePath,
|
||||
bytes: File(imagePath!).readAsBytesSync()));
|
||||
profileProviderObject.setCatchImages(files);
|
||||
profileProviderObject.setImages();
|
||||
print(imagePath);
|
||||
});
|
||||
if (filePath != null) {
|
||||
Navigator.of(context).pop();
|
||||
// showInSnackBar('Picture saved to $filePath');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<String?> takePicture() async {
|
||||
if (!controller!.value.isInitialized) {
|
||||
showInSnackBar('Error: select a camera first.');
|
||||
return null;
|
||||
}
|
||||
final Directory extDir = await getApplicationDocumentsDirectory();
|
||||
final String dirPath = '${extDir.path}/Pictures/flutter_test';
|
||||
await Directory(dirPath).create(recursive: true);
|
||||
final String filePath = '$dirPath/${timestamp()}.jpg';
|
||||
|
||||
if (controller!.value.isTakingPicture) {
|
||||
// A capture is already pending, do nothing.
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
await controller!.takePicture();
|
||||
} on CameraException catch (e) {
|
||||
_showCameraException(e);
|
||||
return null;
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
void _showCameraException(CameraException e) {
|
||||
logError(e.code, e.description!);
|
||||
showInSnackBar('Error: ${e.code}\n${e.description}');
|
||||
}
|
||||
}
|
||||
|
||||
// class CameraApp extends StatelessWidget {
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return MaterialApp(
|
||||
// home: CaptureImage(),
|
||||
// return SafeArea(
|
||||
// child: Scaffold(
|
||||
// key: _scaffoldKey,
|
||||
// // appBar: AppBar(
|
||||
// // title: const Text('Take Picture'),
|
||||
// // ),
|
||||
// body: isInit
|
||||
// ? Center(
|
||||
// child: CircularProgressIndicator(
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
// )
|
||||
// : Stack(children: <Widget>[
|
||||
// _cameraPreviewWidget(),
|
||||
// Positioned(
|
||||
// bottom: 100, left: 100, child: _captureControlRowWidget()),
|
||||
// Positioned(
|
||||
// bottom: 100,
|
||||
// right: 100,
|
||||
// child: InkWell(
|
||||
// onTap: () {
|
||||
// if (curCamera == 0) {
|
||||
// try {
|
||||
// onNewCameraSelected(cameras[1]);
|
||||
// setState(() {
|
||||
// curCamera = 1;
|
||||
// });
|
||||
// } catch (e) {}
|
||||
// } else {
|
||||
// onNewCameraSelected(cameras[0]);
|
||||
// setState(() {
|
||||
// curCamera = 0;
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
// child: Icon(
|
||||
// curCamera == 0 ? Icons.camera_rear : Icons.camera_front,
|
||||
// size: 40,
|
||||
// color: Colors.white,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// // _cameraTogglesRowWidget(cameras),
|
||||
// ]),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// List<CameraDescription> cameras = [];
|
||||
|
||||
// Future<void> main() async {
|
||||
// // Fetch the available cameras before initializing the app.
|
||||
// try {
|
||||
// WidgetsFlutterBinding.ensureInitialized();
|
||||
// } on CameraException catch (e) {
|
||||
// logError(e.code, e.description);
|
||||
// /// Display the preview from the camera (or a message if the preview is not available).
|
||||
// Widget _cameraPreviewWidget() {
|
||||
// if (controller == null || !controller!.value.isInitialized) {
|
||||
// return const Text(
|
||||
// 'Tap a camera',
|
||||
// style: TextStyle(
|
||||
// color: Colors.white,
|
||||
// fontSize: 24.0,
|
||||
// fontWeight: FontWeight.w900,
|
||||
// ),
|
||||
// );
|
||||
// } else {
|
||||
// return Container(
|
||||
// width: double.infinity,
|
||||
// child: CameraPreview(controller!),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// Toggle recording audio
|
||||
|
||||
// /// Display the control bar with buttons to take pictures and record videos.
|
||||
// Widget _captureControlRowWidget() {
|
||||
// return Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
// mainAxisSize: MainAxisSize.max,
|
||||
// children: <Widget>[
|
||||
// IconButton(
|
||||
// icon: const Icon(
|
||||
// Icons.camera_alt,
|
||||
// size: 40,
|
||||
// color: Colors.white,
|
||||
// ),
|
||||
// // color: Colors.blue,
|
||||
// onPressed: controller != null &&
|
||||
// controller!.value.isInitialized &&
|
||||
// !controller!.value.isRecordingVideo
|
||||
// ? onTakePictureButtonPressed
|
||||
// : null,
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
|
||||
// getCameras() async {
|
||||
// return await availableCameras();
|
||||
// }
|
||||
|
||||
// /// Display a row of toggle to select the camera (or a message if no camera is available).
|
||||
// // Widget _cameraTogglesRowWidget(var cameras) {
|
||||
// // final List<Widget> toggles = <Widget>[];
|
||||
|
||||
// // if (cameras.isEmpty) {
|
||||
// // return const Text('No camera found');
|
||||
// // } else {
|
||||
// // for (CameraDescription cameraDescription in cameras) {
|
||||
// // print("${cameraDescription.name}");
|
||||
// // toggles.add(
|
||||
// // SizedBox(
|
||||
// // width: 90.0,
|
||||
// // child: RadioListTile<CameraDescription>(
|
||||
// // title: Icon(getCameraLensIcon(cameraDescription.lensDirection)),
|
||||
// // groupValue: controller?.description,
|
||||
// // value: cameraDescription,
|
||||
// // onChanged: controller != null && controller.value.isRecordingVideo
|
||||
// // ? null
|
||||
// // : onNewCameraSelected,
|
||||
// // ),
|
||||
// // ),
|
||||
// // );
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // return Row(children: toggles);
|
||||
// // }
|
||||
|
||||
// String timestamp() => DateTime.now().millisecondsSinceEpoch.toString();
|
||||
|
||||
// void showInSnackBar(String message) {
|
||||
// ScaffoldMessenger.of(context).showSnackBar(
|
||||
// SnackBar(
|
||||
// content: Text(message),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
|
||||
// void onNewCameraSelected(CameraDescription cameraDescription) async {
|
||||
// print(cameraDescription.lensDirection.toString());
|
||||
// if (controller != null) {
|
||||
// await controller!.dispose();
|
||||
// }
|
||||
// controller = CameraController(
|
||||
// cameraDescription,
|
||||
// ResolutionPreset.medium,
|
||||
// // enableAudio: enableAudio,
|
||||
// );
|
||||
|
||||
// // If the controller is updated then update the UI.
|
||||
// controller!.addListener(() {
|
||||
// if (mounted) setState(() {});
|
||||
// if (controller!.value.hasError) {
|
||||
// showInSnackBar('Camera error ${controller!.value.errorDescription}');
|
||||
// }
|
||||
// });
|
||||
|
||||
// try {
|
||||
// await controller!.initialize();
|
||||
// } on CameraException catch (e) {
|
||||
// _showCameraException(e);
|
||||
// }
|
||||
|
||||
// if (mounted) {
|
||||
// setState(() {});
|
||||
// }
|
||||
// }
|
||||
|
||||
// void onTakePictureButtonPressed() {
|
||||
// takePicture().then((String? filePath) {
|
||||
// if (mounted) {
|
||||
// setState(() {
|
||||
// imagePath = filePath;
|
||||
// var profileProviderObject =
|
||||
// Provider.of<TestResultsProvider>(context, listen: false);
|
||||
// List<PlatformFile> files = profileProviderObject.catchImages;
|
||||
// print(imagePath);
|
||||
// files.add(PlatformFile(
|
||||
// name: 'test',
|
||||
// size: 0,
|
||||
// path: imagePath,
|
||||
// bytes: File(imagePath!).readAsBytesSync()));
|
||||
// profileProviderObject.setCatchImages(files);
|
||||
// profileProviderObject.setImages();
|
||||
// print(imagePath);
|
||||
// });
|
||||
// if (filePath != null) {
|
||||
// Navigator.of(context).pop();
|
||||
// // showInSnackBar('Picture saved to $filePath');
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// Future<String?> takePicture() async {
|
||||
// if (!controller!.value.isInitialized) {
|
||||
// showInSnackBar('Error: select a camera first.');
|
||||
// return null;
|
||||
// }
|
||||
// final Directory extDir = await getApplicationDocumentsDirectory();
|
||||
// final String dirPath = '${extDir.path}/Pictures/flutter_test';
|
||||
// await Directory(dirPath).create(recursive: true);
|
||||
// final String filePath = '$dirPath/${timestamp()}.jpg';
|
||||
|
||||
// if (controller!.value.isTakingPicture) {
|
||||
// // A capture is already pending, do nothing.
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// try {
|
||||
// await controller!.takePicture();
|
||||
// } on CameraException catch (e) {
|
||||
// _showCameraException(e);
|
||||
// return null;
|
||||
// }
|
||||
// return filePath;
|
||||
// }
|
||||
|
||||
// void _showCameraException(CameraException e) {
|
||||
// logError(e.code, e.description!);
|
||||
// showInSnackBar('Error: ${e.code}\n${e.description}');
|
||||
// }
|
||||
// runApp(CameraApp());
|
||||
// }
|
||||
|
||||
// // class CameraApp extends StatelessWidget {
|
||||
// // @override
|
||||
// // Widget build(BuildContext context) {
|
||||
// // return MaterialApp(
|
||||
// // home: CaptureImage(),
|
||||
// // );
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // List<CameraDescription> cameras = [];
|
||||
|
||||
// // Future<void> main() async {
|
||||
// // // Fetch the available cameras before initializing the app.
|
||||
// // try {
|
||||
// // WidgetsFlutterBinding.ensureInitialized();
|
||||
// // } on CameraException catch (e) {
|
||||
// // logError(e.code, e.description);
|
||||
// // }
|
||||
// // runApp(CameraApp());
|
||||
// // }
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
// ignore_for_file: deprecated_member_use, invalid_use_of_visible_for_testing_member
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:barcode_scan2/barcode_scan2.dart';
|
||||
import 'package:cssd/config/colors.dart';
|
||||
import 'package:cssd/providers/input.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:image_picker_gallery_camera/image_picker_gallery_camera.dart';
|
||||
import 'package:multiselect_formfield/multiselect_formfield.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../config/routes.dart';
|
||||
import '../../../providers/test_results.dart';
|
||||
|
||||
class FormCreator extends StatefulWidget {
|
||||
@@ -124,8 +128,7 @@ class _FormCreatorState extends State<FormCreator> {
|
||||
),
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
await Navigator.of(context)
|
||||
.pushNamed(Routes.captureImageScreen);
|
||||
await loadAssetsFromCamera(context);
|
||||
// await captureImage(context);
|
||||
},
|
||||
child: Container(
|
||||
@@ -589,6 +592,27 @@ class _FormCreatorState extends State<FormCreator> {
|
||||
// profileProviderObject.addImage();
|
||||
}
|
||||
|
||||
Future<void> loadAssetsFromCamera(BuildContext context) async {
|
||||
var providerObject =
|
||||
Provider.of<TestResultsProvider>(context, listen: false);
|
||||
List<PlatformFile> _catchImages = providerObject.catchImages;
|
||||
var image = await ImagePicker.platform.pickImage(
|
||||
source: ImageSource.camera,
|
||||
);
|
||||
if (image != null) {
|
||||
_catchImages.add(
|
||||
PlatformFile(
|
||||
path: image.path,
|
||||
name: "item_image",
|
||||
bytes: File(image.path).readAsBytesSync(),
|
||||
size: File(image.path).lengthSync(),
|
||||
),
|
||||
);
|
||||
providerObject.setCatchImages(_catchImages);
|
||||
providerObject.setImages();
|
||||
}
|
||||
}
|
||||
|
||||
// _FormCreatorState(this.formItems);
|
||||
|
||||
void _handleChanged() {
|
||||
|
||||
Reference in New Issue
Block a user