fix: 1.not display inout records when changing date 2.reduce image upload quality

This commit is contained in:
louis 2024-04-15 15:14:40 +08:00
parent cc8ef3e1a8
commit 61e09970d4
16 changed files with 110 additions and 129 deletions

View File

@ -29,15 +29,15 @@ if (flutterVersionName == null) {
android {
namespace "com.sdkj.skt"
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 34
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}
sourceSets {
@ -50,8 +50,7 @@ android {
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
compileSdkVersion 34
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

View File

@ -0,0 +1,6 @@
package com.sdkj.sk_base_mobile
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}

View File

@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.9.22'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.0' // Change this to a version that supports compileSdkVersion 34
classpath 'com.android.tools.build:gradle:8.0.2' // Change this to a version that supports compileSdkVersion 34
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

View File

@ -16,6 +16,7 @@ import 'package:sk_base_mobile/util/logger_util.dart';
import 'package:sk_base_mobile/util/media_util.dart';
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
import 'package:sk_base_mobile/util/snack_bar.util.dart';
import 'package:sk_base_mobile/util/util.dart';
import 'package:sk_base_mobile/widgets/common/multi-picker/models/value_item.dart';
import 'package:sk_base_mobile/widgets/core/sk_cascade_picker.dart';
import 'package:sk_base_mobile/widgets/core/sk_dialog_header.dart';
@ -392,9 +393,19 @@ class EditUserInfoController extends GetxController {
}
Future<void> photoPicker() async {
XFile? pickedFile = await MediaUtil().getImageFromGallery();
if (pickedFile != null) {
filePath.value = pickedFile.path;
}
await MediaUtil().showPicker(callback: (path) async {
if (path != null) {
filePath.value = path;
// MB
final file = File(path);
final size = await file.length();
final sizeInMb = size / (1024 * 1024);
print(sizeInMb);
// if (sizeInMb > 2) {
// SnackBarUtil().error('图片大小不能超过2MB');
// filePath.value = '';
// }
}
});
}
}

View File

@ -10,16 +10,15 @@ import 'package:sk_base_mobile/widgets/fade_in_cache_image.dart';
import '../../../constants/enum.dart';
class InventoryInoutCard extends StatelessWidget {
InventoryInoutCard({super.key, required this.index, required this.ind});
InventoryInoutCard({super.key, required this.index});
final int index;
final int ind;
final controller = Get.find<InventoryInoutController>();
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
controller
.showInventoryInoutInfoDialog(controller.list[ind][index].id!);
.showInventoryInoutInfoDialog(controller.inoutList[index].id!);
},
child: Stack(
children: [
@ -67,7 +66,7 @@ class InventoryInoutCard extends StatelessWidget {
children: [
Expanded(
child: Text(
controller.list[ind][index].product?.name ?? '-',
controller.inoutList[index].product?.name ?? '-',
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black,
@ -77,7 +76,7 @@ class InventoryInoutCard extends StatelessWidget {
],
),
Text(
controller.list[ind][index].product?.company?.name ?? '-',
controller.inoutList[index].product?.company?.name ?? '-',
style: TextStyle(
color: AppTheme.grey, fontSize: ScreenAdaper.height(20)),
),
@ -88,7 +87,7 @@ class InventoryInoutCard extends StatelessWidget {
children: [
Expanded(
child: Text(
'${controller.list[ind][index].project?.name}',
'${controller.inoutList[index].project?.name}',
style: TextStyle(
color: AppTheme.grey, fontSize: ScreenAdaper.height(20)),
),
@ -102,18 +101,18 @@ class InventoryInoutCard extends StatelessWidget {
children: [
Expanded(
child: Text(
'${controller.list[ind][index].quantity} ${controller.list[ind][index].product?.unit?.label ?? '-'}',
'${controller.inoutList[index].quantity} ${controller.inoutList[index].product?.unit?.label ?? '-'}',
style: TextStyle(
fontSize: ScreenAdaper.height(20),
fontWeight: FontWeight.w600),
),
),
Text(
'${SkDateUtil.format(controller.list[ind][index].time!, formats: [
'${SkDateUtil.format(controller.inoutList[index].time!, formats: [
'HH',
':',
"nn"
])} ${controller.list[ind][index].agent ?? '-'}',
])} ${controller.inoutList[index].agent ?? '-'}',
style: TextStyle(
fontSize: ScreenAdaper.height(20),
fontWeight: FontWeight.w600),
@ -132,19 +131,19 @@ class InventoryInoutCard extends StatelessWidget {
child: FadeInCacheImage(
width: ScreenAdaper.height(150),
height: ScreenAdaper.height(150),
url: controller.list[ind][index].files.isNotEmpty
? '${GloablConfig.OSS_URL}${controller.list[ind][index].files[0].path}'
url: controller.inoutList[index].files.isNotEmpty
? '${GloablConfig.OSS_URL}${controller.inoutList[index].files[0].path}'
: ''),
));
}
Widget buildInOrOut() {
final bgColor =
controller.list[ind][index].inOrOut == InventoryInOrOutEnum.In
controller.inoutList[index].inOrOut == InventoryInOrOutEnum.In
? AppTheme.snackbarSuccessBackgroudColor
: AppTheme.snackbarErrorBackgroudColor;
final textInOut =
controller.list[ind][index].inOrOut == InventoryInOrOutEnum.In
controller.inoutList[index].inOrOut == InventoryInOrOutEnum.In
? ''
: '';
return Container(

View File

@ -17,33 +17,26 @@ class InventoryInoutViewItem extends StatelessWidget {
return Responsive(
tablet: Grid(
columnNum: 2,
ind: index,
),
largeTablet: Grid(
columnNum: 3,
ind: index,
),
mobile: Grid(
columnNum: 1,
ind: index,
));
}
}
class Grid extends StatelessWidget {
final int columnNum;
int ind;
final controller = Get.find<InventoryInoutController>();
Grid({super.key, required this.columnNum, required this.ind});
Grid({super.key, required this.columnNum});
@override
Widget build(BuildContext context) {
if (controller.currentIndex.value != ind) {
ind = controller.currentIndex.value;
}
return Obx(
() => controller.loading.value
? const LoadingIndicator(common: true)
: controller.list[ind].isEmpty
: controller.inoutList.isEmpty
? Center(
child: Text(
TextEnum.noInventoryInout,
@ -57,11 +50,10 @@ class Grid extends StatelessWidget {
: MasonryGridView.count(
padding: EdgeInsets.only(top: ScreenAdaper.height(60)),
crossAxisCount: columnNum,
itemCount: controller.list[ind].length,
itemCount: controller.inoutList.length,
itemBuilder: (context, index) {
return InventoryInoutCard(
index: index,
ind: ind,
);
},
),

View File

@ -19,17 +19,8 @@ class InventoryInoutController extends GetxController {
final PageController pageController = PageController();
Rx<DateTime> endTime = Rx<DateTime>(DateTime.now());
final DbHelper db = DbHelper();
List<RxList<InventoryInOutModel>> list = [
<InventoryInOutModel>[].obs,
<InventoryInOutModel>[].obs,
<InventoryInOutModel>[].obs,
<InventoryInOutModel>[].obs,
<InventoryInOutModel>[].obs,
<InventoryInOutModel>[].obs,
<InventoryInOutModel>[].obs,
].obs;
RxList<InventoryInOutModel> inoutList = <InventoryInOutModel>[].obs;
RxInt barIndex = 0.obs;
RxList model = [].obs;
final ScrollController scrollController = ScrollController();
final RefreshController refreshController = RefreshController();
final daysNum = 20;
@ -242,7 +233,7 @@ class InventoryInoutController extends GetxController {
).then((value) => {Get.delete<InventoryInouInfoController>()});
}
Future<List<InventoryInOutModel>> getInoutHistory() async {
Future<void> getInoutHistory() async {
loading.value = true;
await Future.delayed(const Duration(milliseconds: 500));
final selectedDate = SkDateUtil.format(
@ -252,24 +243,17 @@ class InventoryInoutController extends GetxController {
'time': [selectedDate, selectedDate]
});
if (res.data != null) {
return res.data!.items
inoutList.assignAll(res.data!.items
.map((e) => InventoryInOutModel.fromJson(e))
.toList();
.toList());
}
return [];
} catch (e) {
print(e);
return [];
} finally {
loading.value = false;
}
}
getData() async {
getInoutHistory().then((value) {
model.value = value;
getSepretLists();
});
await getInoutHistory();
}
setEndTime(DateTime newEndTime) async {
@ -292,23 +276,6 @@ class InventoryInoutController extends GetxController {
endTime.value.add(Duration(days: -(daysNum - value))));
}
getSepretLists() {
List<RxList<InventoryInOutModel>> tempList = [];
for (int i = daysNum; i > 0; i--) {
RxList<InventoryInOutModel> tempList1 = <InventoryInOutModel>[].obs;
tempList1.clear();
for (int j = 0; j < model.length; j++) {
final sourceDateStr = SkDateUtil.format(model[j].time);
final currentDateStr = getDateAccordingTabs(i);
if (sourceDateStr == currentDateStr) {
tempList1.add(model[j]);
}
}
tempList.add(tempList1);
}
list.assignAll(tempList);
}
onMoveNextPage() {
if (currentIndex.value > 0) {
setIndex(currentIndex.value - 1);

View File

@ -538,7 +538,7 @@ class SaleQuotationPage extends StatelessWidget {
alignment: Alignment.center,
width: ScreenAdaper.width(unitPriceWidth),
child: Text(
CommonUtil.toNumberWithout0(controller
CommonUtil.toNumberWithoutZero(controller
.groups[groupIndex].items[rowIndex].unitPrice),
style: TextStyle(fontSize: ScreenAdaper.height(25)),
),
@ -553,7 +553,7 @@ class SaleQuotationPage extends StatelessWidget {
alignment: Alignment.center,
width: ScreenAdaper.width(amountWidth),
child: Text(
CommonUtil.toNumberWithout0(
CommonUtil.toNumberWithoutZero(
controller.groups[groupIndex].items[rowIndex].amount),
style: TextStyle(fontSize: ScreenAdaper.height(25)),
),
@ -607,8 +607,9 @@ class SaleQuotationPage extends StatelessWidget {
horizontal: ScreenAdaper.width(20),
vertical: ScreenAdaper.height(10)),
textController: TextEditingController(
text:
value == 0 ? '' : CommonUtil.toNumberWithout0(value))),
text: value == 0
? ''
: CommonUtil.toNumberWithoutZero(value))),
)
: InkWell(
onTap: () {

View File

@ -127,7 +127,7 @@ class DioService extends get_package.GetxService {
}
void onResponse(Response response, ResponseInterceptorHandler handler) async {
/* LoggerUtil().info('[Service-dio] ${response.data}'); */
LoggerUtil().info('[Service-dio] ${response.data}');
if (whiteList.firstWhereOrNull(
(item) => response.requestOptions.path.contains(item)) !=

View File

@ -37,9 +37,13 @@ class CommonUtil {
return result;
}
static String toNumberWithout0(num num) {
static String toNumberWithoutZero(num num) {
return num.toStringAsFixed(num.truncateToDouble() == num ? 0 : 2);
}
static String addZeroOnFront(num num) {
return num.toString().padLeft(2, '0');
}
}
class TreeNode<T> {

View File

@ -2,14 +2,57 @@ import 'dart:io';
import 'dart:typed_data';
import 'package:dio/dio.dart' as dio_package;
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:sk_base_mobile/apis/api.dart';
import 'package:image_picker/image_picker.dart';
import 'package:sk_base_mobile/app_theme.dart';
import 'package:sk_base_mobile/config.dart';
import 'package:sk_base_mobile/models/upload_result.model.dart';
import 'package:sk_base_mobile/router/router.util.dart';
import 'package:sk_base_mobile/services/service.dart';
class MediaUtil {
///
showPicker({Function(String?)? callback, String title = '请选择上传方式'}) async {
await showCupertinoModalPopup(
context: Get.overlayContext!,
builder: (BuildContext ctx) {
return CupertinoActionSheet(
title: Text(title),
cancelButton: CupertinoActionSheetAction(
onPressed: () {
RouterUtil.back();
},
child: const Text(
'取消',
style: TextStyle(color: Color(0xffcdcdcd)),
)),
actions: ['拍照', '相册']
.map((item) => CupertinoActionSheetAction(
onPressed: () async {
await RouterUtil.back();
XFile? pickedFile = item == '拍照'
? await MediaUtil().getImageFromCamera()
: await MediaUtil().getImageFromGallery();
if (pickedFile != null) {
if (callback != null) {
callback(pickedFile.path);
}
}
},
child: Text(
item,
style: const TextStyle(color: AppTheme.primaryColor),
)))
.toList(),
);
});
}
static String getMediaUrl(String? url) {
if ((url ?? '').isEmpty) {
return '';
@ -28,6 +71,7 @@ class MediaUtil {
}
AppInfoService.to.isCameraing.value = true;
pickedFile = await ImagePicker().pickImage(
imageQuality: 40,
source: ImageSource.camera,
maxWidth: maxWidth ?? 2000,
preferredCameraDevice:
@ -46,7 +90,7 @@ class MediaUtil {
}
AppInfoService.to.isCameraing.value = true;
XFile? pickedFile = await ImagePicker()
.pickImage(source: ImageSource.gallery, imageQuality: 60);
.pickImage(source: ImageSource.gallery, imageQuality: 40);
AppInfoService.to.isCameraing.value = false;
return pickedFile;
}

View File

@ -1,44 +0,0 @@
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:sk_base_mobile/router/router.util.dart';
import 'package:sk_base_mobile/util/media_util.dart';
import 'package:sk_base_mobile/app_theme.dart';
class PhotoPickerUtil {
showPicker({Function? callback, String title = '请选择上传方式'}) async {
return showCupertinoModalPopup(
context: Get.context!,
builder: (BuildContext ctx) {
return CupertinoActionSheet(
title: Text(title),
cancelButton: CupertinoActionSheetAction(
onPressed: () {
RouterUtil.back();
},
child: const Text(
'取消',
style: TextStyle(color: Color(0xffcdcdcd)),
)),
actions: ['拍照', '相册']
.map((item) => CupertinoActionSheetAction(
onPressed: () async {
await RouterUtil.back();
XFile? pickedFile = item == '拍照'
? await MediaUtil().getImageFromCamera()
: await MediaUtil().getImageFromGallery();
if (pickedFile != null) {
if (callback != null) {
callback(pickedFile);
}
}
},
child: Text(
item,
style: const TextStyle(color: AppTheme.primaryColor),
)))
.toList(),
);
});
}
}

View File

@ -3,7 +3,6 @@ library store;
export 'snack_bar.util.dart';
export 'loading_util.dart';
export 'media_util.dart';
export 'photo_picker_util.dart';
export 'screen_adaper_util.dart';
export 'validator_util.dart';
export 'date.util.dart';

View File

@ -47,7 +47,10 @@ class SkBaseDatePicker extends StatelessWidget {
if (int.parse(month) < 10) {
month = '0$month';
}
final day = dayController.selectedItem + 1;
String day = '${dayController.selectedItem + 1}';
if (int.parse(day) < 10) {
day = '0$day';
}
if (onDateTimeChanged != null) {
onDateTimeChanged!('$year-$month-$day');
}

View File

@ -69,7 +69,7 @@ class MyAvatarWidget extends StatelessWidget {
class MyAvatarController extends GetxController {
final uploadImgFilePath = ''.obs;
Future<void> photoPicker() async {
await PhotoPickerUtil().showPicker(callback: (XFile pickedFile) async {
await MediaUtil().showPicker(callback: (String? pickedFile) async {
await LoadingUtil.to.show(status: 'Uploading...');
try {
// UploadResultModel? res = await MediaUtil().uploadImg(File(pickedFile.path));

View File

@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.devz
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.3+1
version: 1.0.4+1
environment:
sdk: '>=3.2.6 <4.0.0'