1. 添加接口返回值
2. 解决返回类型冲突
This commit is contained in:
parent
93e30361a8
commit
b16427f208
11
lib/app/enum/wms_api_response_code.dart
Normal file
11
lib/app/enum/wms_api_response_code.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
enum WmsApiResponseCode {
|
||||||
|
success(code: 0, message: "成功"),
|
||||||
|
warning(code: 400, message: "警告"),
|
||||||
|
fail(code: 500, message: "失败"),
|
||||||
|
error(code: 999, message: "错误");
|
||||||
|
|
||||||
|
final int code;
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
const WmsApiResponseCode({required this.code, required this.message});
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle;
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import '../../features/page/domain/models/base_wms_api_response.dart';
|
||||||
import '/features/page/business_logic/notifiers/page_repository_notifier.dart';
|
import '/features/page/business_logic/notifiers/page_repository_notifier.dart';
|
||||||
import '/features/page/data/repositories/page_repository_impl.dart';
|
import '/features/page/data/repositories/page_repository_impl.dart';
|
||||||
import '/features/page/domain/repositories/page_repository.dart';
|
import '/features/page/domain/repositories/page_repository.dart';
|
||||||
|
|
@ -12,6 +13,7 @@ import '../api/config/api_config.dart';
|
||||||
import '../../features/stock/data/repositories/stock_repository_impl.dart';
|
import '../../features/stock/data/repositories/stock_repository_impl.dart';
|
||||||
import '../../features/stock/domain/repositories/stock_repository.dart';
|
import '../../features/stock/domain/repositories/stock_repository.dart';
|
||||||
import '../../features/stock/business_logic/notifiers/stock_in_empty_notifier.dart';
|
import '../../features/stock/business_logic/notifiers/stock_in_empty_notifier.dart';
|
||||||
|
import '../../features/stock/domain/models/base_wms_api_response.dart';
|
||||||
|
|
||||||
final _defaultApiConfig = ApiConfig.fromYaml('''
|
final _defaultApiConfig = ApiConfig.fromYaml('''
|
||||||
wms:
|
wms:
|
||||||
|
|
@ -48,34 +50,34 @@ final pageRepositoryProvider = Provider<PageRepository>((ref) {
|
||||||
return PageRepositoryImpl(wmsApiClient: apiClient);
|
return PageRepositoryImpl(wmsApiClient: apiClient);
|
||||||
});
|
});
|
||||||
|
|
||||||
final stockInEmptyNotifierProvider =
|
final stockInEmptyNotifierProvider = StateNotifierProvider.autoDispose<
|
||||||
StateNotifierProvider.autoDispose<StockInEmptyNotifier, AsyncValue<void>>((
|
StockInEmptyNotifier,
|
||||||
ref,
|
AsyncValue<StockBaseWmsApiResponse?>
|
||||||
) {
|
>((ref) {
|
||||||
final repository = ref.watch(stockRepositoryProvider);
|
final repository = ref.watch(stockRepositoryProvider);
|
||||||
return StockInEmptyNotifier(repository);
|
return StockInEmptyNotifier(repository);
|
||||||
});
|
});
|
||||||
|
|
||||||
final stockInNotifierProvider =
|
final stockInNotifierProvider = StateNotifierProvider.autoDispose<
|
||||||
StateNotifierProvider.autoDispose<StockInManualNotifier, AsyncValue<void>>((
|
StockInManualNotifier,
|
||||||
ref,
|
AsyncValue<StockBaseWmsApiResponse?>
|
||||||
) {
|
>((ref) {
|
||||||
final repository = ref.watch(stockRepositoryProvider);
|
final repository = ref.watch(stockRepositoryProvider);
|
||||||
return StockInManualNotifier(repository);
|
return StockInManualNotifier(repository);
|
||||||
});
|
});
|
||||||
|
|
||||||
final pageNotifierProvider =
|
final pageNotifierProvider = StateNotifierProvider.autoDispose<
|
||||||
StateNotifierProvider.autoDispose<PageRepositoryNotifier, AsyncValue<void>>(
|
PageRepositoryNotifier,
|
||||||
(ref) {
|
AsyncValue<PageBaseWmsApiResponse?>
|
||||||
final repository = ref.watch(pageRepositoryProvider);
|
>((ref) {
|
||||||
return PageRepositoryNotifier(repository);
|
final repository = ref.watch(pageRepositoryProvider);
|
||||||
},
|
return PageRepositoryNotifier(repository);
|
||||||
);
|
});
|
||||||
|
|
||||||
final stockOutEmptyNotifierProvider =
|
final stockOutEmptyNotifierProvider = StateNotifierProvider.autoDispose<
|
||||||
StateNotifierProvider.autoDispose<StockOutEmptyNotifier, AsyncValue<void>>((
|
StockOutEmptyNotifier,
|
||||||
ref,
|
AsyncValue<StockBaseWmsApiResponse?>
|
||||||
) {
|
>((ref) {
|
||||||
final repository = ref.watch(stockRepositoryProvider);
|
final repository = ref.watch(stockRepositoryProvider);
|
||||||
return StockOutEmptyNotifier(repository);
|
return StockOutEmptyNotifier(repository);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:pda_template/features/page/domain/repositories/page_repository.dart';
|
import '/features/page/domain/models/base_wms_api_response.dart';
|
||||||
|
import '/features/page/domain/repositories/page_repository.dart';
|
||||||
import '../../../../core/di/providers.dart';
|
import '../../../../core/di/providers.dart';
|
||||||
|
|
||||||
class PageRepositoryNotifier extends StateNotifier<AsyncValue<void>> {
|
class PageRepositoryNotifier
|
||||||
|
extends StateNotifier<AsyncValue<PageBaseWmsApiResponse?>> {
|
||||||
final PageRepository _repository;
|
final PageRepository _repository;
|
||||||
|
|
||||||
PageRepositoryNotifier(this._repository) : super(const AsyncValue.data(null));
|
PageRepositoryNotifier(this._repository) : super(const AsyncValue.data(null));
|
||||||
|
|
@ -10,18 +12,18 @@ class PageRepositoryNotifier extends StateNotifier<AsyncValue<void>> {
|
||||||
Future<void> submit() async {
|
Future<void> submit() async {
|
||||||
state = const AsyncValue.loading();
|
state = const AsyncValue.loading();
|
||||||
try {
|
try {
|
||||||
await _repository.testLink();
|
final response = await _repository.testLink();
|
||||||
state = const AsyncValue.data(null);
|
state = AsyncValue.data(response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
state = AsyncValue.error(e, StackTrace.current);
|
state = AsyncValue.error(e, StackTrace.current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final pageNotifierProvider =
|
final pageNotifierProvider = StateNotifierProvider.autoDispose<
|
||||||
StateNotifierProvider.autoDispose<PageRepositoryNotifier, AsyncValue<void>>((
|
PageRepositoryNotifier,
|
||||||
ref,
|
AsyncValue<PageBaseWmsApiResponse?>
|
||||||
) {
|
>((ref) {
|
||||||
final repository = ref.watch(pageRepositoryProvider);
|
final repository = ref.watch(pageRepositoryProvider);
|
||||||
return PageRepositoryNotifier(repository);
|
return PageRepositoryNotifier(repository);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import 'package:pda_template/core/api/clients/wms_api_client.dart';
|
import 'package:pda_template/core/api/clients/wms_api_client.dart';
|
||||||
import 'package:pda_template/features/page/domain/repositories/page_repository.dart';
|
import 'package:pda_template/features/page/domain/repositories/page_repository.dart';
|
||||||
import '../../../stock/domain/models/base_wms_api_response.dart';
|
import '../../domain/models/base_wms_api_response.dart';
|
||||||
|
|
||||||
|
|
||||||
class PageRepositoryImpl extends PageRepository {
|
class PageRepositoryImpl extends PageRepository {
|
||||||
final WmsApiClient wmsApiClient;
|
final WmsApiClient wmsApiClient;
|
||||||
|
|
@ -9,7 +8,7 @@ class PageRepositoryImpl extends PageRepository {
|
||||||
PageRepositoryImpl({required this.wmsApiClient});
|
PageRepositoryImpl({required this.wmsApiClient});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<BaseWmsApiResponse> testLink() {
|
Future<PageBaseWmsApiResponse> testLink() {
|
||||||
return wmsApiClient.testLink().then((value) => BaseWmsApiResponse.fromDto(value));
|
return wmsApiClient.testLink().then((value) => PageBaseWmsApiResponse.fromDto(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
import '../../../../core/api/models/responses/base_wms_api_response_dto.dart';
|
import '/core/api/models/responses/base_wms_api_response_dto.dart';
|
||||||
|
|
||||||
class BaseWmsApiResponse {
|
class PageBaseWmsApiResponse {
|
||||||
final int code;
|
final int code;
|
||||||
final String message;
|
final String message;
|
||||||
|
|
||||||
BaseWmsApiResponse({required this.code, required this.message});
|
PageBaseWmsApiResponse({required this.code, required this.message});
|
||||||
|
|
||||||
factory BaseWmsApiResponse.fromJson(Map<String, dynamic> json) {
|
factory PageBaseWmsApiResponse.fromJson(Map<String, dynamic> json) {
|
||||||
return BaseWmsApiResponse(
|
return PageBaseWmsApiResponse(
|
||||||
code: int.parse(json['code'].toString()),
|
code: int.parse(json['code'].toString()),
|
||||||
message: json['message'].toString(),
|
message: json['message'].toString(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory BaseWmsApiResponse.fromDto(BaseWmsApiResponseDto dto) {
|
factory PageBaseWmsApiResponse.fromDto(BaseWmsApiResponseDto dto) {
|
||||||
return BaseWmsApiResponse(
|
return PageBaseWmsApiResponse(
|
||||||
code: dto.code,
|
code: dto.code,
|
||||||
message: dto.message,
|
message: dto.message,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import '../../../stock/domain/models/base_wms_api_response.dart';
|
import '../models/base_wms_api_response.dart';
|
||||||
|
|
||||||
abstract class PageRepository {
|
abstract class PageRepository {
|
||||||
Future<BaseWmsApiResponse> testLink();
|
Future<PageBaseWmsApiResponse> testLink();
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:bruno/bruno.dart';
|
import 'package:bruno/bruno.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:pda_template/app/enum/wms_api_response_code.dart';
|
||||||
|
import '/features/page/domain/models/base_wms_api_response.dart';
|
||||||
import 'package:yaml/yaml.dart';
|
import 'package:yaml/yaml.dart';
|
||||||
import '../../../app/enum/config_path_enum.dart';
|
import '../../../app/enum/config_path_enum.dart';
|
||||||
import '../../../core/di/providers.dart';
|
import '../../../core/di/providers.dart';
|
||||||
|
|
@ -21,7 +23,7 @@ class _HomePageState extends ConsumerState<Home> {
|
||||||
List<BrnDoughnutDataItem> stockChartsData = [];
|
List<BrnDoughnutDataItem> stockChartsData = [];
|
||||||
late Color primaryColor;
|
late Color primaryColor;
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
AsyncValue<void>? _previousState;
|
AsyncValue<PageBaseWmsApiResponse?>? _previousState;
|
||||||
bool _hasSubmitted = false;
|
bool _hasSubmitted = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -213,24 +215,36 @@ class _HomePageState extends ConsumerState<Home> {
|
||||||
ref.read(pageNotifierProvider.notifier).submit();
|
ref.read(pageNotifierProvider.notifier).submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleState(AsyncValue<void> state) {
|
void _handleState(AsyncValue<PageBaseWmsApiResponse?> state) {
|
||||||
state.whenOrNull(
|
state.whenOrNull(
|
||||||
loading: () => BrnLoadingDialog.show(context, content: "正在请求"),
|
loading: () => BrnLoadingDialog.show(context, content: "正在请求"),
|
||||||
error: (error, _) {
|
error: (error, _) {
|
||||||
BrnLoadingDialog.dismiss(context);
|
BrnLoadingDialog.dismiss(context);
|
||||||
DialogUtils.showErrorMessage(context, "请求发生错误", error.toString());
|
DialogUtils.showErrorMessage(context, "请求发生错误", error.toString());
|
||||||
|
_hasSubmitted = false;
|
||||||
},
|
},
|
||||||
data: (_) {
|
data: (response) {
|
||||||
BrnLoadingDialog.dismiss(context);
|
BrnLoadingDialog.dismiss(context);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
if (response != null &&
|
||||||
SnackBar(
|
response.code == WmsApiResponseCode.success.code) {
|
||||||
content: Text("请求成功"),
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
duration: const Duration(seconds: 2),
|
SnackBar(
|
||||||
behavior: SnackBarBehavior.floating,
|
content: Text("请求成功"),
|
||||||
backgroundColor: Colors.green,
|
duration: const Duration(seconds: 2),
|
||||||
margin: const EdgeInsets.only(bottom: 100, left: 20, right: 20),
|
behavior: SnackBarBehavior.floating,
|
||||||
),
|
backgroundColor: Colors.green,
|
||||||
);
|
margin: const EdgeInsets.only(bottom: 100, left: 20, right: 20),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
_hasSubmitted = false;
|
||||||
|
} else if (response != null) {
|
||||||
|
DialogUtils.showWarningMessage(
|
||||||
|
context,
|
||||||
|
"操作未成功",
|
||||||
|
"${response.message} ${response.code.toString()}",
|
||||||
|
btnLabel: "返回",
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import '../../../../core/di/providers.dart';
|
import '../../../../core/di/providers.dart';
|
||||||
import '../../domain/models/stock_in_request.dart';
|
import '../../domain/models/stock_in_request.dart';
|
||||||
import '../../domain/repositories/stock_repository.dart';
|
import '../../domain/repositories/stock_repository.dart';
|
||||||
|
import '../../domain/models/base_wms_api_response.dart';
|
||||||
|
|
||||||
class StockInEmptyNotifier extends StateNotifier<AsyncValue<void>> {
|
class StockInEmptyNotifier
|
||||||
|
extends StateNotifier<AsyncValue<StockBaseWmsApiResponse?>> {
|
||||||
final StockRepository _repository;
|
final StockRepository _repository;
|
||||||
|
|
||||||
StockInEmptyNotifier(this._repository) : super(const AsyncValue.data(null));
|
StockInEmptyNotifier(this._repository) : super(const AsyncValue.data(null));
|
||||||
|
|
@ -14,7 +16,7 @@ class StockInEmptyNotifier extends StateNotifier<AsyncValue<void>> {
|
||||||
}) async {
|
}) async {
|
||||||
state = const AsyncValue.loading();
|
state = const AsyncValue.loading();
|
||||||
try {
|
try {
|
||||||
await _repository.requireStockIn(
|
final response = await _repository.requireStockIn(
|
||||||
StockInRequest(
|
StockInRequest(
|
||||||
emptyTask: true,
|
emptyTask: true,
|
||||||
vehicleId: vehicleId,
|
vehicleId: vehicleId,
|
||||||
|
|
@ -23,17 +25,17 @@ class StockInEmptyNotifier extends StateNotifier<AsyncValue<void>> {
|
||||||
origin: standId,
|
origin: standId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
state = const AsyncValue.data(null);
|
state = AsyncValue.data(response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
state = AsyncValue.error(e, StackTrace.current);
|
state = AsyncValue.error(e, StackTrace.current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final stockEmptyInNotifierProvider =
|
final stockEmptyInNotifierProvider = StateNotifierProvider.autoDispose<
|
||||||
StateNotifierProvider.autoDispose<StockInEmptyNotifier, AsyncValue<void>>((
|
StockInEmptyNotifier,
|
||||||
ref,
|
AsyncValue<StockBaseWmsApiResponse?>
|
||||||
) {
|
>((ref) {
|
||||||
final repository = ref.watch(stockRepositoryProvider);
|
final repository = ref.watch(stockRepositoryProvider);
|
||||||
return StockInEmptyNotifier(repository);
|
return StockInEmptyNotifier(repository);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:pda_template/features/stock/domain/models/base_wms_api_response.dart';
|
||||||
import '../../../../core/di/providers.dart';
|
import '../../../../core/di/providers.dart';
|
||||||
import '../../domain/models/goodsInfo_for_task.dart';
|
import '../../domain/models/goodsInfo_for_task.dart';
|
||||||
import '/features/stock/domain/repositories/stock_repository.dart';
|
import '/features/stock/domain/repositories/stock_repository.dart';
|
||||||
import '../../domain/models/stock_in_request.dart';
|
import '../../domain/models/stock_in_request.dart';
|
||||||
|
|
||||||
class StockInManualNotifier extends StateNotifier<AsyncValue<void>> {
|
class StockInManualNotifier
|
||||||
|
extends StateNotifier<AsyncValue<StockBaseWmsApiResponse?>> {
|
||||||
final StockRepository _repository;
|
final StockRepository _repository;
|
||||||
|
|
||||||
StockInManualNotifier(this._repository) : super(const AsyncValue.data(null));
|
StockInManualNotifier(this._repository) : super(const AsyncValue.data(null));
|
||||||
|
|
@ -16,7 +18,7 @@ class StockInManualNotifier extends StateNotifier<AsyncValue<void>> {
|
||||||
}) async {
|
}) async {
|
||||||
state = const AsyncValue.loading();
|
state = const AsyncValue.loading();
|
||||||
try {
|
try {
|
||||||
await _repository.requireStockIn(
|
final response = await _repository.requireStockIn(
|
||||||
StockInRequest(
|
StockInRequest(
|
||||||
emptyTask: false,
|
emptyTask: false,
|
||||||
vehicleId: vehicleId,
|
vehicleId: vehicleId,
|
||||||
|
|
@ -25,17 +27,17 @@ class StockInManualNotifier extends StateNotifier<AsyncValue<void>> {
|
||||||
origin: standId,
|
origin: standId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
state = const AsyncValue.data(null);
|
state = AsyncValue.data(response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
state = AsyncValue.error(e, StackTrace.current);
|
state = AsyncValue.error(e, StackTrace.current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final stockInNotifierProvider =
|
final stockInNotifierProvider = StateNotifierProvider.autoDispose<
|
||||||
StateNotifierProvider.autoDispose<StockInManualNotifier, AsyncValue<void>>((
|
StockInManualNotifier,
|
||||||
ref,
|
AsyncValue<StockBaseWmsApiResponse?>
|
||||||
) {
|
>((ref) {
|
||||||
final repository = ref.watch(stockRepositoryProvider);
|
final repository = ref.watch(stockRepositoryProvider);
|
||||||
return StockInManualNotifier(repository);
|
return StockInManualNotifier(repository);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:pda_template/features/stock/domain/repositories/stock_repository.dart';
|
import '/features/stock/domain/models/base_wms_api_response.dart';
|
||||||
|
import '/features/stock/domain/repositories/stock_repository.dart';
|
||||||
import '/core/di/providers.dart';
|
import '/core/di/providers.dart';
|
||||||
|
|
||||||
class StockOutEmptyNotifier extends StateNotifier<AsyncValue<void>> {
|
class StockOutEmptyNotifier extends StateNotifier<AsyncValue<StockBaseWmsApiResponse?>> {
|
||||||
final StockRepository repository;
|
final StockRepository repository;
|
||||||
|
|
||||||
StockOutEmptyNotifier(this.repository) : super(const AsyncValue.data(null));
|
StockOutEmptyNotifier(this.repository) : super(const AsyncValue.data(null));
|
||||||
|
|
@ -13,11 +14,11 @@ class StockOutEmptyNotifier extends StateNotifier<AsyncValue<void>> {
|
||||||
}) async {
|
}) async {
|
||||||
state = const AsyncValue.loading();
|
state = const AsyncValue.loading();
|
||||||
try {
|
try {
|
||||||
await repository.emptyStockOut(
|
final response = await repository.emptyStockOut(
|
||||||
needNum: needNum,
|
needNum: needNum,
|
||||||
destination: destination,
|
destination: destination,
|
||||||
);
|
);
|
||||||
state = const AsyncValue.data(null);
|
state = AsyncValue.data(response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
state = AsyncValue.error(e, StackTrace.current);
|
state = AsyncValue.error(e, StackTrace.current);
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +26,7 @@ class StockOutEmptyNotifier extends StateNotifier<AsyncValue<void>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
final stockEmptyOutNotifierProvider =
|
final stockEmptyOutNotifierProvider =
|
||||||
StateNotifierProvider.autoDispose<StockOutEmptyNotifier, AsyncValue<void>>((
|
StateNotifierProvider.autoDispose<StockOutEmptyNotifier, AsyncValue<StockBaseWmsApiResponse?>>((
|
||||||
ref,
|
ref,
|
||||||
) {
|
) {
|
||||||
final repository = ref.watch(stockRepositoryProvider);
|
final repository = ref.watch(stockRepositoryProvider);
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@ class StockRepositoryImpl implements StockRepository {
|
||||||
StockRepositoryImpl({required this.wmsApiClient});
|
StockRepositoryImpl({required this.wmsApiClient});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<BaseWmsApiResponse> requireStockIn(StockInRequest request) {
|
Future<StockBaseWmsApiResponse> requireStockIn(StockInRequest request) {
|
||||||
return wmsApiClient
|
return wmsApiClient
|
||||||
.requireStockIn(request.toDto())
|
.requireStockIn(request.toDto())
|
||||||
.then((value) => BaseWmsApiResponse.fromDto(value));
|
.then((value) => StockBaseWmsApiResponse.fromDto(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<BaseWmsApiResponse> emptyStockIn({
|
Future<StockBaseWmsApiResponse> emptyStockIn({
|
||||||
required String vehicleId,
|
required String vehicleId,
|
||||||
required String standId,
|
required String standId,
|
||||||
required String origin,
|
required String origin,
|
||||||
|
|
@ -32,11 +32,11 @@ class StockRepositoryImpl implements StockRepository {
|
||||||
);
|
);
|
||||||
return wmsApiClient
|
return wmsApiClient
|
||||||
.requireStockIn(request.toDto())
|
.requireStockIn(request.toDto())
|
||||||
.then((value) => BaseWmsApiResponse.fromDto(value));
|
.then((value) => StockBaseWmsApiResponse.fromDto(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<BaseWmsApiResponse> emptyStockOut({
|
Future<StockBaseWmsApiResponse> emptyStockOut({
|
||||||
required int needNum,
|
required int needNum,
|
||||||
required String destination,
|
required String destination,
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -51,6 +51,6 @@ class StockRepositoryImpl implements StockRepository {
|
||||||
);
|
);
|
||||||
return wmsApiClient
|
return wmsApiClient
|
||||||
.requireStockOut(request.toDto())
|
.requireStockOut(request.toDto())
|
||||||
.then((value) => BaseWmsApiResponse.fromDto(value));
|
.then((value) => StockBaseWmsApiResponse.fromDto(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,20 @@
|
||||||
import '../../../../core/api/models/responses/base_wms_api_response_dto.dart';
|
import '../../../../core/api/models/responses/base_wms_api_response_dto.dart';
|
||||||
|
|
||||||
class BaseWmsApiResponse {
|
class StockBaseWmsApiResponse {
|
||||||
final int code;
|
final int code;
|
||||||
final String message;
|
final String message;
|
||||||
|
|
||||||
BaseWmsApiResponse({required this.code, required this.message});
|
StockBaseWmsApiResponse({required this.code, required this.message});
|
||||||
|
|
||||||
factory BaseWmsApiResponse.fromJson(Map<String, dynamic> json) {
|
factory StockBaseWmsApiResponse.fromJson(Map<String, dynamic> json) {
|
||||||
return BaseWmsApiResponse(
|
return StockBaseWmsApiResponse(
|
||||||
code: int.parse(json['code'].toString()),
|
code: int.parse(json['code'].toString()),
|
||||||
message: json['message'].toString(),
|
message: json['message'].toString(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory BaseWmsApiResponse.fromDto(BaseWmsApiResponseDto dto) {
|
factory StockBaseWmsApiResponse.fromDto(BaseWmsApiResponseDto dto) {
|
||||||
return BaseWmsApiResponse(
|
return StockBaseWmsApiResponse(
|
||||||
code: dto.code,
|
code: dto.code,
|
||||||
message: dto.message,
|
message: dto.message,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ import '../models/stock_in_request.dart';
|
||||||
import '../models/base_wms_api_response.dart';
|
import '../models/base_wms_api_response.dart';
|
||||||
|
|
||||||
abstract class StockRepository {
|
abstract class StockRepository {
|
||||||
Future<BaseWmsApiResponse> emptyStockIn({required String vehicleId, required String standId, required String origin});
|
Future<StockBaseWmsApiResponse> emptyStockIn({required String vehicleId, required String standId, required String origin});
|
||||||
|
|
||||||
Future<BaseWmsApiResponse> requireStockIn(StockInRequest request);
|
Future<StockBaseWmsApiResponse> requireStockIn(StockInRequest request);
|
||||||
|
|
||||||
Future<BaseWmsApiResponse> emptyStockOut({required int needNum, required String destination});
|
Future<StockBaseWmsApiResponse> emptyStockOut({required int needNum, required String destination});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:bruno/bruno.dart';
|
import 'package:bruno/bruno.dart';
|
||||||
|
import 'package:pda_template/app/enum/wms_api_response_code.dart';
|
||||||
|
import 'package:pda_template/app/enum/wms_out_type.dart';
|
||||||
import 'package:pda_template/core/di/providers.dart' as app_providers;
|
import 'package:pda_template/core/di/providers.dart' as app_providers;
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle;
|
||||||
import 'package:yaml/yaml.dart';
|
import 'package:yaml/yaml.dart';
|
||||||
import '../../../../app/enum/config_path_enum.dart';
|
import '../../../../app/enum/config_path_enum.dart';
|
||||||
import '../../../../app/enum/stand.dart';
|
import '../../../../app/enum/stand.dart';
|
||||||
import '../../../../core/utils/extensions/dialogUtils.dart';
|
import '../../../../core/utils/extensions/dialogUtils.dart';
|
||||||
|
import '../../domain/models/base_wms_api_response.dart';
|
||||||
|
|
||||||
class StockInEmpty extends ConsumerStatefulWidget {
|
class StockInEmpty extends ConsumerStatefulWidget {
|
||||||
const StockInEmpty({super.key});
|
const StockInEmpty({super.key});
|
||||||
|
|
@ -20,7 +23,7 @@ class _StockInEmptyPageState extends ConsumerState<StockInEmpty> {
|
||||||
Stand? _selectedStand;
|
Stand? _selectedStand;
|
||||||
late Color primaryColor;
|
late Color primaryColor;
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
AsyncValue<void>? _previousState;
|
AsyncValue<StockBaseWmsApiResponse?>? _previousState;
|
||||||
bool _hasSubmitted = false;
|
bool _hasSubmitted = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -33,16 +36,12 @@ class _StockInEmptyPageState extends ConsumerState<StockInEmpty> {
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
|
|
||||||
// 获取当前状态
|
|
||||||
final currentState = ref.read(app_providers.stockInEmptyNotifierProvider);
|
final currentState = ref.read(app_providers.stockInEmptyNotifierProvider);
|
||||||
|
|
||||||
// 只有在状态变化且已提交过请求时才处理状态
|
|
||||||
if (_previousState != currentState && _hasSubmitted) {
|
if (_previousState != currentState && _hasSubmitted) {
|
||||||
_previousState = currentState;
|
_previousState = currentState;
|
||||||
// 使用Future.microtask确保在build完成后处理状态
|
|
||||||
Future.microtask(() => _handleState(currentState));
|
Future.microtask(() => _handleState(currentState));
|
||||||
} else {
|
} else {
|
||||||
// 仅保存初始状态,不处理
|
|
||||||
_previousState = currentState;
|
_previousState = currentState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -64,11 +63,9 @@ class _StockInEmptyPageState extends ConsumerState<StockInEmpty> {
|
||||||
return Scaffold(body: Center(child: CircularProgressIndicator()));
|
return Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监听状态变化,但不在build中处理
|
|
||||||
ref.listen(app_providers.stockInEmptyNotifierProvider, (previous, next) {
|
ref.listen(app_providers.stockInEmptyNotifierProvider, (previous, next) {
|
||||||
if (previous != next && _hasSubmitted) {
|
if (previous != next && _hasSubmitted) {
|
||||||
_previousState = next;
|
_previousState = next;
|
||||||
// 使用Future.microtask确保在build完成后处理状态
|
|
||||||
Future.microtask(() => _handleState(next));
|
Future.microtask(() => _handleState(next));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -192,18 +189,33 @@ class _StockInEmptyPageState extends ConsumerState<StockInEmpty> {
|
||||||
.submit(vehicleId: vehicleId, standId: standId!);
|
.submit(vehicleId: vehicleId, standId: standId!);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleState(AsyncValue<void> state) {
|
void _handleState(AsyncValue<StockBaseWmsApiResponse?> state) {
|
||||||
state.whenOrNull(
|
state.whenOrNull(
|
||||||
loading: () => BrnLoadingDialog.show(context, content: "正在请求"),
|
loading: () => BrnLoadingDialog.show(context, content: "正在请求"),
|
||||||
error: (error, _) {
|
error: (error, _) {
|
||||||
BrnLoadingDialog.dismiss(context);
|
BrnLoadingDialog.dismiss(context);
|
||||||
DialogUtils.showErrorMessage(context, "请求发生错误", error.toString());
|
DialogUtils.showErrorMessage(context, "请求发生错误", error.toString());
|
||||||
},
|
},
|
||||||
data: (_) {
|
data: (response) {
|
||||||
BrnLoadingDialog.dismiss(context);
|
BrnLoadingDialog.dismiss(context);
|
||||||
DialogUtils.showSuccessMessage(context, "成功", "入库成功", btnLabel: "我知道了");
|
if (response != null &&
|
||||||
_vehicleTextController.clear();
|
response.code == WmsApiResponseCode.success.code) {
|
||||||
setState(() => _selectedStand = null);
|
DialogUtils.showSuccessMessage(
|
||||||
|
context,
|
||||||
|
"成功",
|
||||||
|
"入库成功",
|
||||||
|
btnLabel: "我知道了",
|
||||||
|
);
|
||||||
|
_vehicleTextController.clear();
|
||||||
|
setState(() => _selectedStand = null);
|
||||||
|
} else if (response != null) {
|
||||||
|
DialogUtils.showWarningMessage(
|
||||||
|
context,
|
||||||
|
"操作未成功",
|
||||||
|
"${response.message} ${response.code.toString()}",
|
||||||
|
btnLabel: "返回",
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import 'package:bruno/bruno.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:pda_template/app/enum/wms_api_response_code.dart';
|
||||||
|
import 'package:pda_template/features/stock/domain/models/base_wms_api_response.dart';
|
||||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||||
import 'package:yaml/yaml.dart';
|
import 'package:yaml/yaml.dart';
|
||||||
import '../../../../app/enum/config_path_enum.dart';
|
import '../../../../app/enum/config_path_enum.dart';
|
||||||
|
|
@ -25,7 +27,7 @@ class _StockInManualPageState extends ConsumerState<StockInManual> {
|
||||||
Stand? _selectedStand;
|
Stand? _selectedStand;
|
||||||
late Color primaryColor;
|
late Color primaryColor;
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
AsyncValue<void>? _previousState;
|
AsyncValue<StockBaseWmsApiResponse?>? _previousState;
|
||||||
bool _hasSubmitted = false;
|
bool _hasSubmitted = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -90,7 +92,7 @@ class _StockInManualPageState extends ConsumerState<StockInManual> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleState(AsyncValue<void> state) {
|
void _handleState(AsyncValue<StockBaseWmsApiResponse?> state) {
|
||||||
state.whenOrNull(
|
state.whenOrNull(
|
||||||
loading: () => BrnLoadingDialog.show(context, content: "正在请求"),
|
loading: () => BrnLoadingDialog.show(context, content: "正在请求"),
|
||||||
error: (error, _) {
|
error: (error, _) {
|
||||||
|
|
@ -98,16 +100,25 @@ class _StockInManualPageState extends ConsumerState<StockInManual> {
|
||||||
DialogUtils.showErrorMessage(context, "请求发生错误", error.toString());
|
DialogUtils.showErrorMessage(context, "请求发生错误", error.toString());
|
||||||
_hasSubmitted = false;
|
_hasSubmitted = false;
|
||||||
},
|
},
|
||||||
data: (_) {
|
data: (response) {
|
||||||
BrnLoadingDialog.dismiss(context);
|
BrnLoadingDialog.dismiss(context);
|
||||||
DialogUtils.showSuccessMessage(context, "成功", "入库成功", btnLabel: "我知道了");
|
if (response != null && response.code == WmsApiResponseCode.success.code) {
|
||||||
_vehicleIdController.clear();
|
DialogUtils.showSuccessMessage(context, "成功", "入库成功", btnLabel: "我知道了");
|
||||||
_goodsCodeController.clear();
|
_vehicleIdController.clear();
|
||||||
goodsInfoList = [];
|
_goodsCodeController.clear();
|
||||||
setState(() {
|
goodsInfoList = [];
|
||||||
_selectedStand = null;
|
setState(() {
|
||||||
_hasSubmitted = false;
|
_selectedStand = null;
|
||||||
});
|
_hasSubmitted = false;
|
||||||
|
});
|
||||||
|
} else if (response != null) {
|
||||||
|
DialogUtils.showWarningMessage(
|
||||||
|
context,
|
||||||
|
"操作未成功",
|
||||||
|
"${response.message} ${response.code.toString()}",
|
||||||
|
btnLabel: "返回",
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +217,7 @@ class _StockInManualPageState extends ConsumerState<StockInManual> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ref.listen(app_providers.stockInNotifierProvider, (previous, next) {
|
ref.listen(app_providers.stockInNotifierProvider, (previous, next) {
|
||||||
if (_hasSubmitted) {
|
if (previous != next && _hasSubmitted) {
|
||||||
_previousState = next;
|
_previousState = next;
|
||||||
Future.microtask(() => _handleState(next));
|
Future.microtask(() => _handleState(next));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import 'package:bruno/bruno.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle;
|
||||||
|
import 'package:pda_template/app/enum/wms_api_response_code.dart';
|
||||||
|
import 'package:pda_template/features/stock/domain/models/base_wms_api_response.dart';
|
||||||
import 'package:yaml/yaml.dart';
|
import 'package:yaml/yaml.dart';
|
||||||
import '/app/enum/config_path_enum.dart';
|
import '/app/enum/config_path_enum.dart';
|
||||||
import '/app/enum/stand.dart';
|
import '/app/enum/stand.dart';
|
||||||
|
|
@ -26,7 +28,7 @@ class _StockOutEmptyPageState extends ConsumerState<StockOutEmpty> {
|
||||||
.map((stand) => BrnCommonActionSheetItem(stand.message))
|
.map((stand) => BrnCommonActionSheetItem(stand.message))
|
||||||
.toList();
|
.toList();
|
||||||
bool _hasSubmitted = false;
|
bool _hasSubmitted = false;
|
||||||
AsyncValue<void>? _previousState;
|
AsyncValue<StockBaseWmsApiResponse?>? _previousState;
|
||||||
late Color primaryColor;
|
late Color primaryColor;
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
|
|
||||||
|
|
@ -60,7 +62,7 @@ class _StockOutEmptyPageState extends ConsumerState<StockOutEmpty> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleState(AsyncValue<void> state) {
|
void _handleState(AsyncValue<StockBaseWmsApiResponse?> state) {
|
||||||
state.whenOrNull(
|
state.whenOrNull(
|
||||||
loading: () => BrnLoadingDialog.show(context, content: "正在请求"),
|
loading: () => BrnLoadingDialog.show(context, content: "正在请求"),
|
||||||
error: (error, _) {
|
error: (error, _) {
|
||||||
|
|
@ -68,18 +70,27 @@ class _StockOutEmptyPageState extends ConsumerState<StockOutEmpty> {
|
||||||
DialogUtils.showErrorMessage(context, "请求发生错误", error.toString());
|
DialogUtils.showErrorMessage(context, "请求发生错误", error.toString());
|
||||||
_hasSubmitted = false;
|
_hasSubmitted = false;
|
||||||
},
|
},
|
||||||
data: (_) {
|
data: (response) {
|
||||||
BrnLoadingDialog.dismiss(context);
|
BrnLoadingDialog.dismiss(context);
|
||||||
DialogUtils.showSuccessMessage(
|
if (response != null && response.code == WmsApiResponseCode.success.code) {
|
||||||
context,
|
DialogUtils.showSuccessMessage(
|
||||||
"成功",
|
context,
|
||||||
"空托已呼叫",
|
"成功",
|
||||||
btnLabel: "我知道了",
|
"空托已呼叫",
|
||||||
);
|
btnLabel: "我知道了",
|
||||||
setState(() {
|
);
|
||||||
selectedQuantity = 1;
|
setState(() {
|
||||||
_hasSubmitted = false;
|
selectedQuantity = 1;
|
||||||
});
|
_hasSubmitted = false;
|
||||||
|
});
|
||||||
|
} else if (response != null) {
|
||||||
|
DialogUtils.showWarningMessage(
|
||||||
|
context,
|
||||||
|
"操作未成功",
|
||||||
|
"${response.message} ${response.code.toString()}",
|
||||||
|
btnLabel: "返回",
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user