linux flutter example with bridge to rust and build system
This commit is contained in:
@@ -40,7 +40,7 @@ enum AttachmentState {
|
||||
|
||||
class VeilidConfig {
|
||||
final String programName;
|
||||
final String namespace;
|
||||
final String veilidNamespace;
|
||||
final bool capabilitiesProtocolUdp;
|
||||
final bool capabilitiesProtocolConnectTcp;
|
||||
final bool capabilitiesProtocolAcceptTcp;
|
||||
@@ -108,7 +108,7 @@ class VeilidConfig {
|
||||
|
||||
VeilidConfig({
|
||||
required this.programName,
|
||||
required this.namespace,
|
||||
required this.veilidNamespace,
|
||||
required this.capabilitiesProtocolUdp,
|
||||
required this.capabilitiesProtocolConnectTcp,
|
||||
required this.capabilitiesProtocolAcceptTcp,
|
||||
@@ -332,7 +332,7 @@ class VeilidFlutterImpl extends FlutterRustBridgeBase<VeilidFlutterWire>
|
||||
void _api_fill_to_wire_veilid_config(
|
||||
VeilidConfig apiObj, wire_VeilidConfig wireObj) {
|
||||
wireObj.program_name = _api2wire_String(apiObj.programName);
|
||||
wireObj.namespace = _api2wire_String(apiObj.namespace);
|
||||
wireObj.veilid_namespace = _api2wire_String(apiObj.veilidNamespace);
|
||||
wireObj.capabilities__protocol_udp =
|
||||
_api2wire_bool(apiObj.capabilitiesProtocolUdp);
|
||||
wireObj.capabilities__protocol_connect_tcp =
|
||||
@@ -708,7 +708,7 @@ class wire_StringList extends ffi.Struct {
|
||||
class wire_VeilidConfig extends ffi.Struct {
|
||||
external ffi.Pointer<wire_uint_8_list> program_name;
|
||||
|
||||
external ffi.Pointer<wire_uint_8_list> namespace_;
|
||||
external ffi.Pointer<wire_uint_8_list> veilid_namespace;
|
||||
|
||||
@ffi.Uint8()
|
||||
external int capabilities__protocol_udp;
|
||||
|
230
veilid-flutter/lib/bridge_generated.freezed.dart
Normal file
230
veilid-flutter/lib/bridge_generated.freezed.dart
Normal file
@@ -0,0 +1,230 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target
|
||||
|
||||
part of 'bridge_generated.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
|
||||
|
||||
/// @nodoc
|
||||
class _$VeilidUpdateTearOff {
|
||||
const _$VeilidUpdateTearOff();
|
||||
|
||||
Attachment attachment(AttachmentState field0) {
|
||||
return Attachment(
|
||||
field0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
const $VeilidUpdate = _$VeilidUpdateTearOff();
|
||||
|
||||
/// @nodoc
|
||||
mixin _$VeilidUpdate {
|
||||
AttachmentState get field0 => throw _privateConstructorUsedError;
|
||||
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(AttachmentState field0) attachment,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult Function(AttachmentState field0)? attachment,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(AttachmentState field0)? attachment,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(Attachment value) attachment,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult Function(Attachment value)? attachment,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(Attachment value)? attachment,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
$VeilidUpdateCopyWith<VeilidUpdate> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $VeilidUpdateCopyWith<$Res> {
|
||||
factory $VeilidUpdateCopyWith(
|
||||
VeilidUpdate value, $Res Function(VeilidUpdate) then) =
|
||||
_$VeilidUpdateCopyWithImpl<$Res>;
|
||||
$Res call({AttachmentState field0});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$VeilidUpdateCopyWithImpl<$Res> implements $VeilidUpdateCopyWith<$Res> {
|
||||
_$VeilidUpdateCopyWithImpl(this._value, this._then);
|
||||
|
||||
final VeilidUpdate _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function(VeilidUpdate) _then;
|
||||
|
||||
@override
|
||||
$Res call({
|
||||
Object? field0 = freezed,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
field0: field0 == freezed
|
||||
? _value.field0
|
||||
: field0 // ignore: cast_nullable_to_non_nullable
|
||||
as AttachmentState,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $AttachmentCopyWith<$Res>
|
||||
implements $VeilidUpdateCopyWith<$Res> {
|
||||
factory $AttachmentCopyWith(
|
||||
Attachment value, $Res Function(Attachment) then) =
|
||||
_$AttachmentCopyWithImpl<$Res>;
|
||||
@override
|
||||
$Res call({AttachmentState field0});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$AttachmentCopyWithImpl<$Res> extends _$VeilidUpdateCopyWithImpl<$Res>
|
||||
implements $AttachmentCopyWith<$Res> {
|
||||
_$AttachmentCopyWithImpl(Attachment _value, $Res Function(Attachment) _then)
|
||||
: super(_value, (v) => _then(v as Attachment));
|
||||
|
||||
@override
|
||||
Attachment get _value => super._value as Attachment;
|
||||
|
||||
@override
|
||||
$Res call({
|
||||
Object? field0 = freezed,
|
||||
}) {
|
||||
return _then(Attachment(
|
||||
field0 == freezed
|
||||
? _value.field0
|
||||
: field0 // ignore: cast_nullable_to_non_nullable
|
||||
as AttachmentState,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$Attachment implements Attachment {
|
||||
const _$Attachment(this.field0);
|
||||
|
||||
@override
|
||||
final AttachmentState field0;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'VeilidUpdate.attachment(field0: $field0)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(dynamic other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is Attachment &&
|
||||
const DeepCollectionEquality().equals(other.field0, field0));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, const DeepCollectionEquality().hash(field0));
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
$AttachmentCopyWith<Attachment> get copyWith =>
|
||||
_$AttachmentCopyWithImpl<Attachment>(this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>({
|
||||
required TResult Function(AttachmentState field0) attachment,
|
||||
}) {
|
||||
return attachment(field0);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>({
|
||||
TResult Function(AttachmentState field0)? attachment,
|
||||
}) {
|
||||
return attachment?.call(field0);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>({
|
||||
TResult Function(AttachmentState field0)? attachment,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (attachment != null) {
|
||||
return attachment(field0);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>({
|
||||
required TResult Function(Attachment value) attachment,
|
||||
}) {
|
||||
return attachment(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>({
|
||||
TResult Function(Attachment value)? attachment,
|
||||
}) {
|
||||
return attachment?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>({
|
||||
TResult Function(Attachment value)? attachment,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (attachment != null) {
|
||||
return attachment(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Attachment implements VeilidUpdate {
|
||||
const factory Attachment(AttachmentState field0) = _$Attachment;
|
||||
|
||||
@override
|
||||
AttachmentState get field0;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
$AttachmentCopyWith<Attachment> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
@@ -1,13 +1,38 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:veilid/bridge_generated.dart';
|
||||
|
||||
class Veilid {
|
||||
static const MethodChannel _channel = MethodChannel('veilid');
|
||||
const base = 'veilid_flutter';
|
||||
final path = Platform.isWindows
|
||||
? '$base.dll'
|
||||
: Platform.isMacOS
|
||||
? 'lib$base.dylib'
|
||||
: 'lib$base.so';
|
||||
late final dylib = Platform.isIOS ? DynamicLibrary.process() : DynamicLibrary.open(path);
|
||||
late final veilidApi = VeilidFlutterImpl(dylib);
|
||||
|
||||
static Future<String?> get platformVersion async {
|
||||
final String? version = await _channel.invokeMethod('getPlatformVersion');
|
||||
return version;
|
||||
class Veilid {
|
||||
|
||||
static VeilidFlutterImpl get api {
|
||||
if (veilidApi == null) {
|
||||
throw PlatformException(
|
||||
code: 'Library missing',
|
||||
details: 'veilid_core library could not be loaded dynamically',
|
||||
);
|
||||
}
|
||||
return veilidApi;
|
||||
}
|
||||
|
||||
// static const MethodChannel _channel = MethodChannel('veilid');
|
||||
|
||||
// static Future<String?> get platformVersion async {
|
||||
// final String? version = await _channel.invokeMethod('getPlatformVersion');
|
||||
// return version;
|
||||
// }
|
||||
|
||||
}
|
||||
|
@@ -8,37 +8,34 @@ import 'dart:html' as html show window;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
|
||||
|
||||
// xxx link in WASM version of veilid-flutter
|
||||
|
||||
/// A web implementation of the Veilid plugin.
|
||||
class VeilidWeb {
|
||||
static void registerWith(Registrar registrar) {
|
||||
final MethodChannel channel = MethodChannel(
|
||||
'veilid',
|
||||
const StandardMethodCodec(),
|
||||
registrar,
|
||||
);
|
||||
// final MethodChannel channel = MethodChannel(
|
||||
// 'veilid',
|
||||
// const StandardMethodCodec(),
|
||||
// registrar,
|
||||
// );
|
||||
|
||||
final pluginInstance = VeilidWeb();
|
||||
channel.setMethodCallHandler(pluginInstance.handleMethodCall);
|
||||
// final pluginInstance = VeilidWeb();
|
||||
// channel.setMethodCallHandler(pluginInstance.handleMethodCall);
|
||||
}
|
||||
|
||||
/// Handles method calls over the MethodChannel of this plugin.
|
||||
/// Note: Check the "federated" architecture for a new way of doing this:
|
||||
/// https://flutter.dev/go/federated-plugins
|
||||
Future<dynamic> handleMethodCall(MethodCall call) async {
|
||||
switch (call.method) {
|
||||
case 'getPlatformVersion':
|
||||
return getPlatformVersion();
|
||||
default:
|
||||
// switch (call.method) {
|
||||
// case 'getPlatformVersion':
|
||||
// return getPlatformVersion();
|
||||
// default:
|
||||
throw PlatformException(
|
||||
code: 'Unimplemented',
|
||||
details: 'veilid for web doesn\'t implement \'${call.method}\'',
|
||||
);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
/// Returns a [String] containing the version of the platform.
|
||||
Future<String> getPlatformVersion() {
|
||||
final version = html.window.navigator.userAgent;
|
||||
return Future.value(version);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user