|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:test_sa/controllers/providers/api/devices_provider.dart';
|
|
|
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
|
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:test_sa/helper/utils.dart';
|
|
|
|
|
import 'package:test_sa/models/generic_attachment_model.dart';
|
|
|
|
|
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
|
|
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/default_app_bar.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/dialogs/dialog.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
|
|
|
|
|
|
|
|
|
|
class AssetImageUploadPage extends StatefulWidget {
|
|
|
|
|
int assetId;
|
|
|
|
|
List<GenericAttachmentModel> attachments;
|
|
|
|
|
|
|
|
|
|
AssetImageUploadPage({Key? key, required this.assetId, required this.attachments}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_AssetImageUploadPageState createState() {
|
|
|
|
|
return _AssetImageUploadPageState();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AssetImageUploadPageState extends State<AssetImageUploadPage> {
|
|
|
|
|
List<GenericAttachmentModel> attachments = [];
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
// attachments = widget.attachments;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: const DefaultAppBar(title: "Upload"),
|
|
|
|
|
body: Column(
|
|
|
|
|
children: [
|
|
|
|
|
ListView(
|
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
|
children: [
|
|
|
|
|
AttachmentPicker(
|
|
|
|
|
label: "Import",
|
|
|
|
|
attachment: attachments,
|
|
|
|
|
buttonColor: AppColor.black10,
|
|
|
|
|
onlyImages: true,
|
|
|
|
|
pickMultiple: true,
|
|
|
|
|
showAsListView: true,
|
|
|
|
|
buttonIcon: 'image-plus'.toSvgAsset(color: context.isDark ? AppColor.primary10 : AppColor.neutral120),
|
|
|
|
|
onChange: (_attachments) {
|
|
|
|
|
attachments = _attachments;
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
).toShadowContainer(context),
|
|
|
|
|
],
|
|
|
|
|
).expanded,
|
|
|
|
|
FooterActionButton.footerContainer(
|
|
|
|
|
context: context,
|
|
|
|
|
child: AppFilledButton(
|
|
|
|
|
buttonColor: AppColor.primary10,
|
|
|
|
|
disableButton: attachments.length < 4,
|
|
|
|
|
label: "Upload Images",
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
bool result = await showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (_) => AAlertDialog(
|
|
|
|
|
title: context.translation.confirm,
|
|
|
|
|
content: "For more enhancement, these images will be used to train AI model.\n\nAre you sure you are uploading clear and high quality images?"),
|
|
|
|
|
);
|
|
|
|
|
if (result) {
|
|
|
|
|
Utils.showUploadingDialog(context);
|
|
|
|
|
result = await Provider.of<AssetProvider>(context, listen: false).uploadAssetImages(widget.assetId, attachments);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (result) {
|
|
|
|
|
Navigator.pop(context, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|