Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在颤振镖中实现插件架构_Flutter_Dart_Mobile Development_Plugin Architecture - Fatal编程技术网

Flutter 如何在颤振镖中实现插件架构

Flutter 如何在颤振镖中实现插件架构,flutter,dart,mobile-development,plugin-architecture,Flutter,Dart,Mobile Development,Plugin Architecture,我想在Flatter Dart中实现一个插件架构。程序如下: 1.用户下载应用程序。 2.用户从我们的站点加载插件。 3.应用程序会查看插件是否实现了接口。 4.如果实现了该接口,则将信息和小部件从插件加载到应用程序 我在C#中实现了相同的过程,在运行时使用编译的DLL加载,但无法为flifter找到它 我已经研究了互联网上以前的一些问题和资源,我发现最接近的是这个,但是Dart 2中不支持该插件,因此不推荐使用 这就是我用C#实现的代码 inti=0; if(Directory.Exists(

我想在Flatter Dart中实现一个插件架构。程序如下: 1.用户下载应用程序。 2.用户从我们的站点加载插件。 3.应用程序会查看插件是否实现了接口。 4.如果实现了该接口,则将信息和小部件从插件加载到应用程序

我在C#中实现了相同的过程,在运行时使用编译的DLL加载,但无法为flifter找到它

我已经研究了互联网上以前的一些问题和资源,我发现最接近的是这个,但是Dart 2中不支持该插件,因此不推荐使用

这就是我用C#实现的代码

inti=0;
if(Directory.Exists(“Plugins”))
{
dllFileNames=Directory.GetFiles(“插件”,“*.dll”);
ICollection assemblies=新列表(dllFileNames.Length);
foreach(dllFileNames中的字符串dllFile)
{
AssemblyName an=AssemblyName.GetAssemblyName(dllFile);
组件组件=组件负载(an);
组件。添加(组件);
}
类型pluginType=typeof(IPlugin);
列表插件类型=新列表();
foreach(部件中的部件)
{
如果(程序集!=null)
{
Type[]types=assembly.GetTypes();
foreach(类型中的类型)
{
if(type.IsInterface | | type.IsAbstract)
{
继续;
}
else if(pluginType.IsAssignableFrom(type))
{
pluginTypes.Add(类型);
}
}
}
i++;
}
ICollection plugins=新列表(pluginTypes.Count);
foreach(插件类型中的类型)
{
IPlugin插件=(IPlugin)Activator.CreateInstance(类型);
plugin.Initiate();
plugins.Add(plugin);
}
返回插件;
}
返回null;

这可能是不可能的


AOT编译的一部分是准备将你的应用程序上传到商店,这是一个摇树过程,删除了当前构建不需要的所有内容。因此,你的插件需要调用的任何东西都不见了。

非Dart解决方案可能是,也可能没有尝试过这些方法。或者甚至一个webview看起来更复杂,但基本上提供一个NodeJS运行时似乎更强大。有新的解决方案吗?
            int i = 0;

            if (Directory.Exists("Plugins"))
            {
                dllFileNames = Directory.GetFiles("Plugins", "*.dll");

                ICollection<Assembly> assemblies = new List<Assembly>(dllFileNames.Length);
                foreach (string dllFile in dllFileNames)
                {
                    AssemblyName an = AssemblyName.GetAssemblyName(dllFile);
                    Assembly assembly = Assembly.Load(an);
                    assemblies.Add(assembly);
                }

                Type pluginType = typeof(IPlugin);
                List<Type> pluginTypes = new List<Type>();
                foreach (Assembly assembly in assemblies)
                {
                    if (assembly != null)
                    {
                        Type[] types = assembly.GetTypes();
                        foreach (Type type in types)
                        {
                            if (type.IsInterface || type.IsAbstract)
                            {
                                continue;
                            }
                            else if (pluginType.IsAssignableFrom(type))
                            {
                                pluginTypes.Add(type);
                            }
                        }
                    }

                    i++;
                }

                ICollection<IPlugin> plugins = new List<IPlugin>(pluginTypes.Count);
                foreach (Type type in pluginTypes)
                {
                    IPlugin plugin = (IPlugin)Activator.CreateInstance(type);
                    plugin.Initiate();
                    plugins.Add(plugin);
                }

                return plugins;
            }

            return null;