feat: improve rate menu

This commit is contained in:
22
2025-06-02 18:51:40 +08:00
parent 8dbb2ac56d
commit a1c0fb53a7
3 changed files with 51 additions and 46 deletions

View File

@@ -1,8 +1,11 @@
// ignore: unnecessary_library_name
library my_app.globals;
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
List<String> arguments = [];
String? initUri;
PermissionStatus? storagePermissionStatus;
final moreMenuKey = GlobalKey<PopupMenuButtonState>();
final rateMenuKey = GlobalKey<PopupMenuButtonState>();

View File

@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_zustand/flutter_zustand.dart';
import 'package:iris/globals.dart';
import 'package:iris/models/player.dart';
import 'package:iris/models/storages/local.dart';
import 'package:iris/models/store/app_state.dart';
@@ -223,59 +224,54 @@ class ControlBar extends HookWidget {
),
),
if (MediaQuery.of(context).size.width > 600)
Builder(
builder: (context) => DarkTheme(
PopupMenuButton(
key: rateMenuKey,
clipBehavior: Clip.hardEdge,
constraints: const BoxConstraints(minWidth: 0),
itemBuilder: (BuildContext context) => [
0.25,
0.5,
0.75,
1.0,
1.25,
1.5,
1.75,
2.0,
3.0,
4.0,
5.0,
]
.map(
(item) => PopupMenuItem(
child: Text(
'${item}X',
style: TextStyle(
color: item == rate
? Theme.of(context).colorScheme.primary
: null,
fontWeight: item == rate
? FontWeight.bold
: FontWeight.w100,
),
),
onTap: () async {
showControl();
useAppStore().updateRate(item);
},
),
)
.toList(),
child: DarkTheme(
child: Tooltip(
message: t.playback_speed,
child: TextButton(
onPressed: () =>
rateMenuKey.currentState?.showButtonMenu(),
child: Text(
'${rate}X',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).brightness ==
Brightness.dark
? Theme.of(context).colorScheme.onSurface
: Theme.of(context).colorScheme.surface,
),
),
onPressed: () => showControlForHover(
showCustomMenu(
context,
items: [
0.25,
0.5,
0.75,
1.0,
1.25,
1.5,
1.75,
2.0,
3.0,
4.0,
5.0,
]
.map(
(item) => PopupMenuItem(
child: Text(
'${item}X',
style: TextStyle(
color: item == rate
? Theme.of(context)
.colorScheme
.primary
: null,
fontWeight: item == rate
? FontWeight.bold
: FontWeight.w100,
),
),
onTap: () async {
showControl();
useAppStore().updateRate(item);
},
),
)
.toList(),
color: Colors.white.withValues(alpha: 0.9),
),
),
),
@@ -430,6 +426,7 @@ class ControlBar extends HookWidget {
),
),
child: PopupMenuButton(
key: moreMenuKey,
icon: const Icon(
Icons.more_vert_rounded,
size: 20,

View File

@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_zustand/flutter_zustand.dart';
import 'package:iris/globals.dart';
import 'package:iris/hooks/use_app_lifecycle.dart';
import 'package:iris/hooks/use_brightness.dart';
import 'package:iris/hooks/use_cover.dart';
@@ -412,6 +413,10 @@ class IrisPlayer extends HookWidget {
case LogicalKeyboardKey.minus:
await player.stepBackward();
break;
case LogicalKeyboardKey.contextMenu:
showControl();
moreMenuKey.currentState?.showButtonMenu();
break;
default:
break;
}