diff --git a/flutter_hbb/lib/common.dart b/flutter_hbb/lib/common.dart index 36eff63ac..08dde00c6 100644 --- a/flutter_hbb/lib/common.dart +++ b/flutter_hbb/lib/common.dart @@ -4,6 +4,7 @@ import 'package:path_provider/path_provider.dart'; import 'dart:io'; import 'dart:ffi'; import 'dart:async'; +import 'dart:convert'; class HexColor extends Color { HexColor(final String hexColor) : super(_getColorFromHex(hexColor)); @@ -49,9 +50,18 @@ class FfiModel with ChangeNotifier { void peers() { var p = _getPeers(); - var x = Utf8.fromUtf8(p); - // https://github.com/brickpop/flutter-rust-ffi - _freeCString(p); + try { + List peers = json.decode(Utf8.fromUtf8(p)); + // https://github.com/brickpop/flutter-rust-ffi + _freeCString(p); + peers = peers + .map((s) => s as List) + .map((s) => + [s[0] as String, Peer.fromJson(s[1] as Map)]) + .toList(); + } catch (e) { + print(e); + } } Future initialzeFFI() async { @@ -70,3 +80,19 @@ class FfiModel with ChangeNotifier { notifyListeners(); } } + +class Peer { + final String name; + final String email; + + Peer(this.name, this.email); + + Peer.fromJson(Map json) + : name = json['name'], + email = json['email']; + + Map toJson() => { + 'name': name, + 'email': email, + }; +}