Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions lib/pages/video/widgets/header_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,60 @@ mixin TimeBatteryMixin<T extends StatefulWidget> on State<T> {
);
}

/// 选择字幕
void showSelectSubtitle() {
showBottomSheet(
(context, setState) {
final theme = Theme.of(context);
return Padding(
padding: const EdgeInsets.all(12),
child: Material(
clipBehavior: Clip.hardEdge,
color: theme.colorScheme.surface,
borderRadius: const BorderRadius.all(Radius.circular(12)),
child: CustomScrollView(
slivers: [
const SliverToBoxAdapter(
child: SizedBox(
height: 45,
child: Center(
child: Text('选择字幕', style: titleStyle),
),
),
),
SliverList.builder(
itemCount: videoDetailCtr.subtitles.length + 1,
itemBuilder: (context, index) {
final bool isCurrent = videoDetailCtr.subtitle.value == index;
return ListTile(
dense: true,
onTap: () {
Get.back();
videoDetailCtr.setSubtitle(index);
},
contentPadding: const EdgeInsets.symmetric(
horizontal: 20,
),
title: Text(index == 0
? '关闭'
: videoDetailCtr.subtitles[index - 1].lanDoc!),

Copilot AI Dec 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential null pointer exception when accessing lanDoc property. If videoDetailCtr.subtitles[index - 1].lanDoc is null, the null assertion operator (!) will cause a runtime exception. Consider using null-aware operators or providing a fallback value to handle cases where lanDoc might be null.

Suggested change
: videoDetailCtr.subtitles[index - 1].lanDoc!),
: videoDetailCtr.subtitles[index - 1].lanDoc ?? '未知'),

Copilot uses AI. Check for mistakes.
trailing: isCurrent
? Icon(
Icons.done,
color: theme.colorScheme.primary,
)
: null,
);
},
),
],
),
),
);
},
);
}

List<Widget>? get timeBatteryWidgets {
if (_showCurrTime) {
return [
Expand Down Expand Up @@ -1321,6 +1375,23 @@ class HeaderControlState extends State<HeaderControl>
secondary: const Icon(Icons.comment_outlined, size: 20),
title: const Text('弹幕', style: titleStyle),
),
ListTile(
dense: true,
onTap: () {
Get.back();
showSelectSubtitle();
},
leading: const Icon(Icons.subtitles_outlined, size: 20),
title: const Text('字幕', style: titleStyle),
),
SwitchListTile(
value: videoDetailCtr.vttSubtitlesIndex.value > 0,
onChanged: (value) {
videoDetailCtr.setSubtitle(value ? 1 : 0);

Copilot AI Dec 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SwitchListTile always sets the subtitle to index 1 when enabled, but this doesn't account for the user's previously selected subtitle. If a user had subtitle 2 or 3 selected, turning the switch off and back on would reset it to subtitle 1 instead of restoring their previous selection. Consider storing and restoring the last selected subtitle index, or remove this control in favor of the more comprehensive subtitle selection dialog.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

},
secondary: const Icon(Icons.subtitles_outlined, size: 20),
title: const Text('开启字幕', style: titleStyle),
),
Comment on lines +1378 to +1394

Copilot AI Dec 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are duplicate subtitle UI controls in the settings menu. Both a ListTile (lines 1378-1386) that opens the subtitle selection dialog and a SwitchListTile (lines 1387-1394) for toggling subtitles are added here. Looking at the existing code, there's already another ListTile for subtitles at lines 1395-1403 that calls showSetSubtitle(). This creates three subtitle-related controls in the same menu, which is confusing and redundant for users. Consider consolidating these into a single, well-designed subtitle control interface.

Copilot uses AI. Check for mistakes.
ListTile(
dense: true,
onTap: () {
Expand Down
Loading