Compare commits
2
Commits
62d717c3ee
...
a4333d3bd1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4333d3bd1 | ||
|
|
e08a8ed26b |
@@ -11,8 +11,6 @@ import 'package:recording_tool/shared/widgets/widgets.dart';
|
||||
class EventInfoPage extends ConsumerStatefulWidget {
|
||||
const EventInfoPage({super.key, required this.playerId});
|
||||
final String playerId;
|
||||
static const mockRtmpUrl =
|
||||
'rtmp://192.168.1.245:19090/蔡依婷vs夏志豪_空中格斗赛_高中组/蔡依婷vs夏志豪_空中格斗赛_高中组';
|
||||
|
||||
@override
|
||||
ConsumerState<EventInfoPage> createState() => _EventInfoPageState();
|
||||
@@ -22,15 +20,11 @@ class _EventInfoPageState extends ConsumerState<EventInfoPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
ref.read(eventInfoProvider.notifier).loadRegistrationList();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> onItemTap(EventRegistrationItem item) async {
|
||||
debugPrint('item tapped: ${item.itemName}');
|
||||
await ref.read(eventInfoProvider.notifier).requestStreamKey(item);
|
||||
// debugPrint('item tapped: ${item.itemName}');
|
||||
// await ref.read(eventInfoProvider.notifier).requestStreamKey(item);
|
||||
if (!mounted) return;
|
||||
// final profile = ref.read(eventInfoProvider).profile;
|
||||
|
||||
@@ -182,17 +176,13 @@ class _ScheduleList extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (state.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (state.items.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
state.errorMessage ?? '暂无赛事报名信息',
|
||||
'暂无赛事报名信息',
|
||||
textAlign: TextAlign.center,
|
||||
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 {
|
||||
const EventInfoState({
|
||||
this.isLoading = false,
|
||||
this.isRequestingStreamKey = false,
|
||||
this.errorMessage,
|
||||
this.profile = const EventProfile(name: '', phone: '', eventTitle: '赛事信息'),
|
||||
this.total = 0,
|
||||
this.items = const [],
|
||||
});
|
||||
|
||||
final bool isLoading;
|
||||
final bool isRequestingStreamKey;
|
||||
final String? errorMessage;
|
||||
final EventProfile profile;
|
||||
final int total;
|
||||
final List<EventRegistrationItem> items;
|
||||
@@ -21,21 +17,14 @@ class EventInfoState {
|
||||
items.isEmpty ? profile.eventTitle : items.first.eventName;
|
||||
|
||||
EventInfoState copyWith({
|
||||
bool? isLoading,
|
||||
bool? isRequestingStreamKey,
|
||||
String? errorMessage,
|
||||
bool clearErrorMessage = false,
|
||||
EventProfile? profile,
|
||||
int? total,
|
||||
List<EventRegistrationItem>? items,
|
||||
}) {
|
||||
return EventInfoState(
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
isRequestingStreamKey:
|
||||
isRequestingStreamKey ?? this.isRequestingStreamKey,
|
||||
errorMessage: clearErrorMessage
|
||||
? null
|
||||
: (errorMessage ?? this.errorMessage),
|
||||
profile: profile ?? this.profile,
|
||||
total: total ?? this.total,
|
||||
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/server/server_events.dart';
|
||||
import 'package:recording_tool/features/events/state/state_event_info.dart';
|
||||
import 'package:recording_tool/shared/widgets/app_toast.dart';
|
||||
|
||||
final eventInfoProvider =
|
||||
StateNotifierProvider<EventInfoViewModel, EventInfoState>((ref) {
|
||||
@@ -15,44 +16,42 @@ class EventInfoViewModel extends StateNotifier<EventInfoState> {
|
||||
EventInfoViewModel(this._ref) : super(const EventInfoState());
|
||||
|
||||
static const defaultRegistrationRequest = PlayerRegistrationListReq(
|
||||
userId: '74300708945530955',
|
||||
userId: '',
|
||||
status: '',
|
||||
);
|
||||
|
||||
static const _fallbackEventId = '10224';
|
||||
static const _fallbackItemId = '2318';
|
||||
static const _fallbackStreamUserId = '74300708949725207';
|
||||
static const _fallbackEventId = '';
|
||||
static const _fallbackItemId = '';
|
||||
static const _fallbackStreamUserId = '';
|
||||
|
||||
final Ref _ref;
|
||||
|
||||
Future<void> loadRegistrationList({
|
||||
Future<bool> loadRegistrationList({
|
||||
PlayerRegistrationListReq request = defaultRegistrationRequest,
|
||||
}) async {
|
||||
state = state.copyWith(isLoading: true, clearErrorMessage: true);
|
||||
if (request.userId.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final result = await _ref
|
||||
.read(eventsServerProvider)
|
||||
.fetchPlayerRegistrationList(request);
|
||||
debugPrint('报名列表请求成功: $result');
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
profile: result.toProfile(),
|
||||
total: result.total,
|
||||
items: result.items,
|
||||
clearErrorMessage: true,
|
||||
);
|
||||
} on ApiException catch (error) {
|
||||
state = state.copyWith(isLoading: false, errorMessage: error.message);
|
||||
return true;
|
||||
} catch (error) {
|
||||
debugPrint('报名列表请求失败: $error');
|
||||
state = state.copyWith(isLoading: false, errorMessage: '报名列表加载失败');
|
||||
AppToast.show('报名列表加载失败');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> requestStreamKey(EventRegistrationItem item) async {
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: true,
|
||||
clearErrorMessage: true,
|
||||
);
|
||||
state = state.copyWith(isRequestingStreamKey: true);
|
||||
final req = StreamKeyReq(
|
||||
eventId: item.eventId.isNotEmpty ? item.eventId : _fallbackEventId,
|
||||
itemId: item.itemId.isNotEmpty ? item.itemId : _fallbackItemId,
|
||||
@@ -64,22 +63,15 @@ class EventInfoViewModel extends StateNotifier<EventInfoState> {
|
||||
.read(eventsServerProvider)
|
||||
.fetchStreamKey(req);
|
||||
debugPrint('推流 Key 接口响应: $response');
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: false,
|
||||
clearErrorMessage: true,
|
||||
);
|
||||
state = state.copyWith(isRequestingStreamKey: false);
|
||||
} on ApiException catch (error) {
|
||||
debugPrint('推流 Key 接口请求失败: ${error.message}');
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: false,
|
||||
errorMessage: error.message,
|
||||
);
|
||||
state = state.copyWith(isRequestingStreamKey: false);
|
||||
AppToast.show(error.message);
|
||||
} catch (error) {
|
||||
debugPrint('推流 Key 接口请求失败: $error');
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: false,
|
||||
errorMessage: '推流 Key 获取失败',
|
||||
);
|
||||
state = state.copyWith(isRequestingStreamKey: false);
|
||||
AppToast.show('推流 Key 获取失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.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/features/auth/pages/page_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/view_model/view_model_event_info.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_button.dart';
|
||||
@@ -126,12 +129,30 @@ class _AuthPageWidgetState extends ConsumerState<ScanQrCodePage> {
|
||||
context,
|
||||
);
|
||||
if (playerId == null || playerId.isEmpty) {
|
||||
AppToast.show('无效的参赛凭证');
|
||||
AppToast.show('查询选手信息失败');
|
||||
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,
|
||||
),
|
||||
|
||||
@@ -64,7 +64,7 @@ class WebviewPageState extends State<WebviewPage> {
|
||||
late final WebViewController controller;
|
||||
controller = WebViewController.fromPlatformCreationParams(params)
|
||||
..setJavaScriptMode(JavaScriptMode.unrestricted)
|
||||
..setBackgroundColor(Colors.transparent)
|
||||
..setBackgroundColor(Colors.white)
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
onProgress: (int progress) {
|
||||
@@ -231,6 +231,21 @@ class WebviewPageState extends State<WebviewPage> {
|
||||
return const PlatformWebViewControllerCreationParams();
|
||||
}
|
||||
|
||||
Widget _buildWebView(WebViewController controller) {
|
||||
PlatformWebViewWidgetCreationParams params =
|
||||
PlatformWebViewWidgetCreationParams(controller: controller.platform);
|
||||
|
||||
if (WebViewPlatform.instance is AndroidWebViewPlatform) {
|
||||
params =
|
||||
AndroidWebViewWidgetCreationParams.fromPlatformWebViewWidgetCreationParams(
|
||||
params,
|
||||
displayWithHybridComposition: true,
|
||||
);
|
||||
}
|
||||
|
||||
return WebViewWidget.fromPlatformCreationParams(params: params);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -294,7 +309,7 @@ class WebviewPageState extends State<WebviewPage> {
|
||||
Expanded(
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(child: WebViewWidget(controller: controller)),
|
||||
Positioned.fill(child: _buildWebView(controller)),
|
||||
if (_isLoading)
|
||||
const Center(child: CircularProgressIndicator()),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user