mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 02:57:22 +00:00
feat: implement dialog callback
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flutter_hbb/plugin/utils/dialogs.dart';
|
||||
|
||||
abstract class NativeHandler {
|
||||
bool onEvent(Map<String, dynamic> evt);
|
||||
}
|
||||
@@ -37,7 +41,13 @@ class NativeUiHandler extends NativeHandler {
|
||||
}
|
||||
|
||||
void onSelectPeers(OnSelectPeersCallbackDart cb, int userData) async {
|
||||
// TODO: design a UI interface to pick peers.
|
||||
cb(0, Pointer.fromAddress(0), 0, Pointer.fromAddress(userData));
|
||||
showPeerSelectionDialog(onPeersCallback: (peers) {
|
||||
String json = jsonEncode(<String, dynamic> {
|
||||
"peers": peers
|
||||
});
|
||||
final native = json.toNativeUtf8();
|
||||
cb(0, native.cast(), native.length, Pointer.fromAddress(userData));
|
||||
malloc.free(native);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
83
flutter/lib/plugin/utils/dialogs.dart
Normal file
83
flutter/lib/plugin/utils/dialogs.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hbb/common.dart';
|
||||
import 'package:flutter_hbb/models/platform_model.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
void showPeerSelectionDialog(
|
||||
{bool singleSelection = false,
|
||||
required Function(List<String>) onPeersCallback}) {
|
||||
final peers = bind.mainLoadRecentPeersSync();
|
||||
if (peers.isEmpty) {
|
||||
debugPrint("load recent peers sync failed.");
|
||||
return;
|
||||
}
|
||||
Map<String, dynamic> map = jsonDecode(peers);
|
||||
List<dynamic> peersList = map['peers'] ?? [];
|
||||
final selected = List<String>.empty(growable: true);
|
||||
|
||||
submit() async {
|
||||
onPeersCallback.call(selected);
|
||||
}
|
||||
|
||||
gFFI.dialogManager.show((setState, close, context) {
|
||||
return CustomAlertDialog(
|
||||
title:
|
||||
Text(translate(singleSelection ? "Select peers" : "Select a peer")),
|
||||
content: SizedBox(
|
||||
height: 300.0,
|
||||
child: ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
final Map<String, dynamic> peer = peersList[index];
|
||||
final String platform = peer['platform'] ?? "";
|
||||
final String id = peer['id'] ?? "";
|
||||
final String alias = peer['alias'] ?? "";
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
if (selected.contains(id)) {
|
||||
selected.remove(id);
|
||||
} else {
|
||||
selected.add(id);
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
key: ValueKey(index),
|
||||
height: 50.0,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).highlightColor,
|
||||
borderRadius: BorderRadius.circular(12.0)
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
|
||||
margin: EdgeInsets.symmetric(vertical: 4.0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
// platform
|
||||
SizedBox(width: 8.0,),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
getPlatformImage(platform, size: 34.0),
|
||||
],
|
||||
),
|
||||
SizedBox(width: 8.0,),
|
||||
// id/alias
|
||||
Expanded(child: Text(alias.isEmpty ? id : alias)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: peersList.length,
|
||||
itemExtent: 50.0,
|
||||
),
|
||||
),
|
||||
onSubmit: submit,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user