fix:首页布局问题

This commit is contained in:
zengyi 2025-09-24 11:34:52 +08:00
parent 311e4fe06c
commit ab042840b9
5 changed files with 380 additions and 358 deletions

View File

@ -1,3 +1,5 @@
import java.util.Properties
plugins {
id("com.android.application")
id("kotlin-android")

View File

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:flutter_kinetra/kt_pages/kt_explore/state.dart';
import 'package:get/get.dart';
import 'package:easy_refresh/easy_refresh.dart';
@ -7,7 +9,9 @@ import 'package:video_player/video_player.dart';
import '../../dio_cilent/kt_apis.dart';
import '../../dio_cilent/kt_request.dart';
import '../../kt_model/kt_short_video_bean.dart';
import '../../kt_utils/kt_device_info_utils.dart';
import '../../kt_widgets/kt_status_widget.dart';
import '../kt_main_page/view.dart';
class KtExploreLogic extends GetxController {
final state = KtExploreState();
@ -145,17 +149,25 @@ class KtExploreLogic extends GetxController {
if (index < 0 || index >= state.videoList.length) return;
if (state.controllers[index] != null) return;
final episode = state.videoList[index];
final controller = VideoPlayerController.networkUrl(
Uri.parse(episode.videoInfo!.videoUrl!),
formatHint: VideoFormat.hls,
);
VideoPlayerController controller =
Platform.isAndroid && KtDeviceInfoUtil().osVersion == '10'
? VideoPlayerController.networkUrl(
Uri.parse(episode.videoInfo!.videoUrl!),
formatHint: VideoFormat.hls,
viewType: VideoViewType.platformView,
)
: VideoPlayerController.networkUrl(
Uri.parse(episode.videoInfo!.videoUrl!),
formatHint: VideoFormat.hls,
);
state.controllers[index] = controller;
try {
await controller.initialize();
if (index == state.currentPage) {
controller.play();
final mainLogic = Get.find<KtMainLogic>();
if(mainLogic.curIndex == 1) controller.play();
update();
}
controller.addListener(() {

View File

@ -11,7 +11,6 @@ import '../../kt_widgets/kt_status_widget.dart';
class KtHomeLogic extends GetxController {
final state = KtHomeState();
late TabController categoryTabCtrl;
final EasyRefreshController easyRefreshController = EasyRefreshController(
controlFinishRefresh: true,

View File

@ -1030,146 +1030,144 @@ class _KtHomePageState extends State<KtHomePage>
),
SizedBox(height: 10.w),
if (state.topPickList.length > 3)
Expanded(
child: ListView.separated(
padding: EdgeInsets.zero,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: state.topPickList.length - 3,
itemBuilder: (BuildContext context, int index) {
KtShortVideoBean video = state.topPickList[index + 3];
return GestureDetector(
onTap: () => Get.toNamed(
KtRoutes.shortVideo,
arguments: {
'shortPlayId': video.shortPlayId,
'imageUrl': video.imageUrl ?? '',
},
ListView.separated(
padding: EdgeInsets.zero,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: state.topPickList.length - 3,
itemBuilder: (BuildContext context, int index) {
KtShortVideoBean video = state.topPickList[index + 3];
return GestureDetector(
onTap: () => Get.toNamed(
KtRoutes.shortVideo,
arguments: {
'shortPlayId': video.shortPlayId,
'imageUrl': video.imageUrl ?? '',
},
),
child: Container(
width: ScreenUtil().screenWidth - 30.w,
padding: EdgeInsets.all(10.w),
decoration: BoxDecoration(
color: Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(14.w),
),
child: Container(
width: ScreenUtil().screenWidth - 30.w,
padding: EdgeInsets.all(10.w),
decoration: BoxDecoration(
color: Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(14.w),
),
child: Row(
children: [
Stack(
clipBehavior: Clip.none,
alignment: Alignment.topLeft,
children: [
KtNetworkImage(
imageUrl: video.imageUrl ?? '',
width: 100.w,
height: 127.w,
borderRadius: BorderRadius.circular(12.w),
child: Row(
children: [
Stack(
clipBehavior: Clip.none,
alignment: Alignment.topLeft,
children: [
KtNetworkImage(
imageUrl: video.imageUrl ?? '',
width: 100.w,
height: 127.w,
borderRadius: BorderRadius.circular(12.w),
),
Container(
width: 24.w,
height: 24.w,
alignment: Alignment.center,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('top_other.png'.ktIcon),
fit: BoxFit.fill,
),
),
Container(
width: 24.w,
height: 24.w,
alignment: Alignment.center,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('top_other.png'.ktIcon),
fit: BoxFit.fill,
),
child: Text(
'${index + 4}',
style: TextStyle(
fontSize: 12.sp,
color: Colors.black,
fontWeight: FontWeight.w800,
fontStyle: FontStyle.italic,
),
child: Text(
'${index + 4}',
style: TextStyle(
fontSize: 12.sp,
color: Colors.black,
fontWeight: FontWeight.w800,
fontStyle: FontStyle.italic,
),
),
),
],
),
SizedBox(width: 12.w),
SizedBox(
width: 200.w,
height: 127.w,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
video.name ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.w500,
color: Color(0xFF1E1E20),
),
),
Text(
video.categoryList?.first.name ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Color(0xFF79C900),
),
),
Text(
video.description ?? '',
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 10.sp,
fontWeight: FontWeight.w400,
color: Color(0xFF5E5E5E),
),
),
Row(
children: [
Container(
padding: EdgeInsets.symmetric(
horizontal: 14.w,
vertical: 7.w,
),
decoration: BoxDecoration(
color: Color(0xFF1E1E20),
borderRadius: BorderRadius.circular(
100,
),
),
child: Row(
children: [
Image.asset(
'ic_top_play.png'.ktIcon,
width: 16.w,
),
SizedBox(width: 4.w),
Text(
'Play',
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w500,
color: Color(0xFFA7F62F),
),
),
],
),
),
],
),
],
),
SizedBox(width: 12.w),
SizedBox(
width: 200.w,
height: 127.w,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
video.name ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.w500,
color: Color(0xFF1E1E20),
),
),
Text(
video.categoryList?.first.name ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w400,
color: Color(0xFF79C900),
),
),
Text(
video.description ?? '',
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 10.sp,
fontWeight: FontWeight.w400,
color: Color(0xFF5E5E5E),
),
),
Row(
children: [
Container(
padding: EdgeInsets.symmetric(
horizontal: 14.w,
vertical: 7.w,
),
decoration: BoxDecoration(
color: Color(0xFF1E1E20),
borderRadius: BorderRadius.circular(
100,
),
),
child: Row(
children: [
Image.asset(
'ic_top_play.png'.ktIcon,
width: 16.w,
),
SizedBox(width: 4.w),
Text(
'Play',
style: TextStyle(
fontSize: 12.sp,
fontWeight: FontWeight.w500,
color: Color(0xFFA7F62F),
),
),
],
),
),
],
),
],
),
),
],
),
),
],
),
);
},
separatorBuilder: (_, __) => SizedBox(height: 10.w),
),
),
);
},
separatorBuilder: (_, __) => SizedBox(height: 10.w),
),
],
);

View File

@ -20,6 +20,7 @@ class KtMainPage extends StatefulWidget {
class _KtMainPageState extends State<KtMainPage>
with RouteAware, WidgetsBindingObserver {
final logic = Get.put(KtMainLogic());
final PageController _controller = PageController();
static const List _tabsTitle = [
{'icon': 'home', 'title': 'Home'},
@ -78,61 +79,67 @@ class _KtMainPageState extends State<KtMainPage>
}
}
},
child: Scaffold(
body: PageView.builder(
controller: _controller,
physics: const NeverScrollableScrollPhysics(),
onPageChanged: (index) {
_currentIndex = index;
setState(() {});
},
itemBuilder: (context, index) => _getTab(index),
itemCount: _tabsTitle.length,
),
bottomNavigationBar: BottomNavigationBar(
selectedItemColor: Color(0xFF1E1E20),
selectedLabelStyle: TextStyle(
fontSize: 10.sp,
fontWeight: FontWeight.w400,
),
unselectedLabelStyle: TextStyle(
fontSize: 10.sp,
color: Color(0xFF95959C),
fontWeight: FontWeight.w400,
),
type: BottomNavigationBarType.fixed,
currentIndex: _currentIndex,
onTap: (index) {
_currentIndex = index;
_controller.jumpToPage(index);
final myListLogic = Get.put(MyListLogic());
myListLogic.initData();
},
items: [
..._tabsTitle.map(
(item) => BottomNavigationBarItem(
icon: Container(
height: 24.w,
margin: EdgeInsets.only(top: 4.w),
alignment: Alignment.center,
child: Image.asset(
'ic_${item['icon']}_unsel.png'.ktIcon,
width: 24.w,
),
),
activeIcon: Container(
margin: EdgeInsets.only(top: 4.w),
child: Image.asset(
'ic_${item['icon']}_sel.png'.ktIcon,
width: 24.w,
height: 24.w,
),
),
label: item['title'],
),
child: GetBuilder<KtMainLogic>(
builder: (ctrl) {
return Scaffold(
body: PageView.builder(
controller: _controller,
physics: const NeverScrollableScrollPhysics(),
onPageChanged: (index) {
_currentIndex = index;
logic.curIndex = index;
setState(() {});
},
itemBuilder: (context, index) => _getTab(index),
itemCount: _tabsTitle.length,
),
],
),
bottomNavigationBar: BottomNavigationBar(
selectedItemColor: Color(0xFF1E1E20),
selectedLabelStyle: TextStyle(
fontSize: 10.sp,
fontWeight: FontWeight.w400,
),
unselectedLabelStyle: TextStyle(
fontSize: 10.sp,
color: Color(0xFF95959C),
fontWeight: FontWeight.w400,
),
type: BottomNavigationBarType.fixed,
currentIndex: _currentIndex,
onTap: (index) {
_currentIndex = index;
logic.curIndex = index;
_controller.jumpToPage(index);
final myListLogic = Get.put(MyListLogic());
myListLogic.initData();
},
items: [
..._tabsTitle.map(
(item) => BottomNavigationBarItem(
icon: Container(
height: 24.w,
margin: EdgeInsets.only(top: 4.w),
alignment: Alignment.center,
child: Image.asset(
'ic_${item['icon']}_unsel.png'.ktIcon,
width: 24.w,
),
),
activeIcon: Container(
margin: EdgeInsets.only(top: 4.w),
child: Image.asset(
'ic_${item['icon']}_sel.png'.ktIcon,
width: 24.w,
height: 24.w,
),
),
label: item['title'],
),
),
],
),
);
}
),
);
}
@ -164,170 +171,174 @@ class _KtMainPageState extends State<KtMainPage>
super.dispose();
}
// @override
// void didChangeAppLifecycleState(AppLifecycleState state) {
// super.didChangeAppLifecycleState(state);
// if (state == AppLifecycleState.paused) {
// _cycleLifeTime = DateTime.now();
// } else if (state == AppLifecycleState.resumed) {
// AppBadgePlus.updateBadge(0);
// final now = DateTime.now();
// final duration = now.difference(_cycleLifeTime ?? now);
// if ((duration.inMilliseconds > 3 || _isAndroidTwicePermission) && _pageOpen) {
// Future.delayed(const Duration(milliseconds: 1000)).then((_) {
// if (mounted) _checkDeeplink();
// });
// }
// _cycleLifeTime = null;
// }
// }
//
// void _checkDeeplink() {
// EasyThrottle.throttle('check-deeplink', Duration(seconds: 2), () async {
// try {
// // deepling链接
// // final adjustProvider = context.read<AdjustProvider>();
// final deepLink = AdjustService().deeplink ?? '';
// debugPrint('[CheckDeeplink] DEEPLINK链接: $deepLink');
// // 使使
// String useString = '';
// String useStr = '';
// //使
// if (deepLink != '') {
// useString = deepLink;
// useStr = deepLink;
// // deeplink
// AdjustService().clearDeeplink();
// debugPrint('----清理deeplink:${AdjustService().deeplink}');
// } else {
// //
// final clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
// final clipboardString = clipboardData?.text ?? '';
// debugPrint('[CheckDeeplink] 剪贴板原始链接: $clipboardString');
// //
// final clipboardStr =
// clipboardString != '' &&
// clipboardString.startsWith(Apis.W2A_PREFIX) &&
// clipboardString.contains(Apis.W2A_NAME)
// ? clipboardString.substring(Apis.W2A_PREFIX.length).trim()
// : '';
// debugPrint('[CheckDeeplink] 剪贴板处理链接: $clipboardStr');
// useString = clipboardString;
// useStr = clipboardStr;
// }
//
// // 使
// if (useStr != '') {
// final uri = Uri.tryParse(useStr);
// Map<String, dynamic> params = uri!.queryParameters;
// // params.forEach((k, v) {
// // debugPrint('----key:$k value:$v');
// // });
//
// final shortPlayId = params['short_play_id'];
// final videoId = params['video_id'] ?? 0;
// if (shortPlayId?.isEmpty ?? false) {
// debugPrint('[CheckDeeplink] 链接中没有参数');
// return;
// }
// // w2a
// HttpClient().request(Apis.uploadW2a, data: {"data": useString});
// debugPrint('[CheckDeeplink] 跳转链接: $useStr');
// debugPrint('[CheckDeeplink] 上报链接: $useString');
// debugPrint('---current route:${Get.currentRoute}');
// AdjustService().clearDeeplink();
// //
// await Clipboard.setData(const ClipboardData(text: ''));
// if (Get.currentRoute == AppRoutes.shortVideo) {
// // Get.offAndToNamed(
// // AppRoutes.shortVideo,
// // arguments: {'shortPlayId': int.parse(shortPlayId), "videoId": int.parse(videoId)},
// // );
// final logic = Get.put(ShortVideoLogic());
// logic.state.shortPlayId = int.parse(shortPlayId);
// logic.state.videoId = int.parse(videoId);
// logic.initData();
// } else {
// Get.toNamed(
// AppRoutes.shortVideo,
// arguments: {'shortPlayId': int.parse(shortPlayId.toString()), "videoId": int.parse(videoId.toString())},
// );
// }
// }
// } catch (e) {
// debugPrint('[AdjustManager] 读取剪贴板异常: $e');
// }
// });
// }
//
// _initFirebase() async {
// try {
// await Firebase.initializeApp();
// } catch (e) {
// debugPrint("----initFirebase err: $e");
// }
// if (Platform.isIOS) {
// await FirebaseIOS().initialize();
// } else if (Platform.isAndroid) {
// await FirebaseAndroid().initialize();
// await FirebaseAndroid().initializeNotifications();
// }
// //
// if (Platform.isIOS) {
// WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
// //
// RemoteMessage? remoteMessage = await FirebaseMessaging.instance.getInitialMessage();
// debugPrint("杀死app启动通知:$remoteMessage");
// if (remoteMessage != null) {
// final msgData = remoteMessage.data as Map;
// final msgNotification = remoteMessage.notification;
// final String? msgId = msgData['msg_id'];
// final String title = msgNotification?.title ?? "";
// if (msgId != null) {
// HttpClient().request(Apis.sendMessageReport, data: {"message_id": int.parse(msgId), "title": title});
// }
// FirebaseCommon().onFirebaseRoute(msgData);
// }
// });
// }
// }
//
// //
// Future<void> _checkNotificationPermission() async {
// final permissionStatus = await Permission.notification.status;
// if (permissionStatus.isDenied) {
// if (Platform.isAndroid) {
// //,w2a链接
// _isAndroidTwicePermission = true;
// }
// //
// await Permission.notification.request();
// } else if (permissionStatus.isPermanentlyDenied) {
// int now = DateTime.now().millisecondsSinceEpoch;
// int lastRequestTime = SpUtils().getInt(SpKeys.notiPermissionTime) ?? now;
// int hours = DateTime.now().difference(DateTime.fromMillisecondsSinceEpoch(lastRequestTime)).inHours;
// if (hours < 24) return;
// SpUtils().setInt(SpKeys.notiPermissionTime, now);
// //
// Get.dialog(
// CommonDialog(
// topIconWidget: Positioned(
// left: -35.w,
// top: 0.w,
// child: Image.asset('ic_dialog_subscribe.png'.icon, width: 140.w, height: 100.w),
// ),
// title: 'Turn on Notifications?',
// subTitle: 'Get alerts for new episodes and exclusive offers.',
// hasLeftBtn: false,
// rightBtnText: 'Allow',
// rightBtnFunc: () => openAppSettings(),
// ),
// );
// }
// }
//
// _restore() async {
// await Get.put(MineLogic()).getUserInfo();
// EasyThrottle.throttle('restore', Duration(minutes: 5), () => BuyUtils.restorePay(showTips: false));
// }
// @override
// void didChangeAppLifecycleState(AppLifecycleState state) {
// super.didChangeAppLifecycleState(state);
// if (state == AppLifecycleState.paused) {
// _cycleLifeTime = DateTime.now();
// } else if (state == AppLifecycleState.resumed) {
// AppBadgePlus.updateBadge(0);
// final now = DateTime.now();
// final duration = now.difference(_cycleLifeTime ?? now);
// if ((duration.inMilliseconds > 3 || _isAndroidTwicePermission) && _pageOpen) {
// Future.delayed(const Duration(milliseconds: 1000)).then((_) {
// if (mounted) _checkDeeplink();
// });
// }
// _cycleLifeTime = null;
// }
// }
//
// void _checkDeeplink() {
// EasyThrottle.throttle('check-deeplink', Duration(seconds: 2), () async {
// try {
// // deepling链接
// // final adjustProvider = context.read<AdjustProvider>();
// final deepLink = AdjustService().deeplink ?? '';
// debugPrint('[CheckDeeplink] DEEPLINK链接: $deepLink');
// // 使使
// String useString = '';
// String useStr = '';
// //使
// if (deepLink != '') {
// useString = deepLink;
// useStr = deepLink;
// // deeplink
// AdjustService().clearDeeplink();
// debugPrint('----清理deeplink:${AdjustService().deeplink}');
// } else {
// //
// final clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
// final clipboardString = clipboardData?.text ?? '';
// debugPrint('[CheckDeeplink] 剪贴板原始链接: $clipboardString');
// //
// final clipboardStr =
// clipboardString != '' &&
// clipboardString.startsWith(Apis.W2A_PREFIX) &&
// clipboardString.contains(Apis.W2A_NAME)
// ? clipboardString.substring(Apis.W2A_PREFIX.length).trim()
// : '';
// debugPrint('[CheckDeeplink] 剪贴板处理链接: $clipboardStr');
// useString = clipboardString;
// useStr = clipboardStr;
// }
//
// // 使
// if (useStr != '') {
// final uri = Uri.tryParse(useStr);
// Map<String, dynamic> params = uri!.queryParameters;
// // params.forEach((k, v) {
// // debugPrint('----key:$k value:$v');
// // });
//
// final shortPlayId = params['short_play_id'];
// final videoId = params['video_id'] ?? 0;
// if (shortPlayId?.isEmpty ?? false) {
// debugPrint('[CheckDeeplink] 链接中没有参数');
// return;
// }
// // w2a
// HttpClient().request(Apis.uploadW2a, data: {"data": useString});
// debugPrint('[CheckDeeplink] 跳转链接: $useStr');
// debugPrint('[CheckDeeplink] 上报链接: $useString');
// debugPrint('---current route:${Get.currentRoute}');
// AdjustService().clearDeeplink();
// //
// await Clipboard.setData(const ClipboardData(text: ''));
// if (Get.currentRoute == AppRoutes.shortVideo) {
// // Get.offAndToNamed(
// // AppRoutes.shortVideo,
// // arguments: {'shortPlayId': int.parse(shortPlayId), "videoId": int.parse(videoId)},
// // );
// final logic = Get.put(ShortVideoLogic());
// logic.state.shortPlayId = int.parse(shortPlayId);
// logic.state.videoId = int.parse(videoId);
// logic.initData();
// } else {
// Get.toNamed(
// AppRoutes.shortVideo,
// arguments: {'shortPlayId': int.parse(shortPlayId.toString()), "videoId": int.parse(videoId.toString())},
// );
// }
// }
// } catch (e) {
// debugPrint('[AdjustManager] 读取剪贴板异常: $e');
// }
// });
// }
//
// _initFirebase() async {
// try {
// await Firebase.initializeApp();
// } catch (e) {
// debugPrint("----initFirebase err: $e");
// }
// if (Platform.isIOS) {
// await FirebaseIOS().initialize();
// } else if (Platform.isAndroid) {
// await FirebaseAndroid().initialize();
// await FirebaseAndroid().initializeNotifications();
// }
// //
// if (Platform.isIOS) {
// WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
// //
// RemoteMessage? remoteMessage = await FirebaseMessaging.instance.getInitialMessage();
// debugPrint("杀死app启动通知:$remoteMessage");
// if (remoteMessage != null) {
// final msgData = remoteMessage.data as Map;
// final msgNotification = remoteMessage.notification;
// final String? msgId = msgData['msg_id'];
// final String title = msgNotification?.title ?? "";
// if (msgId != null) {
// HttpClient().request(Apis.sendMessageReport, data: {"message_id": int.parse(msgId), "title": title});
// }
// FirebaseCommon().onFirebaseRoute(msgData);
// }
// });
// }
// }
//
// //
// Future<void> _checkNotificationPermission() async {
// final permissionStatus = await Permission.notification.status;
// if (permissionStatus.isDenied) {
// if (Platform.isAndroid) {
// //,w2a链接
// _isAndroidTwicePermission = true;
// }
// //
// await Permission.notification.request();
// } else if (permissionStatus.isPermanentlyDenied) {
// int now = DateTime.now().millisecondsSinceEpoch;
// int lastRequestTime = SpUtils().getInt(SpKeys.notiPermissionTime) ?? now;
// int hours = DateTime.now().difference(DateTime.fromMillisecondsSinceEpoch(lastRequestTime)).inHours;
// if (hours < 24) return;
// SpUtils().setInt(SpKeys.notiPermissionTime, now);
// //
// Get.dialog(
// CommonDialog(
// topIconWidget: Positioned(
// left: -35.w,
// top: 0.w,
// child: Image.asset('ic_dialog_subscribe.png'.icon, width: 140.w, height: 100.w),
// ),
// title: 'Turn on Notifications?',
// subTitle: 'Get alerts for new episodes and exclusive offers.',
// hasLeftBtn: false,
// rightBtnText: 'Allow',
// rightBtnFunc: () => openAppSettings(),
// ),
// );
// }
// }
//
// _restore() async {
// await Get.put(MineLogic()).getUserInfo();
// EasyThrottle.throttle('restore', Duration(minutes: 5), () => BuyUtils.restorePay(showTips: false));
// }
}
class KtMainLogic extends GetxController{
int curIndex = 0;
}