This commit is contained in:
erfan hayat'bakhsh
2020-08-01 14:16:20 +04:30
parent 30f10dca2e
commit e4d29c4e3c
71 changed files with 5018 additions and 2319 deletions
@@ -1,8 +1,16 @@
import 'dart:io';
import 'package:cssd/config/routes.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:image_picker_gallery_camera/image_picker_gallery_camera.dart';
import 'package:meta/meta.dart';
import 'package:multiselect_formfield/multiselect_formfield.dart';
import 'package:provider/provider.dart';
import '../../../providers/test_results.dart';
class FormCreator extends StatefulWidget {
const FormCreator({
@@ -60,7 +68,82 @@ class _FormCreatorState extends State<FormCreator> {
),
);
}
if (item['type'] == 'Image') {
final testProviderObject = Provider.of<TestResultsProvider>(context);
final mediaData = MediaQuery.of(context);
final deviceWidth = mediaData.size.width;
final _deviceBlockSize = deviceWidth / 100;
listWidgets.insert(
3,
Container(
// height: 70,
child: Directionality(
textDirection: TextDirection.rtl,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 20),
height: testProviderObject.catchImages.length != 0 ? 60 : 0,
child: ImageBox(
deviceBlockSize: _deviceBlockSize,
testProvider: testProviderObject,
),
),
SizedBox(
height: testProviderObject.catchImages.length != 0 ? 10 : 0,
),
InkWell(
onTap: () async {
await loadAssets(context);
},
child: Container(
width: MediaQuery.of(context).size.width - 40,
padding:
EdgeInsets.symmetric(vertical: 10, horizontal: 30),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.black,
),
child: Text(
'+ Add an image or file from device',
textDirection: TextDirection.ltr,
style: TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
),
),
SizedBox(
height: 10,
),
InkWell(
onTap: () async {
await Navigator.of(context).pushNamed(Routes.captureImageScreen);
// await captureImage(context);
},
child: Container(
width: MediaQuery.of(context).size.width - 40,
padding:
EdgeInsets.symmetric(vertical: 10, horizontal: 30),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.black,
),
child: Text(
'+ Add an image from camera',
textDirection: TextDirection.ltr,
style: TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
),
),
],
),
),
),
);
}
if (item['type'] == "Label") {
listWidgets.add(
Container(
@@ -113,26 +196,39 @@ class _FormCreatorState extends State<FormCreator> {
}
formItems[count]['value'] = formItems[count]['value'] ?? startValue;
int divisions = (endValue - startValue).round();
// int divisions = (endValue - startValue).round();
listWidgets.add(
Padding(
padding: EdgeInsets.only(top: 35),
child: Slider(
min: startValue,
max: endValue,
value: formItems[count]['value'],
label: '${formItems[count]['value'].round()}',
divisions: divisions,
onChanged: (double value) {
setState(() {
formItems[count]['value'] = value;
});
},
semanticFormatterCallback: (double newValue) {
return '${newValue.round()}';
},
),
),
padding: EdgeInsets.only(top: 35, left: 10, right: 10),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(item['type']),
Text(formItems[count]['value'].toString()),
],
),
Slider(
min: startValue,
max: endValue,
value: formItems[count]['value'],
// label: '${formItems[count]['value'].round()}',
// divisions: divisions,
onChanged: (double value) {
setState(() {
formItems[count]['value'] =
double.parse(value.toStringAsFixed(2));
});
// print(formItems[count]['value']);
},
// semanticFormatterCallback: (double newValue) {
// return '${newValue.round()}';
// },
),
],
)),
);
}
@@ -353,9 +449,51 @@ class _FormCreatorState extends State<FormCreator> {
// ),
// );
}
return listWidgets;
}
Future captureImage(BuildContext context) async {
var profileProviderObject =
Provider.of<TestResultsProvider>(context, listen: false);
List<File> files = profileProviderObject.catchImages;
try {
files.add(
await ImagePickerGC.pickImage(
context: context,
source: ImgSource.Camera,
cameraIcon: Icon(
Icons.camera_alt,
color: Colors.red,
), //cameraIcon and galleryIcon can change. If no icon provided default icon will be present
cameraText: Text(
"From Camera",
style: TextStyle(color: Colors.red),
),
),
);
} catch (e) {}
profileProviderObject.setCatchImages(files);
profileProviderObject.setImages();
}
Future<void> loadAssets(BuildContext context) async {
var profileProviderObject =
Provider.of<TestResultsProvider>(context, listen: false);
List<File> files = profileProviderObject.catchImages;
try {
files += await FilePicker.getMultiFile(
type: FileType.custom,
allowedExtensions: ['jpg', 'png', 'bmp', 'jpeg', 'pdf', 'docx', 'doc'],
);
// print(files);
} catch (_) {}
profileProviderObject.setCatchImages(files);
profileProviderObject.setImages();
// profileProviderObject.addImage();
}
_FormCreatorState(this.formItems);
void _handleChanged() {
@@ -377,3 +515,110 @@ class _FormCreatorState extends State<FormCreator> {
);
}
}
class ImageBox extends StatelessWidget {
const ImageBox({
Key key,
@required double deviceBlockSize,
@required TestResultsProvider testProvider,
}) : _deviceBlockSize = deviceBlockSize,
_testProvider = testProvider,
super(key: key);
final double _deviceBlockSize;
final TestResultsProvider _testProvider;
@override
Widget build(BuildContext context) {
return ListView.separated(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemBuilder: (ctx, index) {
bool isPdf = _testProvider.catchImages[index].path.endsWith('pdf');
bool isWord = _testProvider.catchImages[index].path.endsWith('docx') ||
_testProvider.catchImages[index].path.endsWith('doc');
// print(_testProvider.catchImages[index].path.endsWith('jpg'));
// .substring(_testProvider.catchImages[index].path.length - 4));
return ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Container(
width: 60,
height: 60,
child: Stack(
children: <Widget>[
Positioned(
top: 10,
left: 0,
child: GestureDetector(
onTap: () => isPdf
? print('pdf')
: isWord
? print('word')
: Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => Container(
color: Colors.white,
child: Center(
child: Image.file(
_testProvider.catchImages[index],
),
),
),
),
),
child: isPdf
? Image.asset(
'assets/Images/pdf.png',
width: 60,
height: 60,
fit: BoxFit.fill,
)
: isWord
? Image.asset(
'assets/Images/word.png',
width: 60,
height: 60,
fit: BoxFit.fill,
)
: Image.file(
_testProvider.catchImages[index],
// asset: _images[index],
width: 60,
height: 60,
fit: BoxFit.fill,
),
),
),
Positioned(
top: 0,
right: 0,
child: GestureDetector(
onTap: () {
// setState(() {
_testProvider.removeImage(index);
// });
},
child: CircleAvatar(
backgroundColor: Colors.red,
radius: 10,
child: Icon(
Icons.close,
size: 12,
color: Colors.white,
),
),
),
)
],
),
),
);
},
itemCount: _testProvider.catchImages.length,
separatorBuilder: (BuildContext context, int index) => SizedBox(
width: 3 * _deviceBlockSize,
),
);
}
}