refact: mobile more actions, divider (#8512)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
parent
c1bbdaf9ae
commit
d689bbf38e
@ -6,7 +6,6 @@ import 'package:flutter_hbb/common.dart';
|
|||||||
import 'package:flutter_hbb/common/shared_state.dart';
|
import 'package:flutter_hbb/common/shared_state.dart';
|
||||||
import 'package:flutter_hbb/common/widgets/dialog.dart';
|
import 'package:flutter_hbb/common/widgets/dialog.dart';
|
||||||
import 'package:flutter_hbb/consts.dart';
|
import 'package:flutter_hbb/consts.dart';
|
||||||
import 'package:flutter_hbb/models/input_model.dart';
|
|
||||||
import 'package:flutter_hbb/models/model.dart';
|
import 'package:flutter_hbb/models/model.dart';
|
||||||
import 'package:flutter_hbb/models/platform_model.dart';
|
import 'package:flutter_hbb/models/platform_model.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@ -23,6 +22,20 @@ class TTextMenu {
|
|||||||
required this.onPressed,
|
required this.onPressed,
|
||||||
this.trailingIcon,
|
this.trailingIcon,
|
||||||
this.divider = false});
|
this.divider = false});
|
||||||
|
|
||||||
|
Widget getChild() {
|
||||||
|
if (trailingIcon != null) {
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
child,
|
||||||
|
trailingIcon!,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TRadioMenu<T> {
|
class TRadioMenu<T> {
|
||||||
@ -77,36 +90,6 @@ List<TTextMenu> toolbarControls(BuildContext context, String id, FFI ffi) {
|
|||||||
final sessionId = ffi.sessionId;
|
final sessionId = ffi.sessionId;
|
||||||
|
|
||||||
List<TTextMenu> v = [];
|
List<TTextMenu> v = [];
|
||||||
if (isMobile &&
|
|
||||||
pi.platform == kPeerPlatformAndroid &&
|
|
||||||
perms['keyboard'] != false) {
|
|
||||||
v.addAll([
|
|
||||||
TTextMenu(
|
|
||||||
child: Text(translate('Back')),
|
|
||||||
onPressed: () => ffi.inputModel.onMobileBack(),
|
|
||||||
),
|
|
||||||
TTextMenu(
|
|
||||||
child: Text(translate('Home')),
|
|
||||||
onPressed: () => ffi.inputModel.onMobileHome(),
|
|
||||||
),
|
|
||||||
TTextMenu(
|
|
||||||
child: Text(translate('Apps')),
|
|
||||||
onPressed: () => ffi.inputModel.onMobileApps(),
|
|
||||||
),
|
|
||||||
TTextMenu(
|
|
||||||
child: Text(translate('Volume up')),
|
|
||||||
onPressed: () => ffi.inputModel.onMobileVolumeUp(),
|
|
||||||
),
|
|
||||||
TTextMenu(
|
|
||||||
child: Text(translate('Volume down')),
|
|
||||||
onPressed: () => ffi.inputModel.onMobileVolumeDown(),
|
|
||||||
),
|
|
||||||
TTextMenu(
|
|
||||||
child: Text(translate('Power')),
|
|
||||||
onPressed: () => ffi.inputModel.onMobilePower(),
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
// elevation
|
// elevation
|
||||||
if (perms['keyboard'] != false && ffi.elevationModel.showRequestMenu) {
|
if (perms['keyboard'] != false && ffi.elevationModel.showRequestMenu) {
|
||||||
v.add(
|
v.add(
|
||||||
|
@ -553,29 +553,62 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
color: MyTheme.canvasColor, child: Stack(children: paints));
|
color: MyTheme.canvasColor, child: Stack(children: paints));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<TTextMenu> _getMobileActionMenus() {
|
||||||
|
if (gFFI.ffiModel.pi.platform != kPeerPlatformAndroid ||
|
||||||
|
!gFFI.ffiModel.keyboard) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
TTextMenu(
|
||||||
|
child: Text(translate('Back')),
|
||||||
|
onPressed: () => gFFI.inputModel.onMobileBack(),
|
||||||
|
),
|
||||||
|
TTextMenu(
|
||||||
|
child: Text(translate('Home')),
|
||||||
|
onPressed: () => gFFI.inputModel.onMobileHome(),
|
||||||
|
),
|
||||||
|
TTextMenu(
|
||||||
|
child: Text(translate('Apps')),
|
||||||
|
onPressed: () => gFFI.inputModel.onMobileApps(),
|
||||||
|
),
|
||||||
|
TTextMenu(
|
||||||
|
child: Text(translate('Volume up')),
|
||||||
|
onPressed: () => gFFI.inputModel.onMobileVolumeUp(),
|
||||||
|
),
|
||||||
|
TTextMenu(
|
||||||
|
child: Text(translate('Volume down')),
|
||||||
|
onPressed: () => gFFI.inputModel.onMobileVolumeDown(),
|
||||||
|
),
|
||||||
|
TTextMenu(
|
||||||
|
child: Text(translate('Power')),
|
||||||
|
onPressed: () => gFFI.inputModel.onMobilePower(),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
void showActions(String id) async {
|
void showActions(String id) async {
|
||||||
final size = MediaQuery.of(context).size;
|
final size = MediaQuery.of(context).size;
|
||||||
final x = 120.0;
|
final x = 120.0;
|
||||||
final y = size.height;
|
final y = size.height;
|
||||||
|
final mobileActionMenus = _getMobileActionMenus();
|
||||||
final menus = toolbarControls(context, id, gFFI);
|
final menus = toolbarControls(context, id, gFFI);
|
||||||
getChild(TTextMenu menu) {
|
|
||||||
if (menu.trailingIcon != null) {
|
|
||||||
return Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
menu.child,
|
|
||||||
menu.trailingIcon!,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
return menu.child;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final more = menus
|
final List<PopupMenuEntry<int>> more = [
|
||||||
.asMap()
|
...mobileActionMenus
|
||||||
.entries
|
.asMap()
|
||||||
.map((e) => PopupMenuItem<int>(child: getChild(e.value), value: e.key))
|
.entries
|
||||||
.toList();
|
.map((e) =>
|
||||||
|
PopupMenuItem<int>(child: e.value.getChild(), value: e.key))
|
||||||
|
.toList(),
|
||||||
|
if (mobileActionMenus.isNotEmpty) PopupMenuDivider(),
|
||||||
|
...menus
|
||||||
|
.asMap()
|
||||||
|
.entries
|
||||||
|
.map((e) => PopupMenuItem<int>(
|
||||||
|
child: e.value.getChild(),
|
||||||
|
value: e.key + mobileActionMenus.length))
|
||||||
|
.toList(),
|
||||||
|
];
|
||||||
() async {
|
() async {
|
||||||
var index = await showMenu(
|
var index = await showMenu(
|
||||||
context: context,
|
context: context,
|
||||||
@ -583,8 +616,12 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
items: more,
|
items: more,
|
||||||
elevation: 8,
|
elevation: 8,
|
||||||
);
|
);
|
||||||
if (index != null && index < menus.length) {
|
if (index != null) {
|
||||||
menus[index].onPressed.call();
|
if (index < mobileActionMenus.length) {
|
||||||
|
mobileActionMenus[index].onPressed.call();
|
||||||
|
} else if (index < mobileActionMenus.length + more.length) {
|
||||||
|
menus[index - mobileActionMenus.length].onPressed.call();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
@ -639,23 +676,11 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
),
|
),
|
||||||
onPressVoiceCall),
|
onPressVoiceCall),
|
||||||
];
|
];
|
||||||
getChild(TTextMenu menu) {
|
|
||||||
if (menu.trailingIcon != null) {
|
|
||||||
return Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
menu.child,
|
|
||||||
menu.trailingIcon!,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
return menu.child;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final menuItems = menus
|
final menuItems = menus
|
||||||
.asMap()
|
.asMap()
|
||||||
.entries
|
.entries
|
||||||
.map((e) => PopupMenuItem<int>(child: getChild(e.value), value: e.key))
|
.map((e) => PopupMenuItem<int>(child: e.value.getChild(), value: e.key))
|
||||||
.toList();
|
.toList();
|
||||||
Future.delayed(Duration.zero, () async {
|
Future.delayed(Duration.zero, () async {
|
||||||
final size = MediaQuery.of(context).size;
|
final size = MediaQuery.of(context).size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user