基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
refactor(timeline): redesign timeline fliter bottom sheet with material3 design
Predidit5516ae39d715
diff --git a/lib/pages/timeline/timeline_page.dart b/lib/pages/timeline/timeline_page.dartindex 7b60899b..c8828488 100644--- a/lib/pages/timeline/timeline_page.dart+++ b/lib/pages/timeline/timeline_page.dart@@ -28,11 +28,7 @@ class _TimelinePageState extends State<TimelinePage>late NavigationBarState navigationBarState;TabController? tabController;late bool showRating;-- final List<Tab> optionTabs = [- Tab(text: "排序方式"),- Tab(text: "过滤器"),- ];+ final GlobalKey filterSectionKey = GlobalKey();@overridevoid initState() {@@ -95,90 +91,46 @@ class _TimelinePageState extends State<TimelinePage>return d.year.toString() + Utils.getSeasonStringByMonth(d.month);}- void showSeasonBottomSheet(BuildContext context) {- final currDate = DateTime.now();- final years = List.generate(20, (index) => currDate.year - index);-- // 按年份分组生成可用季节- final yearSeasons = <int, List<DateTime>>{};- for (final year in years) {- final availableSeasons = <DateTime>[];- for (final season in seasons) {- final date = generateDateTime(year, season);- if (currDate.isAfter(date)) {- availableSeasons.add(date);- }- }- if (availableSeasons.isNotEmpty) {- yearSeasons[year] = availableSeasons;- }+ Future<void> scrollToFilterSection() async {+ final filterContext = filterSectionKey.currentContext;+ if (filterContext == null) {+ return;}- KazumiDialog.showBottomSheet(- context: context,- backgroundColor: Theme.of(context).colorScheme.surface,- shape: const RoundedRectangleBorder(- borderRadius: BorderRadius.vertical(top: Radius.circular(28)),- ),- clipBehavior: Clip.antiAlias,- useSafeArea: true,- constraints: BoxConstraints(- maxWidth: (MediaQuery.sizeOf(context).width >=- LayoutBreakpoint.medium['width']!)- ? MediaQuery.of(context).size.width * 9 / 16- : MediaQuery.of(context).size.width,- ),- isScrollControlled: true,- builder: (BuildContext sheetContext) {- final colorScheme = Theme.of(sheetContext).colorScheme;- return DraggableScrollableSheet(- initialChildSize: 0.72,- minChildSize: 0.4,- maxChildSize: 0.92,- expand: false,- builder: (context, scrollController) {- return Container(- decoration: BoxDecoration(- color: colorScheme.surface,- borderRadius:- const BorderRadius.vertical(top: Radius.circular(28)),- ),- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- Padding(- padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),- child: buildSeasonSheetHeader(sheetContext),- ),- // 年份季节列表- Expanded(- child: ListView.separated(- controller: scrollController,- padding: const EdgeInsets.fromLTRB(16, 8, 16, 28),- itemCount: yearSeasons.keys.length,- separatorBuilder: (_, __) => const SizedBox(height: 12),- itemBuilder: (context, index) {- final year = yearSeasons.keys.elementAt(index);- final availableSeasons = yearSeasons[year]!;-- return buildSeasonYearSection(- context,- year,- availableSeasons,- );- },- ),- ),- ],- ),- );- },- );- },+ await Scrollable.ensureVisible(+ filterContext,+ duration: const Duration(milliseconds: 280),+ curve: Curves.easeOutCubic,+ alignment: 0.04,);}- Widget buildSeasonSheetHeader(BuildContext context) {+ BoxConstraints buildTimelineBottomSheetConstraints(+ BuildContext context, {+ double? compactHeightFactor,+ }) {+ final mediaSize = MediaQuery.sizeOf(context);+ final maxWidth = mediaSize.width >= LayoutBreakpoint.medium['width']!+ ? mediaSize.width * 9 / 16+ : mediaSize.width;+ final maxHeight = compactHeightFactor != null+ ? (mediaSize.height >= LayoutBreakpoint.compact['height']!+ ? mediaSize.height * compactHeightFactor+ : mediaSize.height)+ : double.infinity;++ return BoxConstraints(+ maxWidth: maxWidth,+ maxHeight: maxHeight,+ );+ }++ Widget buildTimelineBottomSheetHeaderCard(+ BuildContext context, {+ required String title,+ required String description,+ required Widget footer,+ }) {final colorScheme = Theme.of(context).colorScheme;final textTheme = Theme.of(context).textTheme;@@ -200,7 +152,7 @@ class _TimelinePageState extends State<TimelinePage>crossAxisAlignment: CrossAxisAlignment.start,children: [Text(- '时间机器',+ title,style: textTheme.headlineSmall?.copyWith(color: colorScheme.onSurface,fontWeight: FontWeight.w700,@@ -208,7 +160,7 @@ class _TimelinePageState extends State<TimelinePage>),const SizedBox(height: 6),Text(- '按季度回到任意放送季,时间线会立即切换。',+ description,style: textTheme.bodyMedium?.copyWith(color: colorScheme.onSurfaceVariant,),@@ -225,25 +177,141 @@ class _TimelinePageState extends State<TimelinePage>],),const SizedBox(height: 16),- Container(- padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),- decoration: BoxDecoration(- color: colorScheme.secondaryContainer,- borderRadius: BorderRadius.circular(16),- ),- child: Text(- '当前查看 ${getStringByDateTime(timelineController.selectedDate)}',- style: textTheme.labelLarge?.copyWith(- color: colorScheme.onSecondaryContainer,- fontWeight: FontWeight.w600,+ footer,+ ],+ ),+ );+ }++ Widget buildTimelineBottomSheetShell(+ BuildContext context, {+ required Widget header,+ required Widget body,+ bool showDragHandle = false,+ }) {+ final colorScheme = Theme.of(context).colorScheme;++ return Container(+ decoration: BoxDecoration(+ color: colorScheme.surface,+ borderRadius: const BorderRadius.vertical(top: Radius.circular(28)),+ ),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ if (showDragHandle) ...[+ const SizedBox(height: 12),+ Container(+ width: 32,+ height: 4,+ decoration: BoxDecoration(+ color: colorScheme.onSurfaceVariant.withValues(alpha: 0.4),+ borderRadius: BorderRadius.circular(999),),),+ ],+ Padding(+ padding: EdgeInsets.fromLTRB(+ 16,+ showDragHandle ? 12 : 16,+ 16,+ 8,+ ),+ child: header,),+ Flexible(child: body),],),);}+ void showSeasonBottomSheet(BuildContext context) {+ final currDate = DateTime.now();+ final years = List.generate(20, (index) => currDate.year - index);++ // 按年份分组生成可用季节+ final yearSeasons = <int, List<DateTime>>{};+ for (final year in years) {+ final availableSeasons = <DateTime>[];+ for (final season in seasons) {+ final date = generateDateTime(year, season);+ if (currDate.isAfter(date)) {+ availableSeasons.add(date);+ }+ }+ if (availableSeasons.isNotEmpty) {+ yearSeasons[year] = availableSeasons;+ }+ }++ KazumiDialog.showBottomSheet(+ context: context,+ backgroundColor: Theme.of(context).colorScheme.surface,+ shape: const RoundedRectangleBorder(+ borderRadius: BorderRadius.vertical(top: Radius.circular(28)),+ ),+ clipBehavior: Clip.antiAlias,+ useSafeArea: true,+ constraints: buildTimelineBottomSheetConstraints(context),+ isScrollControlled: true,+ builder: (BuildContext sheetContext) {+ return DraggableScrollableSheet(+ initialChildSize: 0.72,+ minChildSize: 0.4,+ maxChildSize: 0.92,+ expand: false,+ builder: (context, scrollController) {+ return buildTimelineBottomSheetShell(+ sheetContext,+ header: buildSeasonSheetHeader(sheetContext),+ body: ListView.separated(+ controller: scrollController,+ padding: const EdgeInsets.fromLTRB(16, 8, 16, 28),+ itemCount: yearSeasons.keys.length,+ separatorBuilder: (_, __) => const SizedBox(height: 12),+ itemBuilder: (context, index) {+ final year = yearSeasons.keys.elementAt(index);+ final availableSeasons = yearSeasons[year]!;++ return buildSeasonYearSection(+ context,+ year,+ availableSeasons,+ );+ },+ ),+ );+ },+ );+ },+ );+ }++ Widget buildSeasonSheetHeader(BuildContext context) {+ final colorScheme = Theme.of(context).colorScheme;+ final textTheme = Theme.of(context).textTheme;++ return buildTimelineBottomSheetHeaderCard(+ context,+ title: '时间机器',+ description: '按季度回到任意放送季,时间线会立即切换。',+ footer: Container(+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),+ decoration: BoxDecoration(+ color: colorScheme.secondaryContainer,+ borderRadius: BorderRadius.circular(16),+ ),+ child: Text(+ '当前查看 ${getStringByDateTime(timelineController.selectedDate)}',+ style: textTheme.labelLarge?.copyWith(+ color: colorScheme.onSecondaryContainer,+ fontWeight: FontWeight.w600,+ ),+ ),+ ),+ );+ }+DateTime? getSelectedSeason(List<DateTime> availableSeasons) {for (final season in availableSeasons) {if (Utils.isSameSeason(timelineController.selectedDate, season)) {@@ -362,117 +430,384 @@ class _TimelinePageState extends State<TimelinePage>AnimeSeason(timelineController.selectedDate).toString();}- Widget showFilterSwitcher() {- return Wrap(- children: [- Observer(- builder: (context) => InkWell(- onTap: () {- timelineController.setNotShowAbandonedBangumis(- !timelineController.notShowAbandonedBangumis);- },- child: ListTile(- title: const Text('不显示已抛弃的番剧'),- trailing: Switch(- value: timelineController.notShowAbandonedBangumis,- onChanged: (value) {- timelineController.setNotShowAbandonedBangumis(value);- },+ String getSortTypeLabel(int sortType) {+ switch (sortType) {+ case 1:+ return '时间优先';+ case 2:+ return '评分优先';+ case 3:+ return '热度优先';+ default:+ return '热度优先';+ }+ }++ int getEnabledTimelineFilterCount() {+ var enabledCount = 0;+ if (timelineController.notShowAbandonedBangumis) {+ enabledCount++;+ }+ if (timelineController.notShowWatchedBangumis) {+ enabledCount++;+ }+ if (timelineController.onlyShowWatchingBangumis) {+ enabledCount++;+ }+ return enabledCount;+ }++ Widget buildTimelineOptionSummaryChip(+ BuildContext context, {+ required String label,+ bool highlighted = false,+ VoidCallback? onTap,+ IconData? trailingIcon,+ }) {+ final colorScheme = Theme.of(context).colorScheme;+ final textTheme = Theme.of(context).textTheme;+ final foregroundColor =+ highlighted ? colorScheme.onSecondaryContainer : colorScheme.onSurface;++ return Material(+ color: Colors.transparent,+ child: InkWell(+ onTap: onTap,+ borderRadius: BorderRadius.circular(16),+ child: Ink(+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),+ decoration: BoxDecoration(+ color: highlighted+ ? colorScheme.secondaryContainer+ : colorScheme.surfaceContainerHigh,+ borderRadius: BorderRadius.circular(16),+ ),+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(+ label,+ style: textTheme.labelLarge?.copyWith(+ color: foregroundColor,+ fontWeight: FontWeight.w600,+ ),),- ),+ if (trailingIcon != null) ...[+ const SizedBox(width: 6),+ Icon(+ trailingIcon,+ size: 18,+ color: foregroundColor,+ ),+ ],+ ],),),- Observer(- builder: (context) => InkWell(- onTap: () {- timelineController.setNotShowWatchedBangumis(- !timelineController.notShowWatchedBangumis);- },- child: ListTile(- title: const Text('不显示已看过的番剧'),- trailing: Switch(- value: timelineController.notShowWatchedBangumis,- onChanged: (value) {- timelineController.setNotShowWatchedBangumis(value);- },+ ),+ );+ }++ Widget buildTimelineOptionsSheetHeader(BuildContext context) {+ return buildTimelineBottomSheetHeaderCard(+ context,+ title: '时间线选项',+ description: '调整排序和过滤条件,结果会立即应用到当前时间线。',+ footer: Observer(+ builder: (context) {+ final enabledFilterCount = getEnabledTimelineFilterCount();+ return Wrap(+ spacing: 8,+ runSpacing: 8,+ children: [+ buildTimelineOptionSummaryChip(+ context,+ label: '当前排序 ${getSortTypeLabel(timelineController.sortType)}',+ highlighted: true,),+ buildTimelineOptionSummaryChip(+ context,+ label: enabledFilterCount == 0+ ? '未启用过滤条件'+ : '已启用 $enabledFilterCount 个过滤条件',+ onTap: scrollToFilterSection,+ ),+ ],+ );+ },+ ),+ );+ }++ Widget buildTimelineOptionSection(+ BuildContext context, {+ required String title,+ required String description,+ required Widget child,+ Key? sectionKey,+ }) {+ final colorScheme = Theme.of(context).colorScheme;+ final textTheme = Theme.of(context).textTheme;++ return Container(+ key: sectionKey,+ width: double.infinity,+ padding: const EdgeInsets.fromLTRB(20, 18, 20, 20),+ decoration: BoxDecoration(+ color: colorScheme.surfaceContainerLow,+ borderRadius: BorderRadius.circular(24),+ border: Border.all(+ color: colorScheme.outlineVariant.withValues(alpha: 0.5),+ ),+ ),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ title,+ style: textTheme.titleMedium?.copyWith(+ color: colorScheme.onSurface,+ fontWeight: FontWeight.w700,),),- ),- Observer(- builder: (context) => InkWell(- onTap: () {- timelineController.setOnlyShowWatchingBangumis(- !timelineController.onlyShowWatchingBangumis);- },- child: ListTile(- title: const Text('只显示在看的番剧'),- trailing: Switch(- value: timelineController.onlyShowWatchingBangumis,- onChanged: (value) {- timelineController.setOnlyShowWatchingBangumis(value);- },- ),+ const SizedBox(height: 4),+ Text(+ description,+ style: textTheme.bodyMedium?.copyWith(+ color: colorScheme.onSurfaceVariant,),),+ const SizedBox(height: 16),+ child,+ ],+ ),+ );+ }++ Widget buildSortOptionTile(+ BuildContext context, {+ required int sortType,+ required String title,+ required String description,+ required IconData icon,+ }) {+ final colorScheme = Theme.of(context).colorScheme;+ final textTheme = Theme.of(context).textTheme;+ final isSelected = timelineController.sortType == sortType;++ return Ink(+ decoration: BoxDecoration(+ color: isSelected+ ? colorScheme.secondaryContainer+ : colorScheme.surfaceContainerHigh,+ borderRadius: BorderRadius.circular(20),+ border: Border.all(+ color: isSelected+ ? colorScheme.secondary.withValues(alpha: 0.3)+ : colorScheme.outlineVariant.withValues(alpha: 0.4),+ ),+ ),+ child: ListTile(+ contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 6),+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),+ leading: Icon(+ icon,+ color: isSelected+ ? colorScheme.onSecondaryContainer+ : colorScheme.onSurfaceVariant,+ ),+ title: Text(+ title,+ style: textTheme.titleMedium?.copyWith(+ color: isSelected+ ? colorScheme.onSecondaryContainer+ : colorScheme.onSurface,+ fontWeight: FontWeight.w600,+ ),),- ],+ subtitle: Text(+ description,+ style: textTheme.bodySmall?.copyWith(+ color: isSelected+ ? colorScheme.onSecondaryContainer.withValues(alpha: 0.82)+ : colorScheme.onSurfaceVariant,+ ),+ ),+ trailing: Icon(+ isSelected+ ? Icons.check_circle_rounded+ : Icons.radio_button_unchecked_rounded,+ color: isSelected+ ? colorScheme.onSecondaryContainer+ : colorScheme.onSurfaceVariant,+ ),+ onTap: () {+ KazumiDialog.dismiss();+ timelineController.changeSortType(sortType);+ },+ ),);}- Widget showSortSwitcher() {- return Wrap(- children: [- Column(- mainAxisSize: MainAxisSize.min,- children: [- ListTile(- title: const Text('按热度排序'),- onTap: () {- KazumiDialog.dismiss();- timelineController.changeSortType(3);+ Widget buildFilterOptionTile(+ BuildContext context, {+ required String title,+ required String description,+ required bool value,+ required ValueChanged<bool> onChanged,+ required IconData icon,+ }) {+ final colorScheme = Theme.of(context).colorScheme;+ final textTheme = Theme.of(context).textTheme;++ return Ink(+ decoration: BoxDecoration(+ color: value+ ? colorScheme.secondaryContainer.withValues(alpha: 0.5)+ : colorScheme.surfaceContainerHigh,+ borderRadius: BorderRadius.circular(20),+ border: Border.all(+ color: value+ ? colorScheme.secondary.withValues(alpha: 0.24)+ : colorScheme.outlineVariant.withValues(alpha: 0.4),+ ),+ ),+ child: ListTile(+ contentPadding: const EdgeInsets.symmetric(horizontal: 20, vertical: 6),+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),+ leading: Icon(+ icon,+ color: value+ ? colorScheme.onSecondaryContainer+ : colorScheme.onSurfaceVariant,+ ),+ title: Text(+ title,+ style: textTheme.titleMedium?.copyWith(+ color: value+ ? colorScheme.onSecondaryContainer+ : colorScheme.onSurface,+ fontWeight: FontWeight.w600,+ ),+ ),+ subtitle: Text(+ description,+ style: textTheme.bodySmall?.copyWith(+ color: value+ ? colorScheme.onSecondaryContainer.withValues(alpha: 0.82)+ : colorScheme.onSurfaceVariant,+ ),+ ),+ trailing: Switch(+ value: value,+ onChanged: onChanged,+ ),+ onTap: () {+ onChanged(!value);+ },+ ),+ );+ }++ Widget showFilterSwitcher() {+ return buildTimelineOptionSection(+ context,+ sectionKey: filterSectionKey,+ title: '过滤器',+ description: '按收藏状态收起不需要显示的条目,支持连续调整。',+ child: Column(+ children: [+ Observer(+ builder: (context) => buildFilterOptionTile(+ context,+ title: '不显示已抛弃的番剧',+ description: '隐藏已经标记为抛弃的条目。',+ value: timelineController.notShowAbandonedBangumis,+ onChanged: (value) {+ timelineController.setNotShowAbandonedBangumis(value);},+ icon: Icons.heart_broken_rounded,),- ListTile(- title: const Text('按评分排序'),- onTap: () {- KazumiDialog.dismiss();- timelineController.changeSortType(2);+ ),+ const SizedBox(height: 12),+ Observer(+ builder: (context) => buildFilterOptionTile(+ context,+ title: '不显示已看过的番剧',+ description: '把已经看完的条目从时间线中移除。',+ value: timelineController.notShowWatchedBangumis,+ onChanged: (value) {+ timelineController.setNotShowWatchedBangumis(value);},+ icon: Icons.task_alt_rounded,),- ListTile(- title: const Text('按时间排序'),- onTap: () {- KazumiDialog.dismiss();- timelineController.changeSortType(1);+ ),+ const SizedBox(height: 12),+ Observer(+ builder: (context) => buildFilterOptionTile(+ context,+ title: '只显示在看的番剧',+ description: '聚焦当前正在追更的条目。',+ value: timelineController.onlyShowWatchingBangumis,+ onChanged: (value) {+ timelineController.setOnlyShowWatchingBangumis(value);},+ icon: Icons.live_tv_rounded,),- ],- ),- ],+ ),+ ],+ ),);}- Widget showTimelineOptionTabBar({required List<Widget> options}) {- return DefaultTabController(- length: optionTabs.length,- child: Scaffold(- body: Column(- children: [- PreferredSize(- preferredSize: Size.fromHeight(kToolbarHeight),- child: Material(- child: TabBar(- tabs: optionTabs,- ),- ),- ),- Expanded(- child: TabBarView(- children: options,- ))- ],- )));+ Widget showSortSwitcher() {+ return buildTimelineOptionSection(+ context,+ title: '排序方式',+ description: '选择每一天内番剧卡片的排列方式。',+ child: Column(+ children: [+ buildSortOptionTile(+ context,+ sortType: 3,+ title: '按热度排序',+ description: '优先展示讨论度和关注度更高的条目。',+ icon: Icons.local_fire_department_rounded,+ ),+ const SizedBox(height: 12),+ buildSortOptionTile(+ context,+ sortType: 2,+ title: '按评分排序',+ description: '优先展示评分更高的条目。',+ icon: Icons.star_rounded,+ ),+ const SizedBox(height: 12),+ buildSortOptionTile(+ context,+ sortType: 1,+ title: '按时间排序',+ description: '恢复默认时间顺序,方便按播出节奏查看。',+ icon: Icons.schedule_rounded,+ ),+ ],+ ),+ );+ }++ Widget buildTimelineOptionsSheet(BuildContext context) {+ return buildTimelineBottomSheetShell(+ context,+ header: buildTimelineOptionsSheetHeader(context),+ body: ListView(+ shrinkWrap: true,+ padding: const EdgeInsets.fromLTRB(16, 8, 16, 28),+ children: [+ showSortSwitcher(),+ const SizedBox(height: 12),+ showFilterSwitcher(),+ ],+ ),+ );}@override@@ -512,21 +847,15 @@ class _TimelinePageState extends State<TimelinePage>borderRadius: BorderRadius.vertical(top: Radius.circular(28)),),isScrollControlled: true,- constraints: BoxConstraints(- maxHeight: (MediaQuery.sizeOf(context).height >=- LayoutBreakpoint.compact['height']!)- ? MediaQuery.of(context).size.height * 1 / 3- : MediaQuery.of(context).size.height,- maxWidth: (MediaQuery.sizeOf(context).width >=- LayoutBreakpoint.medium['width']!)- ? MediaQuery.of(context).size.width * 9 / 16- : MediaQuery.of(context).size.width,+ constraints: buildTimelineBottomSheetConstraints(+ context,+ compactHeightFactor: 2 / 3,),clipBehavior: Clip.antiAlias,+ useSafeArea: true,context: context,builder: (context) {- return showTimelineOptionTabBar(- options: [showSortSwitcher(), showFilterSwitcher()]);+ return buildTimelineOptionsSheet(context);},);},