303 lines
8.2 KiB
Dart
303 lines
8.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:skywood/global/client/play_client.dart';
|
|
import 'package:skywood/main/lib_file.dart';
|
|
import 'package:skywood/pages/home/players/page/drama_detail_page.dart';
|
|
import 'package:skywood/utils/models/drama/skywood_category.dart';
|
|
import 'package:skywood/utils/models/drama/skywood_drama.dart';
|
|
import 'package:skywood/utils/tools/app_toast.dart';
|
|
import 'package:skywood/utils/tools/sky_time_tool.dart';
|
|
import 'package:skywood/utils/tools/widgets/sky_app_bar.dart';
|
|
import 'package:skywood/utils/tools/widgets/sky_common_widget.dart';
|
|
|
|
class CatePage extends StatefulWidget {
|
|
const CatePage({super.key,
|
|
this.preCategory,
|
|
});
|
|
|
|
final SkywoodCategory? preCategory;
|
|
|
|
@override
|
|
State<CatePage> createState() => _CatePageState();
|
|
}
|
|
|
|
class _CatePageState extends State<CatePage> {
|
|
final List<SkywoodCategory> _categories = [];
|
|
final List<SkywoodDrama> _dramas = [];
|
|
int _selectedIndex = 0;
|
|
int? _loadingCategoryId;
|
|
bool _loadingCategories = true;
|
|
bool _loadingDramas = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadCategories();
|
|
}
|
|
|
|
Future<void> _loadCategories() async {
|
|
List<SkywoodCategory> categories = [];
|
|
try {
|
|
categories = await PlayClient.getCategoriesList();
|
|
} catch (_) {
|
|
if (!mounted) return;
|
|
}
|
|
|
|
setState(() {
|
|
_categories
|
|
..clear()
|
|
..addAll(categories);
|
|
_loadingCategories = false;
|
|
});
|
|
|
|
if (categories.isNotEmpty) {
|
|
if (widget.preCategory != null) {
|
|
// 通过id获取_selectedIndex
|
|
setState(() {
|
|
_selectedIndex = _categories.indexWhere((element) => element.id == widget.preCategory!.id);
|
|
});
|
|
_loadCategoryDetail(widget.preCategory!.id);
|
|
return;
|
|
}
|
|
_loadCategoryDetail(categories.first.id);
|
|
}
|
|
}
|
|
|
|
Future<void> _loadCategoryDetail(int categoryId) async {
|
|
_loadingCategoryId = categoryId;
|
|
setState(() {
|
|
_loadingDramas = true;
|
|
_dramas.clear();
|
|
});
|
|
|
|
AppToast.showLottieLoading();
|
|
List<SkywoodDrama> dramas = [];
|
|
try {
|
|
dramas = await PlayClient.getCategoriesDetail(categoryId: categoryId);
|
|
} catch (_) {
|
|
if (!mounted || _loadingCategoryId != categoryId) return;
|
|
}
|
|
|
|
AppToast.dismiss();
|
|
if (!mounted || _loadingCategoryId != categoryId) return;
|
|
|
|
setState(() {
|
|
_dramas.addAll(dramas);
|
|
_loadingDramas = false;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
appBar: SkyAppBar(
|
|
title: 'Explore Genres',
|
|
titleColor: CommonColor.black,
|
|
),
|
|
body: SafeArea(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildCategoryList(),
|
|
Expanded(child: _buildDramaList()),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
|
|
Widget _buildCategoryList() {
|
|
return Container(
|
|
width: 110.w,
|
|
height: double.infinity,
|
|
padding: EdgeInsets.only(top: 12.h, bottom: 18.h),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFF2FFF0),
|
|
borderRadius: BorderRadius.only(topRight: Radius.circular(8.r)),
|
|
),
|
|
child: _loadingCategories
|
|
? const SizedBox.shrink()
|
|
: ListView.builder(
|
|
padding: EdgeInsets.zero,
|
|
itemCount: _categories.length,
|
|
itemBuilder: (context, index) {
|
|
return _buildCategoryItem(index);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildCategoryItem(int index) {
|
|
final category = _categories[index];
|
|
final selected = index == _selectedIndex;
|
|
|
|
return GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () {
|
|
if (selected) return;
|
|
setState(() {
|
|
_selectedIndex = index;
|
|
});
|
|
_loadCategoryDetail(category.id);
|
|
},
|
|
child: SizedBox(
|
|
height: 58,
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
if (selected)
|
|
Positioned(
|
|
left: 5, top: 16.5,
|
|
child: HelpImg.asset(
|
|
ConstImg.cateSelLeft,
|
|
width: 10,
|
|
height: 25,
|
|
fit: BoxFit.fill,
|
|
),
|
|
),
|
|
if (selected)
|
|
Positioned(
|
|
right: 5, top: 16.5,
|
|
child: HelpImg.asset(
|
|
ConstImg.cateSelRight,
|
|
width: 10,
|
|
height: 25,
|
|
fit: BoxFit.fill,
|
|
),
|
|
),
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 12.w),
|
|
child: SkyText(
|
|
text: category.name,
|
|
color: selected
|
|
? CommonColor.primacyColor
|
|
: Colors.black.withAlpha(100),
|
|
fontSize: 11,
|
|
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
|
textAlign: TextAlign.center,
|
|
maxLines: 2,
|
|
lineHeight: 1.05,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildDramaList() {
|
|
if (_loadingDramas) {
|
|
return const SizedBox();
|
|
}
|
|
|
|
if (_dramas.isEmpty) {
|
|
return Center(
|
|
child: SkyText(
|
|
text: 'No Data',
|
|
color: Colors.black.withAlpha(100),
|
|
fontSize: 13,
|
|
),
|
|
);
|
|
}
|
|
|
|
return ListView.separated(
|
|
padding: EdgeInsets.only(left: 8.w, right: 10.w, bottom: 24.h),
|
|
itemCount: _dramas.length,
|
|
separatorBuilder: (context, index) => SizedBox(height: 10.h),
|
|
itemBuilder: (context, index) {
|
|
return _DramaItem(drama: _dramas[index]);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class _DramaItem extends StatelessWidget {
|
|
const _DramaItem({required this.drama});
|
|
|
|
final SkywoodDrama drama;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
height: 104.h,
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
HelpImg.networkRadius(
|
|
drama.imageUrl,
|
|
width: 80.w,
|
|
height: 104.h,
|
|
fit: BoxFit.fill,
|
|
borderRadius: BorderRadius.circular(4.r),
|
|
),
|
|
SizedBox(width: 8.w),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(top: 2.h),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
SkyText(
|
|
text: drama.name,
|
|
color: CommonColor.black,
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.w700,
|
|
maxLines: 2,
|
|
lineHeight: 1.08,
|
|
),
|
|
SizedBox(height: 7.h),
|
|
SkyText(
|
|
text: drama.description,
|
|
color: Colors.black.withAlpha(92),
|
|
fontSize: 11,
|
|
maxLines: 2,
|
|
lineHeight: 1.2,
|
|
),
|
|
const Spacer(),
|
|
Row(
|
|
children: [
|
|
_TipView(icon: ConstImg.star, text: '10.0'),
|
|
SizedBox(width: 12.w),
|
|
_TipView(
|
|
icon: ConstImg.look,
|
|
text: SkyTimeTool.formatNum(drama.watchTotal),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
).addInkWell(onTap: () => HelpNav.to(DramaDetailPage(dramaBean: drama)));
|
|
}
|
|
}
|
|
|
|
class _TipView extends StatelessWidget {
|
|
const _TipView({required this.icon, required this.text});
|
|
|
|
final String icon;
|
|
final String text;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
HelpImg.asset(icon, width: 12.w, height: 12.w),
|
|
SizedBox(width: 2.w),
|
|
SkyText(text: text, color: Colors.black.withAlpha(110), fontSize: 10),
|
|
],
|
|
);
|
|
}
|
|
}
|