|
|
|
|
@ -11,22 +11,44 @@ import '../../../new_views/app_style/app_color.dart';
|
|
|
|
|
|
|
|
|
|
class AssetPicker extends StatelessWidget {
|
|
|
|
|
final Function(Asset)? onPick;
|
|
|
|
|
final Function(List<Asset>)? onMultiAssetPick;
|
|
|
|
|
final Function(int)? onAssetRemove;
|
|
|
|
|
final Asset? device;
|
|
|
|
|
final List<Asset> deviceList;
|
|
|
|
|
final bool editable;
|
|
|
|
|
final bool showAssetInfo;
|
|
|
|
|
final Color? borderColor;
|
|
|
|
|
final Color? buttonColor;
|
|
|
|
|
final bool forPPM;
|
|
|
|
|
final bool showLoading;
|
|
|
|
|
final bool multiSelection;
|
|
|
|
|
|
|
|
|
|
const AssetPicker({Key? key, this.editable = true, this.device, this.onPick, this.borderColor, this.buttonColor, this.showAssetInfo = true, this.forPPM = false, this.showLoading = false})
|
|
|
|
|
: super(key: key);
|
|
|
|
|
const AssetPicker(
|
|
|
|
|
{Key? key,
|
|
|
|
|
this.editable = true,
|
|
|
|
|
this.device,
|
|
|
|
|
this.deviceList = const [],
|
|
|
|
|
this.onPick,
|
|
|
|
|
this.onMultiAssetPick,
|
|
|
|
|
this.onAssetRemove,
|
|
|
|
|
this.borderColor,
|
|
|
|
|
this.buttonColor,
|
|
|
|
|
this.showAssetInfo = true,
|
|
|
|
|
this.multiSelection = false,
|
|
|
|
|
this.forPPM = false,
|
|
|
|
|
this.showLoading = false})
|
|
|
|
|
: assert(
|
|
|
|
|
multiSelection == false || onMultiAssetPick != null,
|
|
|
|
|
'Cannot use multiple asset picker with single onPick Method\n'
|
|
|
|
|
'Use onMultiAssetPick method instead.',
|
|
|
|
|
),
|
|
|
|
|
super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
if (device == null)
|
|
|
|
|
if (device == null && deviceList.isEmpty)
|
|
|
|
|
Container(
|
|
|
|
|
height: 50,
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
@ -45,12 +67,24 @@ class AssetPicker extends StatelessWidget {
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
).onPress(() async {
|
|
|
|
|
Asset? device = await Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
|
builder: (context) => AssetScanQr(
|
|
|
|
|
title: context.translation.assetScan,
|
|
|
|
|
))) as Asset?;
|
|
|
|
|
if (device != null) {
|
|
|
|
|
onPick!(device);
|
|
|
|
|
if (multiSelection) {
|
|
|
|
|
List<Asset>? device = await Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
|
builder: (context) => AssetScanQr(
|
|
|
|
|
title: context.translation.assetScan,
|
|
|
|
|
multiSelection: multiSelection,
|
|
|
|
|
))) as List<Asset>?;
|
|
|
|
|
if (device?.isNotEmpty ?? false) {
|
|
|
|
|
onMultiAssetPick!(device!);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Asset? device = await Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
|
builder: (context) => AssetScanQr(
|
|
|
|
|
title: context.translation.assetScan,
|
|
|
|
|
multiSelection: multiSelection,
|
|
|
|
|
))) as Asset?;
|
|
|
|
|
if (device != null) {
|
|
|
|
|
onPick!(device);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
else
|
|
|
|
|
@ -71,71 +105,104 @@ class AssetPicker extends StatelessWidget {
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
).onPress(() async {
|
|
|
|
|
Asset? device = await Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
|
builder: (context) => AssetScanQr(
|
|
|
|
|
title: context.translation.assetScan,
|
|
|
|
|
))) as Asset?;
|
|
|
|
|
if (device != null) {
|
|
|
|
|
onPick!(device);
|
|
|
|
|
if (multiSelection) {
|
|
|
|
|
List<Asset>? device = await Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
|
builder: (context) => AssetScanQr(
|
|
|
|
|
title: context.translation.assetScan,
|
|
|
|
|
multiSelection: multiSelection,
|
|
|
|
|
))) as List<Asset>?;
|
|
|
|
|
if (device?.isNotEmpty ?? false) {
|
|
|
|
|
onMultiAssetPick!(device!);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Asset? device = await Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
|
builder: (context) => AssetScanQr(
|
|
|
|
|
title: context.translation.assetScan,
|
|
|
|
|
multiSelection: multiSelection,
|
|
|
|
|
))) as Asset?;
|
|
|
|
|
if (device != null) {
|
|
|
|
|
onPick!(device);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
if (device != null && showAssetInfo)
|
|
|
|
|
Container(
|
|
|
|
|
padding: const EdgeInsets.all(12),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: showLoading ? Colors.white : const Color(0xffF4F6FC),
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: const Color(0xff212936).withOpacity(.03),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
device?.modelDefinition?.assetName?.cleanupWhitespace.capitalizeFirstOfEach ?? "",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 14.toScreenWidth,
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
fontStyle: FontStyle.normal,
|
|
|
|
|
color: Colors.black87,
|
|
|
|
|
decoration: TextDecoration.none,
|
|
|
|
|
),
|
|
|
|
|
).toShimmer(isShow: showLoading).expanded,
|
|
|
|
|
const Icon(
|
|
|
|
|
Icons.info,
|
|
|
|
|
color: Color(0xff7D859A),
|
|
|
|
|
size: 20,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
"${context.translation.assetNo}: ${device!.assetNumber}".bodyText2(context).toShimmer(isShow: showLoading),
|
|
|
|
|
2.height,
|
|
|
|
|
// "${context.translation.manufacture}: ${device.modelDefinition?.manufacturerName}".bodyText(context),
|
|
|
|
|
"${context.translation.model}: ${device!.modelDefinition?.modelName}".bodyText2(context).toShimmer(isShow: showLoading),
|
|
|
|
|
// "${context.translation.serialNumber}: ${device.assetNumber}".bodyText(context),
|
|
|
|
|
// const Divider().defaultStyle(context),
|
|
|
|
|
// "${context.translation.department}: ${device.department?.departmentName}".bodyText(context),
|
|
|
|
|
// "${context.translation.site}: ${device.site?.custName}".bodyText(context),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
).onPress(() {
|
|
|
|
|
showModalBottomSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
isScrollControlled: true,
|
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.vertical(
|
|
|
|
|
top: Radius.circular(20),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
clipBehavior: Clip.antiAliasWithSaveLayer,
|
|
|
|
|
builder: (BuildContext context) => AssetDetailBottomSheet(device),
|
|
|
|
|
);
|
|
|
|
|
}).paddingOnly(top: 16),
|
|
|
|
|
if (device != null && showAssetInfo) _assetInfoView(device!, context).paddingOnly(top: 16),
|
|
|
|
|
if (deviceList.isNotEmpty && showAssetInfo)
|
|
|
|
|
ListView.separated(
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
padding: EdgeInsets.only(top: 16),
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
itemBuilder: (cxt, index) => _assetInfoView(deviceList[index], context),
|
|
|
|
|
separatorBuilder: (cxt, index) => 12.height,
|
|
|
|
|
itemCount: deviceList.length)
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _assetInfoView(Asset device, BuildContext context) {
|
|
|
|
|
return Container(
|
|
|
|
|
padding: const EdgeInsets.all(12),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: showLoading ? Colors.white : const Color(0xffF4F6FC),
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: const Color(0xff212936).withOpacity(.03),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
device.modelDefinition?.assetName?.cleanupWhitespace.capitalizeFirstOfEach ?? "",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 14.toScreenWidth,
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
fontStyle: FontStyle.normal,
|
|
|
|
|
color: Colors.black87,
|
|
|
|
|
decoration: TextDecoration.none,
|
|
|
|
|
),
|
|
|
|
|
).toShimmer(isShow: showLoading).expanded,
|
|
|
|
|
const Icon(
|
|
|
|
|
Icons.info,
|
|
|
|
|
color: Color(0xff7D859A),
|
|
|
|
|
size: 20,
|
|
|
|
|
).onPress(() {
|
|
|
|
|
showModalBottomSheet(
|
|
|
|
|
context: context,
|
|
|
|
|
isScrollControlled: true,
|
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.vertical(
|
|
|
|
|
top: Radius.circular(20),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
clipBehavior: Clip.antiAliasWithSaveLayer,
|
|
|
|
|
builder: (BuildContext context) => AssetDetailBottomSheet(device),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
if (multiSelection) ...[
|
|
|
|
|
4.width,
|
|
|
|
|
const Icon(
|
|
|
|
|
Icons.delete_rounded,
|
|
|
|
|
color: Color(0xffF63939),
|
|
|
|
|
size: 20,
|
|
|
|
|
).onPress(() {
|
|
|
|
|
onAssetRemove!(device.id!.toInt());
|
|
|
|
|
}),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
"${context.translation.assetNo}: ${device!.assetNumber}".bodyText2(context).toShimmer(isShow: showLoading),
|
|
|
|
|
2.height,
|
|
|
|
|
// "${context.translation.manufacture}: ${device.modelDefinition?.manufacturerName}".bodyText(context),
|
|
|
|
|
"${context.translation.model}: ${device!.modelDefinition?.modelName}".bodyText2(context).toShimmer(isShow: showLoading),
|
|
|
|
|
// "${context.translation.serialNumber}: ${device.assetNumber}".bodyText(context),
|
|
|
|
|
// const Divider().defaultStyle(context),
|
|
|
|
|
// "${context.translation.department}: ${device.department?.departmentName}".bodyText(context),
|
|
|
|
|
// "${context.translation.site}: ${device.site?.custName}".bodyText(context),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|