From 934e2b4731a8a7fc1da8ab39782f5ac7707a07a4 Mon Sep 17 00:00:00 2001 From: lcy <2503978335@qq.com> Date: Mon, 10 Jul 2023 17:34:42 +0800 Subject: [PATCH] feat:权限调整+课程进度接口对接 --- lib/common/dialogs/customer_dialog.dart | 34 ++++++++++++++++++---------------- lib/common/request/apis.dart | 6 ++++++ lib/common/request/dao/listen_dao.dart | 12 ++++++++++++ lib/common/request/request_client.dart | 8 ++++---- lib/common/request/token_interceptor.dart | 2 ++ lib/pages/home/bloc/home_bloc.dart | 22 +++++++++++++++++++++- lib/pages/home/bloc/home_event.dart | 15 +++++++++++++++ lib/pages/home/bloc/home_state.dart | 9 ++++++++- lib/pages/home/home_page.dart | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- lib/pages/practice/topic_picture_page.dart | 9 +++++++-- lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart | 44 +++++++++++++++++++++++++++----------------- lib/pages/repeataftercontent/widgets/repeat_video_widget.dart | 23 +++++++++++++---------- lib/pages/user/modify/user_avatar_bloc/user_avatar_bloc.dart | 64 +++++++++++++++++++++++++++++----------------------------------- lib/pages/video/lookvideo/look_video_page.dart | 4 +++- lib/pages/video/lookvideo/widgets/video_widget.dart | 18 +++++++++++++++--- lib/route/route.dart | 30 +++++++++++++++++------------- pubspec.yaml | 2 ++ 17 files changed, 251 insertions(+), 118 deletions(-) diff --git a/lib/common/dialogs/customer_dialog.dart b/lib/common/dialogs/customer_dialog.dart index eeaf01b..8cb53cf 100644 --- a/lib/common/dialogs/customer_dialog.dart +++ b/lib/common/dialogs/customer_dialog.dart @@ -20,12 +20,12 @@ class CustomerTwoActionDialog extends Dialog { Widget build(BuildContext context) { super.build(context); return Container( - height: 238.h, + height: 208.h, alignment: Alignment.center, child: ConstrainedBox( constraints: BoxConstraints( - maxHeight: 238.h, - maxWidth: 407.w + maxHeight: 208.h, + maxWidth: 247.w ), child: Container( padding: EdgeInsets.symmetric(horizontal: 24.w,vertical: 15.h), @@ -48,13 +48,16 @@ class CustomerTwoActionDialog extends Dialog { ), ), Expanded( - child: Text( - content, - textAlign: TextAlign.left, - style: TextStyle( - color: const Color(0xFF333333), - fontSize: 13.sp - ) + child: Container( + alignment: Alignment.center, + child: Text( + content, + textAlign: TextAlign.left, + style: TextStyle( + color: const Color(0xFF333333), + fontSize: 13.sp + ) + ), ), ), Row( @@ -63,9 +66,8 @@ class CustomerTwoActionDialog extends Dialog { TextButton( onPressed: leftTap, child: Container( - height: 31.h, padding: EdgeInsets.symmetric( - horizontal: 6.w + horizontal: 6.w,vertical: 2.h ), decoration: BoxDecoration( color: const Color(0xFFFBB661), @@ -87,7 +89,6 @@ class CustomerTwoActionDialog extends Dialog { TextButton( onPressed: rightTap, child: Container( - height: 31.h, decoration: BoxDecoration( color: Colors.white, border: Border.all( @@ -97,8 +98,9 @@ class CustomerTwoActionDialog extends Dialog { borderRadius: BorderRadius.circular(10.r) ), padding: EdgeInsets.symmetric( - horizontal: 6.w + horizontal: 6.w,vertical: 2.h ), + alignment: Alignment.center, child: Text( rightTitle, textAlign: TextAlign.center, @@ -131,8 +133,8 @@ class CustomerOneActionDialog extends Dialog { alignment: Alignment.center, child: ConstrainedBox( constraints: BoxConstraints( - maxHeight: 238.h, - maxWidth: 407.w + maxHeight: 208.h, + maxWidth: 247.w ), child: Container( padding: EdgeInsets.symmetric(horizontal: 24.w,vertical: 15.h), diff --git a/lib/common/request/apis.dart b/lib/common/request/apis.dart index 45dfbb2..6744c20 100644 --- a/lib/common/request/apis.dart +++ b/lib/common/request/apis.dart @@ -76,4 +76,10 @@ class Apis { /// 获取阿里云oss鉴权信息 static const String aliyunOssSts = 'oss/sts/upload'; + + /// 进入课堂 + static const String enterClass = 'course/enter/class'; + + /// 退出课堂 + static const String exitClass = 'course/exit/class'; } diff --git a/lib/common/request/dao/listen_dao.dart b/lib/common/request/dao/listen_dao.dart index 8e9353a..88305ca 100644 --- a/lib/common/request/dao/listen_dao.dart +++ b/lib/common/request/dao/listen_dao.dart @@ -35,4 +35,16 @@ class ListenDao { var data = await requestClient.post(Apis.followResult,data: {'frequency':frequency,'videoFollowReadId':videoFollowReadId}); return data; } + + ///进入课堂 + static Future enterClass(courseLessonId) async { + var data = await requestClient.post(Apis.enterClass,data: {'courseLessonId':courseLessonId}); + return data; + } + + ///退出课堂 + static Future exitClass(courseLessonId,currentStep,currentTime) async { + var data = await requestClient.post(Apis.exitClass,data: {'courseLessonId':courseLessonId,'currentStep':currentStep,'currentTime':currentTime}); + return data; + } } diff --git a/lib/common/request/request_client.dart b/lib/common/request/request_client.dart index 69d9805..848c9b3 100644 --- a/lib/common/request/request_client.dart +++ b/lib/common/request/request_client.dart @@ -45,10 +45,10 @@ class RequestClient { data = _convertRequestData(data); Response response = await _dio.request(url, queryParameters: queryParameters, data: data, options: options); - print("response.body type=${response.data.runtimeType}"); + debugPrint("response.body type=${response.data.runtimeType}"); return _handleResponse(response, onResponse); } catch (e) { - print("e type=${e.runtimeType}"); + debugPrint("e type=${e.runtimeType}"); if (e is ApiException && e.code == 405) { showToast('登录已失效,请重新登录!', duration: const Duration(seconds: 3)); UserUtil.logout(); @@ -166,7 +166,7 @@ class RequestClient { } } else { ApiException exception = ApiException(response.statusCode, ApiException.unknownException); - print("_handleResponse exception type=${exception.runtimeType}"); + debugPrint("_handleResponse exception type=${exception.runtimeType}"); throw exception; } } @@ -177,7 +177,7 @@ class RequestClient { return response.data; } else { ApiException exception = ApiException(response.code, response.msg); - print("_handleBusinessResponse exception type=${exception.runtimeType}"); + debugPrint("_handleBusinessResponse exception type=${exception.runtimeType}"); throw exception; } } diff --git a/lib/common/request/token_interceptor.dart b/lib/common/request/token_interceptor.dart index 95f24fa..6099274 100644 --- a/lib/common/request/token_interceptor.dart +++ b/lib/common/request/token_interceptor.dart @@ -1,5 +1,7 @@ import 'package:dio/dio.dart'; +import 'package:package_info_plus/package_info_plus.dart'; import 'package:wow_english/common/core/user_util.dart'; +import 'package:wow_english/common/request/basic_config.dart'; class TokenInterceptor extends Interceptor { @override diff --git a/lib/pages/home/bloc/home_bloc.dart b/lib/pages/home/bloc/home_bloc.dart index e3a51d9..aa31d7a 100644 --- a/lib/pages/home/bloc/home_bloc.dart +++ b/lib/pages/home/bloc/home_bloc.dart @@ -26,6 +26,8 @@ class HomeBloc extends Bloc { HomeBloc(this.moduleId) : super(HomeInitial()) { on(_requestData); + on(_requestExitClass); + on(_requestEnterClass); on(_requestVideoLesson); } @@ -46,7 +48,7 @@ class HomeBloc extends Bloc { try { await loading(() async { _processEntity = await ListenDao.process(event.courseLessonId); - emitter(RequestVideoLessonState(event.courseType)); + emitter(RequestVideoLessonState(event.courseLessonId,event.courseType)); }); } catch (e) { if (e is ApiException) { @@ -54,4 +56,22 @@ class HomeBloc extends Bloc { } } } + + + void _requestEnterClass(RequestEnterClassEvent event,Emitter emitter) async { + try { + await loading(() async { + await ListenDao.enterClass(event.courseLessonId); + emitter(RequestEnterClassState(event.courseLessonId,event.courseType)); + }); + } catch (e) { + if (e is ApiException) { + showToast(e.message??'请求失败,请检查网络连接'); + } + } + } + + void _requestExitClass(RequestExitClassEvent event,Emitter emitter) async { + await ListenDao.exitClass(event.courseLessonId,event.currentStep,event.currentTime); + } } diff --git a/lib/pages/home/bloc/home_event.dart b/lib/pages/home/bloc/home_event.dart index 61e6317..a28e023 100644 --- a/lib/pages/home/bloc/home_event.dart +++ b/lib/pages/home/bloc/home_event.dart @@ -11,3 +11,18 @@ class RequestVideoLessonEvent extends HomeEvent { final int courseType; RequestVideoLessonEvent(this.courseLessonId, this.courseType); } + +///进入课堂 +class RequestEnterClassEvent extends HomeEvent { + final String courseLessonId; + final int courseType; + RequestEnterClassEvent(this.courseLessonId,this.courseType); +} + +///退出课堂 +class RequestExitClassEvent extends HomeEvent { + final String courseLessonId; + final String currentStep; + final String currentTime; + RequestExitClassEvent(this.courseLessonId,this.currentStep,this.currentTime); +} diff --git a/lib/pages/home/bloc/home_state.dart b/lib/pages/home/bloc/home_state.dart index e403530..a58a828 100644 --- a/lib/pages/home/bloc/home_state.dart +++ b/lib/pages/home/bloc/home_state.dart @@ -8,6 +8,13 @@ class HomeInitial extends HomeState {} class HomeDataLoadState extends HomeState {} class RequestVideoLessonState extends HomeState { + final String courseLessonId; final int type; - RequestVideoLessonState(this.type); + RequestVideoLessonState(this.courseLessonId,this.type); +} + +class RequestEnterClassState extends HomeState{ + final String courseLessonId; + final int courseType; + RequestEnterClassState(this.courseLessonId,this.courseType); } diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index fc7f1c0..3775ca0 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -73,10 +73,56 @@ class _HomePageView extends StatelessWidget { title = 'bonus'; } - if (videoUrl.isEmpty && !videoUrl.contains('http')) { + if (videoUrl.isEmpty || !videoUrl.contains('http')) { + return; + } + pushNamed(AppRouteName.lookVideo,arguments: {'videoUrl':videoUrl,'title':title,'courseLessonId':state.courseLessonId}).then((value) { + if (value != null) { + Map dataMap = value as Map; + bloc.add(RequestExitClassEvent( + dataMap['courseLessonId']!, + '0', + dataMap['currentTime']!, + )); + } + }); + return; + } + + if (state is RequestEnterClassState) { + if (state.courseType != 3 && state.courseType != 4) {///视频类型 + ///获取视频课程内容 + bloc.add(RequestVideoLessonEvent(state.courseLessonId,state.courseType)); + return; + } + + if (state.courseType == 4) {//绘本 + pushNamed(AppRouteName.reading, arguments: {'courseLessonId':state.courseLessonId}).then((value) { + if (value != null) { + Map dataMap = value as Map; + bloc.add(RequestExitClassEvent( + dataMap['courseLessonId']!, + dataMap['currentStep']!, + '0' + )); + } + }); + return; + } + + if (state.courseType == 3) {//练习 + pushNamed(AppRouteName.topicPic,arguments: {'courseLessonId':state.courseLessonId}).then((value) { + if (value != null) { + Map dataMap = value as Map; + bloc.add(RequestExitClassEvent( + dataMap['courseLessonId']!, + dataMap['currentStep']!, + '0' + )); + } + }); return; } - pushNamed(AppRouteName.lookVideo,arguments: {'videoUrl':videoUrl,'title':title}); } }, child: _homeView(), @@ -116,7 +162,8 @@ class _HomePageView extends StatelessWidget { showToast('当前课程暂未解锁'); return; } - bloc.add(RequestVideoLessonEvent(data.id!,data.courseType!)); + ///进入课堂 + bloc.add(RequestEnterClassEvent(data.id!,data.courseType!)); }, child: HomeBoundsItem( imageUrl: data?.coverUrl, @@ -133,18 +180,8 @@ class _HomePageView extends StatelessWidget { showToast('当前课程暂未解锁'); return; } - if (data.courseType == 4) {//绘本 - Navigator.of(context).pushNamed(AppRouteName.reading, arguments: {'courseLessonId':data.id!}); - return; - } - - if (data.courseType == 3) {//练习 - Navigator.of(context).pushNamed(AppRouteName.topicPic,arguments: {'courseLessonId':data.id!}); - return; - } - - //儿歌/看视频 - bloc.add(RequestVideoLessonEvent(data.id!,data.courseType!)); + ///进入课堂 + bloc.add(RequestEnterClassEvent(data.id!,data.courseType!)); }, child: HomeVideoItem( themColor: bloc.modelData?.courseModuleThemeColor, diff --git a/lib/pages/practice/topic_picture_page.dart b/lib/pages/practice/topic_picture_page.dart index f2513ee..08a96a8 100644 --- a/lib/pages/practice/topic_picture_page.dart +++ b/lib/pages/practice/topic_picture_page.dart @@ -6,6 +6,7 @@ import 'package:wow_english/common/core/user_util.dart'; import 'package:wow_english/common/extension/string_extension.dart'; import 'package:wow_english/common/widgets/ow_image_widget.dart'; import 'package:wow_english/models/course_process_entity.dart'; +import 'package:wow_english/route/route.dart'; import 'package:wow_english/utils/toast_util.dart'; import 'bloc/topic_picture_bloc.dart'; @@ -46,7 +47,6 @@ class _TopicPicturePage extends StatelessWidget { if (state is RequestDataState) { context.read().add(CurrentPageIndexChangeEvent(0)); } - if (state is XSVoiceTestState) { } @@ -67,7 +67,12 @@ class _TopicPicturePage extends StatelessWidget { PracticeHeaderWidget( title: '${bloc.currentPage}/${bloc.entity?.topics?.length}', onTap: () { - Navigator.pop(context); + popPage( + data:{ + 'currentStep':bloc.currentPage.toString(), + 'courseLessonId':(int.parse(bloc.courseLessonId)+1).toString() + }); + // Navigator.pop(context); }, ), Expanded( diff --git a/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart b/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart index 1b0bc11..752b5a1 100644 --- a/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart +++ b/lib/pages/repeataftercontent/bloc/repeat_after_content_bloc.dart @@ -9,6 +9,8 @@ import 'package:flutter_sound/flutter_sound.dart'; import 'package:path_provider/path_provider.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:wow_english/common/request/dao/listen_dao.dart'; +import 'package:wow_english/route/route.dart'; +import '../../../common/dialogs/show_dialog.dart'; import '../../../common/request/exception.dart'; import '../../../models/read_content_entity.dart'; import '../../../utils/loading.dart'; @@ -80,7 +82,7 @@ class RepeatAfterContentBloc extends Bloc(_voiceRecordStateChange); @@ -123,13 +125,14 @@ class RepeatAfterContentBloc extends Bloc emitter) async { try { - await loading(() async { - _entityList = await ListenDao.followResult(_recordNumber.toString(),courseLessonId); - }); + await ListenDao.followResult(_recordNumber.toString(),courseLessonId); } catch (e) { if (e is ApiException) { @@ -203,6 +204,9 @@ class RepeatAfterContentBloc extends Bloc emitter) async { + _recordNumber += 1; + _xSCheckState = XSVoiceCheckState.start; + emitter(XSVoiceTestState()); await methodChannel.invokeMethod( 'startLocalVoice', { @@ -212,9 +216,6 @@ class RepeatAfterContentBloc extends Bloc 开始录音'); _voiceRecordState = VoiceRecordState.voiceRecording; + _xSCheckState = XSVoiceCheckState.unKnow; emitter(VoiceRecordStateChange()); }); } catch (error) { @@ -321,7 +322,7 @@ class RepeatAfterContentBloc extends Bloc { } void _initVideo(String videoUrl) { - _controller = VideoPlayerController.network(widget.videoUrl??'') - ..initialize().then((_){ - setState(() { - _currentTime = formatDuration(_controller!.value.position); - _totalTime = formatDuration(_controller!.value.duration); - _controller!.setLooping(false); - _controller!.setVolume(100); - _controller!.play(); + if(videoUrl.isNotEmpty) { + Uri uri = Uri.parse(videoUrl); + _controller = VideoPlayerController.networkUrl(uri) + ..initialize().then((_){ + setState(() { + _currentTime = formatDuration(_controller!.value.position); + _totalTime = formatDuration(_controller!.value.duration); + _controller!.setLooping(false); + _controller!.setVolume(100); + _controller!.play(); + }); + _addListener(); }); - _addListener(); - }); + } } void _destroyVideo() { diff --git a/lib/pages/user/modify/user_avatar_bloc/user_avatar_bloc.dart b/lib/pages/user/modify/user_avatar_bloc/user_avatar_bloc.dart index 5a4f6ce..24e03b0 100644 --- a/lib/pages/user/modify/user_avatar_bloc/user_avatar_bloc.dart +++ b/lib/pages/user/modify/user_avatar_bloc/user_avatar_bloc.dart @@ -3,12 +3,12 @@ import 'dart:io'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:image_picker/image_picker.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:wow_english/common/core/assets_const.dart'; import 'package:wow_english/common/core/user_util.dart'; -import 'package:wow_english/common/request/dao/user_dao.dart'; +import 'package:wow_english/common/dialogs/show_dialog.dart'; +import 'package:wow_english/route/route.dart'; import 'package:wow_english/utils/aliyun_oss_util.dart'; import 'package:wow_english/utils/log_util.dart'; @@ -46,7 +46,18 @@ class UserAvatarBloc extends Bloc { } void _getImageFromPhoto(GetImageFromPhotoEvent event, Emitter emitter) async { - await getPhotoPermissionStatus().then((value) async { + Permission permission; + if (Platform.isAndroid) { + final androidInfo = await DeviceInfoPlugin().androidInfo; + if (androidInfo.version.sdkInt <= 32) { + permission = Permission.storage; + } else { + permission = Permission.photos; + } + } else { + permission = Permission.photos; + } + await getPermissionStatus(permission).then((value) async { if (!value) { debugPrint('失败$value'); return; @@ -62,7 +73,7 @@ class UserAvatarBloc extends Bloc { } void _getImageFromCamera(GetImageFromCameraEvent event, Emitter emitter) async { - await getCameraPermissionStatus().then((value) async { + await getPermissionStatus(Permission.camera).then((value) async { if (!value) { debugPrint('失败$value'); return; @@ -83,46 +94,19 @@ class UserAvatarBloc extends Bloc { emitter(ChangeUserEnterAppState()); } - ///获取相机权限 - Future getCameraPermissionStatus() async { - Permission permission = Permission.camera; - //granted 通过,denied 被拒绝,permanentlyDenied 拒绝且不在提示 + Future getPermissionStatus(Permission permission) async { PermissionStatus status = await permission.status; if (status.isGranted) { return true; } else if (status.isDenied) { _requestPermission(permission); } else if (status.isPermanentlyDenied) { - openAppSettings(); + showDialog(permission); } else if (status.isRestricted) { _requestPermission(permission); - } else {} - return false; - } - - ///获取相册权限 - Future getPhotoPermissionStatus() async { - Permission permission; - if (Platform.isAndroid) { - final androidInfo = await DeviceInfoPlugin().androidInfo; - if (androidInfo.version.sdkInt <= 32) { - permission = Permission.storage; - } else { - permission = Permission.photos; - } } else { - permission = Permission.photos; + } - PermissionStatus status = await permission.status; - if (status.isGranted) { - return true; - } else if (status.isDenied) { - _requestPermission(permission); - } else if (status.isPermanentlyDenied) { - openAppSettings(); - } else if (status.isRestricted) { - _requestPermission(permission); - } else {} return false; } @@ -130,7 +114,17 @@ class UserAvatarBloc extends Bloc { void _requestPermission(Permission permission) async { PermissionStatus status = await permission.request(); if (status.isPermanentlyDenied) { - openAppSettings(); + showDialog(permission); } } + + void showDialog(Permission permission) { + final contentStr = permission == Permission.camera ? '相机权限未开启,请到设置中打开' : '相册权限未开启,请到设置中打开'; + showTwoActionDialog('提示', '取消', '去设置', contentStr, () { + popPage(); + }, () { + popPage(); + openAppSettings(); + }); + } } diff --git a/lib/pages/video/lookvideo/look_video_page.dart b/lib/pages/video/lookvideo/look_video_page.dart index 1c5fdda..b535aa7 100644 --- a/lib/pages/video/lookvideo/look_video_page.dart +++ b/lib/pages/video/lookvideo/look_video_page.dart @@ -2,10 +2,11 @@ import 'package:flutter/material.dart'; import 'package:wow_english/pages/video/lookvideo/widgets/video_widget.dart'; class LookVideoPage extends StatefulWidget { - const LookVideoPage({super.key, this.videoUrl, this.typeTitle}); + const LookVideoPage({super.key, this.videoUrl, this.typeTitle, this.courseLessonId}); final String? videoUrl; final String? typeTitle; + final String? courseLessonId; @override State createState() { @@ -21,6 +22,7 @@ class _LookVideoPageState extends State { child: VideoWidget( videoUrl: widget.videoUrl??'', typeTitle: widget.typeTitle, + courseLessonId: widget.courseLessonId??'', ), ); } diff --git a/lib/pages/video/lookvideo/widgets/video_widget.dart b/lib/pages/video/lookvideo/widgets/video_widget.dart index b76750c..48201da 100644 --- a/lib/pages/video/lookvideo/widgets/video_widget.dart +++ b/lib/pages/video/lookvideo/widgets/video_widget.dart @@ -3,14 +3,16 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:video_player/video_player.dart'; import 'package:wow_english/common/extension/string_extension.dart'; +import 'package:wow_english/route/route.dart'; import 'video_opera_widget.dart'; class VideoWidget extends StatefulWidget { - const VideoWidget({super.key, this.videoUrl = '',this.typeTitle}); + const VideoWidget({super.key, this.videoUrl = '',this.typeTitle, this.courseLessonId = ''}); final String videoUrl; final String? typeTitle; + final String courseLessonId; @override State createState() { @@ -74,7 +76,16 @@ class _VideoWidgetState extends State { void actionType(OperationType type) async { if (type == OperationType.back) { - Navigator.pop(context); + if (widget.courseLessonId.isEmpty) { + popPage(); + } else { + if (_controller == null) { + popPage(); + return; + } + String currentTime = (_controller!.value.position.inMinutes.remainder(60)*60+_controller!.value.position.inSeconds.remainder(60)).toString(); + popPage(data:{'courseLessonId':widget.courseLessonId,'currentTime':currentTime}); + } } else if (type == OperationType.playState) { if (_controller!.value.isPlaying) { _controller!.pause(); @@ -90,7 +101,8 @@ class _VideoWidgetState extends State { @override void initState() { super.initState(); - _controller = VideoPlayerController.network(widget.videoUrl) + Uri uri = Uri.parse(widget.videoUrl); + _controller = VideoPlayerController.networkUrl(uri) ..initialize().then((_){ startTimer(); setState(() { diff --git a/lib/route/route.dart b/lib/route/route.dart index 7b76a90..1f0a3ca 100644 --- a/lib/route/route.dart +++ b/lib/route/route.dart @@ -107,7 +107,7 @@ class AppRouter { case AppRouteName.userAvatar: var pageType = 0; if (settings.arguments != null) { - final content = (settings.arguments as Map)['pageType'] as String ?? '0'; + final content = (settings.arguments as Map)['pageType'] as String; pageType = int.parse(content); } return CupertinoPageRoute( @@ -125,17 +125,19 @@ class AppRouter { case AppRouteName.topicPic: var courseLessonId = ''; if (settings.arguments != null) { - courseLessonId = (settings.arguments as Map)['courseLessonId'] as String ?? ''; + courseLessonId = (settings.arguments as Map)['courseLessonId'] as String; } return CupertinoPageRoute(builder: (_) => TopicPicturePage(courseLessonId: courseLessonId)); case AppRouteName.lookVideo: final videoUrl = (settings.arguments as Map)['videoUrl'] as String; final title = (settings.arguments as Map)['title'] as String?; + final courseLessonId = (settings.arguments as Map)['courseLessonId'] as String?; return CupertinoPageRoute( builder: (_) => LookVideoPage( - videoUrl: videoUrl, - typeTitle: title, - )); + videoUrl: videoUrl, + typeTitle: title, + courseLessonId: courseLessonId, + )); /*case AppRouteName.setPwd: case AppRouteName.setPwd: phoneNum: phoneNum, @@ -153,7 +155,7 @@ class AppRouter { case AppRouteName.readAfterContent: var videoFollowReadId = ''; if (settings.arguments != null) { - videoFollowReadId = (settings.arguments as Map)['videoFollowReadId'] as String ?? ''; + videoFollowReadId = (settings.arguments as Map)['videoFollowReadId'] as String; } return CupertinoPageRoute(builder: (_) => RepeatAfterContentPage(videoFollowReadId: videoFollowReadId)); case AppRouteName.tab: @@ -166,7 +168,7 @@ class AppRouter { case AppRouteName.reading: var courseLessonId = ''; if (settings.arguments != null) { - courseLessonId = (settings.arguments as Map)['courseLessonId'] as String ?? ''; + courseLessonId = (settings.arguments as Map)['courseLessonId'] as String; } return CupertinoPageRoute(builder: (_) => ReadingPage(courseLessonId: courseLessonId)); default: @@ -176,14 +178,16 @@ class AppRouter { } } -void pushNamed(String routeName, {Object? arguments}) { - Navigator.of(AppRouter.context).pushNamed(routeName, arguments: arguments); +Future pushNamed(String routeName, {Object? arguments}) { + return Navigator.of(AppRouter.context).pushNamed(routeName, arguments: arguments).then((value) { + return value; + }); } -void pushNamedAndRemoveUntil(String routeName, RoutePredicate predicate, {Object? arguments}) { - Navigator.of(AppRouter.context).pushNamedAndRemoveUntil(routeName, predicate, arguments: arguments); +Future pushNamedAndRemoveUntil(String routeName, RoutePredicate predicate, {Object? arguments}) { + return Navigator.of(AppRouter.context).pushNamedAndRemoveUntil(routeName, predicate, arguments: arguments); } -void popPage() { - Navigator.pop(AppRouter.context); +void popPage({dynamic data}) { + Navigator.of(AppRouter.context).pop(data); } diff --git a/pubspec.yaml b/pubspec.yaml index 3b718a2..aeb3d00 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -101,6 +101,8 @@ dependencies: path_provider: ^2.0.15 # 阿里云oss https://pub.dev/packages/flutter_oss_aliyun flutter_oss_aliyun: ^6.2.7 + # App信息 https://pub.dev/packages/package_info_plus + package_info_plus: ^4.0.2 dev_dependencies: build_runner: ^2.4.4 -- libgit2 0.22.2