2024-02-07 17:25:29 +06:30
|
|
|
import 'package:fcs/domain/entities/carton.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
2024-02-14 16:58:45 +06:30
|
|
|
import 'package:provider/provider.dart';
|
2024-02-07 17:25:29 +06:30
|
|
|
|
2024-02-14 16:58:45 +06:30
|
|
|
import '../main/util.dart';
|
2024-02-09 17:44:13 +06:30
|
|
|
import '../widgets/local_button.dart';
|
2025-03-07 17:41:09 +06:30
|
|
|
import '../widgets/local_text.dart';
|
2024-02-08 17:09:53 +06:30
|
|
|
import '../widgets/multi_img_file.dart';
|
2024-02-14 16:58:45 +06:30
|
|
|
import 'model/carton_model.dart';
|
2024-02-07 17:25:29 +06:30
|
|
|
|
2024-02-09 13:49:18 +06:30
|
|
|
class CartonImageUploadEditor extends StatefulWidget {
|
2024-02-14 16:58:45 +06:30
|
|
|
final Carton carton;
|
2025-03-07 17:41:09 +06:30
|
|
|
const CartonImageUploadEditor({super.key, required this.carton});
|
2024-02-07 17:25:29 +06:30
|
|
|
@override
|
|
|
|
|
_CartonImageUploaState createState() => _CartonImageUploaState();
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-09 13:49:18 +06:30
|
|
|
class _CartonImageUploaState extends State<CartonImageUploadEditor> {
|
2024-02-08 17:01:32 +06:30
|
|
|
bool _isLoading = false;
|
2024-02-14 16:58:45 +06:30
|
|
|
|
2025-03-07 17:41:09 +06:30
|
|
|
MultiImgController multiImgController = MultiImgController();
|
2024-02-07 17:25:29 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2025-03-07 17:41:09 +06:30
|
|
|
multiImgController.setImageUrls = widget.carton.photoUrls;
|
2024-02-07 17:25:29 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-02-09 17:47:35 +06:30
|
|
|
final saveBtn = Padding(
|
2024-02-09 17:44:13 +06:30
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 30),
|
|
|
|
|
child: LocalButton(
|
2024-02-14 16:58:45 +06:30
|
|
|
textKey: "btn.save",
|
|
|
|
|
callBack: () {
|
|
|
|
|
_uploadImage();
|
|
|
|
|
}),
|
2024-02-09 17:44:13 +06:30
|
|
|
);
|
|
|
|
|
|
2024-02-07 17:25:29 +06:30
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
2024-02-08 17:01:32 +06:30
|
|
|
appBar: LocalAppBar(
|
2025-03-07 17:41:09 +06:30
|
|
|
titleWidget: Column(
|
|
|
|
|
children: [
|
|
|
|
|
LocalText(context, "box.imageupload.title",
|
|
|
|
|
fontSize: 20, color: primaryColor),
|
|
|
|
|
Text(widget.carton.cartonNumber ?? '',
|
|
|
|
|
style: TextStyle(fontSize: 15, color: Colors.black))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
labelColor: primaryColor,
|
|
|
|
|
arrowColor: primaryColor,
|
|
|
|
|
),
|
2024-02-09 17:44:13 +06:30
|
|
|
body: Padding(
|
|
|
|
|
padding: EdgeInsets.only(left: 12.0, right: 12),
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: [
|
|
|
|
|
MultiImageFile(
|
|
|
|
|
enabled: true,
|
2025-03-07 17:41:09 +06:30
|
|
|
controller: multiImgController,
|
2024-02-09 17:44:13 +06:30
|
|
|
title: "Receipt File",
|
2024-02-09 17:09:05 +06:30
|
|
|
),
|
2024-02-14 16:58:45 +06:30
|
|
|
const SizedBox(height: 20),
|
2024-02-09 17:47:35 +06:30
|
|
|
saveBtn,
|
2024-02-09 17:44:13 +06:30
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)));
|
2024-02-07 17:25:29 +06:30
|
|
|
}
|
2024-02-14 16:58:45 +06:30
|
|
|
|
|
|
|
|
_uploadImage() async {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
await context.read<CartonModel>().uploadCartonImages(widget.carton,
|
2025-03-07 17:41:09 +06:30
|
|
|
multiImgController.getAddedFile, multiImgController.getDeletedUrl);
|
2024-02-14 16:58:45 +06:30
|
|
|
Navigator.pop(context, true);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-07 17:25:29 +06:30
|
|
|
}
|