重构事件信息页面,移除不必要的加载状态和错误消息字段,简化状态管理逻辑;在扫码页面中增强选手信息查询功能,添加加载提示和错误处理。
This commit is contained in:
@@ -11,8 +11,6 @@ import 'package:recording_tool/shared/widgets/widgets.dart';
|
|||||||
class EventInfoPage extends ConsumerStatefulWidget {
|
class EventInfoPage extends ConsumerStatefulWidget {
|
||||||
const EventInfoPage({super.key, required this.playerId});
|
const EventInfoPage({super.key, required this.playerId});
|
||||||
final String playerId;
|
final String playerId;
|
||||||
static const mockRtmpUrl =
|
|
||||||
'rtmp://192.168.1.245:19090/蔡依婷vs夏志豪_空中格斗赛_高中组/蔡依婷vs夏志豪_空中格斗赛_高中组';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<EventInfoPage> createState() => _EventInfoPageState();
|
ConsumerState<EventInfoPage> createState() => _EventInfoPageState();
|
||||||
@@ -22,15 +20,11 @@ class _EventInfoPageState extends ConsumerState<EventInfoPage> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
if (!mounted) return;
|
|
||||||
ref.read(eventInfoProvider.notifier).loadRegistrationList();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> onItemTap(EventRegistrationItem item) async {
|
Future<void> onItemTap(EventRegistrationItem item) async {
|
||||||
debugPrint('item tapped: ${item.itemName}');
|
// debugPrint('item tapped: ${item.itemName}');
|
||||||
await ref.read(eventInfoProvider.notifier).requestStreamKey(item);
|
// await ref.read(eventInfoProvider.notifier).requestStreamKey(item);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
// final profile = ref.read(eventInfoProvider).profile;
|
// final profile = ref.read(eventInfoProvider).profile;
|
||||||
|
|
||||||
@@ -182,17 +176,13 @@ class _ScheduleList extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (state.isLoading) {
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.items.isEmpty) {
|
if (state.items.isEmpty) {
|
||||||
return Center(
|
return Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
state.errorMessage ?? '暂无赛事报名信息',
|
'暂无赛事报名信息',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(fontSize: 18.sp, color: const Color(0xFF2F2F2F)),
|
style: TextStyle(fontSize: 18.sp, color: const Color(0xFF2F2F2F)),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -2,17 +2,13 @@ import 'package:recording_tool/features/events/model/model_event_info.dart';
|
|||||||
|
|
||||||
class EventInfoState {
|
class EventInfoState {
|
||||||
const EventInfoState({
|
const EventInfoState({
|
||||||
this.isLoading = false,
|
|
||||||
this.isRequestingStreamKey = false,
|
this.isRequestingStreamKey = false,
|
||||||
this.errorMessage,
|
|
||||||
this.profile = const EventProfile(name: '', phone: '', eventTitle: '赛事信息'),
|
this.profile = const EventProfile(name: '', phone: '', eventTitle: '赛事信息'),
|
||||||
this.total = 0,
|
this.total = 0,
|
||||||
this.items = const [],
|
this.items = const [],
|
||||||
});
|
});
|
||||||
|
|
||||||
final bool isLoading;
|
|
||||||
final bool isRequestingStreamKey;
|
final bool isRequestingStreamKey;
|
||||||
final String? errorMessage;
|
|
||||||
final EventProfile profile;
|
final EventProfile profile;
|
||||||
final int total;
|
final int total;
|
||||||
final List<EventRegistrationItem> items;
|
final List<EventRegistrationItem> items;
|
||||||
@@ -21,21 +17,14 @@ class EventInfoState {
|
|||||||
items.isEmpty ? profile.eventTitle : items.first.eventName;
|
items.isEmpty ? profile.eventTitle : items.first.eventName;
|
||||||
|
|
||||||
EventInfoState copyWith({
|
EventInfoState copyWith({
|
||||||
bool? isLoading,
|
|
||||||
bool? isRequestingStreamKey,
|
bool? isRequestingStreamKey,
|
||||||
String? errorMessage,
|
|
||||||
bool clearErrorMessage = false,
|
|
||||||
EventProfile? profile,
|
EventProfile? profile,
|
||||||
int? total,
|
int? total,
|
||||||
List<EventRegistrationItem>? items,
|
List<EventRegistrationItem>? items,
|
||||||
}) {
|
}) {
|
||||||
return EventInfoState(
|
return EventInfoState(
|
||||||
isLoading: isLoading ?? this.isLoading,
|
|
||||||
isRequestingStreamKey:
|
isRequestingStreamKey:
|
||||||
isRequestingStreamKey ?? this.isRequestingStreamKey,
|
isRequestingStreamKey ?? this.isRequestingStreamKey,
|
||||||
errorMessage: clearErrorMessage
|
|
||||||
? null
|
|
||||||
: (errorMessage ?? this.errorMessage),
|
|
||||||
profile: profile ?? this.profile,
|
profile: profile ?? this.profile,
|
||||||
total: total ?? this.total,
|
total: total ?? this.total,
|
||||||
items: items ?? this.items,
|
items: items ?? this.items,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:recording_tool/core/network/api_exception.dart';
|
|||||||
import 'package:recording_tool/features/events/model/model_event_info.dart';
|
import 'package:recording_tool/features/events/model/model_event_info.dart';
|
||||||
import 'package:recording_tool/features/events/server/server_events.dart';
|
import 'package:recording_tool/features/events/server/server_events.dart';
|
||||||
import 'package:recording_tool/features/events/state/state_event_info.dart';
|
import 'package:recording_tool/features/events/state/state_event_info.dart';
|
||||||
|
import 'package:recording_tool/shared/widgets/app_toast.dart';
|
||||||
|
|
||||||
final eventInfoProvider =
|
final eventInfoProvider =
|
||||||
StateNotifierProvider<EventInfoViewModel, EventInfoState>((ref) {
|
StateNotifierProvider<EventInfoViewModel, EventInfoState>((ref) {
|
||||||
@@ -15,44 +16,42 @@ class EventInfoViewModel extends StateNotifier<EventInfoState> {
|
|||||||
EventInfoViewModel(this._ref) : super(const EventInfoState());
|
EventInfoViewModel(this._ref) : super(const EventInfoState());
|
||||||
|
|
||||||
static const defaultRegistrationRequest = PlayerRegistrationListReq(
|
static const defaultRegistrationRequest = PlayerRegistrationListReq(
|
||||||
userId: '74300708945530955',
|
userId: '',
|
||||||
status: '',
|
status: '',
|
||||||
);
|
);
|
||||||
|
|
||||||
static const _fallbackEventId = '10224';
|
static const _fallbackEventId = '';
|
||||||
static const _fallbackItemId = '2318';
|
static const _fallbackItemId = '';
|
||||||
static const _fallbackStreamUserId = '74300708949725207';
|
static const _fallbackStreamUserId = '';
|
||||||
|
|
||||||
final Ref _ref;
|
final Ref _ref;
|
||||||
|
|
||||||
Future<void> loadRegistrationList({
|
Future<bool> loadRegistrationList({
|
||||||
PlayerRegistrationListReq request = defaultRegistrationRequest,
|
PlayerRegistrationListReq request = defaultRegistrationRequest,
|
||||||
}) async {
|
}) async {
|
||||||
state = state.copyWith(isLoading: true, clearErrorMessage: true);
|
if (request.userId.isEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
final result = await _ref
|
final result = await _ref
|
||||||
.read(eventsServerProvider)
|
.read(eventsServerProvider)
|
||||||
.fetchPlayerRegistrationList(request);
|
.fetchPlayerRegistrationList(request);
|
||||||
|
debugPrint('报名列表请求成功: $result');
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
isLoading: false,
|
|
||||||
profile: result.toProfile(),
|
profile: result.toProfile(),
|
||||||
total: result.total,
|
total: result.total,
|
||||||
items: result.items,
|
items: result.items,
|
||||||
clearErrorMessage: true,
|
|
||||||
);
|
);
|
||||||
} on ApiException catch (error) {
|
return true;
|
||||||
state = state.copyWith(isLoading: false, errorMessage: error.message);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
debugPrint('报名列表请求失败: $error');
|
debugPrint('报名列表请求失败: $error');
|
||||||
state = state.copyWith(isLoading: false, errorMessage: '报名列表加载失败');
|
AppToast.show('报名列表加载失败');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> requestStreamKey(EventRegistrationItem item) async {
|
Future<void> requestStreamKey(EventRegistrationItem item) async {
|
||||||
state = state.copyWith(
|
state = state.copyWith(isRequestingStreamKey: true);
|
||||||
isRequestingStreamKey: true,
|
|
||||||
clearErrorMessage: true,
|
|
||||||
);
|
|
||||||
final req = StreamKeyReq(
|
final req = StreamKeyReq(
|
||||||
eventId: item.eventId.isNotEmpty ? item.eventId : _fallbackEventId,
|
eventId: item.eventId.isNotEmpty ? item.eventId : _fallbackEventId,
|
||||||
itemId: item.itemId.isNotEmpty ? item.itemId : _fallbackItemId,
|
itemId: item.itemId.isNotEmpty ? item.itemId : _fallbackItemId,
|
||||||
@@ -64,22 +63,15 @@ class EventInfoViewModel extends StateNotifier<EventInfoState> {
|
|||||||
.read(eventsServerProvider)
|
.read(eventsServerProvider)
|
||||||
.fetchStreamKey(req);
|
.fetchStreamKey(req);
|
||||||
debugPrint('推流 Key 接口响应: $response');
|
debugPrint('推流 Key 接口响应: $response');
|
||||||
state = state.copyWith(
|
state = state.copyWith(isRequestingStreamKey: false);
|
||||||
isRequestingStreamKey: false,
|
|
||||||
clearErrorMessage: true,
|
|
||||||
);
|
|
||||||
} on ApiException catch (error) {
|
} on ApiException catch (error) {
|
||||||
debugPrint('推流 Key 接口请求失败: ${error.message}');
|
debugPrint('推流 Key 接口请求失败: ${error.message}');
|
||||||
state = state.copyWith(
|
state = state.copyWith(isRequestingStreamKey: false);
|
||||||
isRequestingStreamKey: false,
|
AppToast.show(error.message);
|
||||||
errorMessage: error.message,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
debugPrint('推流 Key 接口请求失败: $error');
|
debugPrint('推流 Key 接口请求失败: $error');
|
||||||
state = state.copyWith(
|
state = state.copyWith(isRequestingStreamKey: false);
|
||||||
isRequestingStreamKey: false,
|
AppToast.show('推流 Key 获取失败');
|
||||||
errorMessage: '推流 Key 获取失败',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:recording_tool/app/router/app_navigator.dart';
|
import 'package:recording_tool/app/router/app_navigator.dart';
|
||||||
@@ -6,7 +7,9 @@ import 'package:recording_tool/core/cache/app_storage.dart';
|
|||||||
import 'package:recording_tool/core/cache/storage_keys.dart';
|
import 'package:recording_tool/core/cache/storage_keys.dart';
|
||||||
import 'package:recording_tool/features/auth/pages/page_auth.dart';
|
import 'package:recording_tool/features/auth/pages/page_auth.dart';
|
||||||
import 'package:recording_tool/features/auth/view_model_auth/view_model_auth.dart';
|
import 'package:recording_tool/features/auth/view_model_auth/view_model_auth.dart';
|
||||||
|
import 'package:recording_tool/features/events/model/model_event_info.dart';
|
||||||
import 'package:recording_tool/features/events/pages/page_event_info.dart';
|
import 'package:recording_tool/features/events/pages/page_event_info.dart';
|
||||||
|
import 'package:recording_tool/features/events/view_model/view_model_event_info.dart';
|
||||||
import 'package:recording_tool/features/recording/model/model_recording_context.dart';
|
import 'package:recording_tool/features/recording/model/model_recording_context.dart';
|
||||||
import 'package:recording_tool/shared/widgets/app_bar.dart';
|
import 'package:recording_tool/shared/widgets/app_bar.dart';
|
||||||
import 'package:recording_tool/shared/widgets/app_button.dart';
|
import 'package:recording_tool/shared/widgets/app_button.dart';
|
||||||
@@ -126,12 +129,30 @@ class _AuthPageWidgetState extends ConsumerState<ScanQrCodePage> {
|
|||||||
context,
|
context,
|
||||||
);
|
);
|
||||||
if (playerId == null || playerId.isEmpty) {
|
if (playerId == null || playerId.isEmpty) {
|
||||||
AppToast.show('无效的参赛凭证');
|
AppToast.show('查询选手信息失败');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
EasyLoading.show(status: '查询选手信息...');
|
||||||
|
try {
|
||||||
|
final success = await ref
|
||||||
|
.read(eventInfoProvider.notifier)
|
||||||
|
.loadRegistrationList(
|
||||||
|
request: PlayerRegistrationListReq(
|
||||||
|
userId: playerId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
EasyLoading.dismiss();
|
||||||
|
if (!success) {
|
||||||
|
AppToast.show('查询选手信息失败');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
/// TODO
|
AppNavigator.push(EventInfoPage(playerId: playerId));
|
||||||
AppNavigator.push(EventInfoPage(playerId: playerId));
|
} catch (error) {
|
||||||
|
AppToast.show('查询选手信息失败');
|
||||||
|
EasyLoading.dismiss();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
variant: AppButtonVariant.secondary,
|
variant: AppButtonVariant.secondary,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user