コード例 #1
0
        /// <summary>
        /// Creates the Flutter module to be integrated into Xamarin (native) applications.
        /// </summary>
        private static DartProject CreateFlutterModule(NewProjectSettings settings, bool verbose = false)
        {
            try
            {
                DartProject project = FlutterTools.CreateModule(settings.FlutterSubfolderPath, settings.FlutterModuleName,
                                                                organization: settings.OrganizationId, verbose: verbose);

                FlutterTools.CreatePackage(settings.FlutterSubfolderPath, settings.FlutterPackageName,
                                           description: DartBridgeBuilder.DefaultPackageDescription, verbose: verbose);

                project.AddDevDependency(new DartProjectDependency(settings.FlutterPackageName, DartProjectDependencyType.Path, $"../{settings.FlutterPackageName}"));
                project.ApplyChanges();

                // Before building the module on a new machine, run "flutter pub get" first
                // to regenerate the .android/ and .ios/ directories.
                // (see: https://flutter.dev/docs/development/add-to-app/android/project-setup#create-a-flutter-module
                //  and: https://flutter.dev/docs/development/add-to-app/ios/project-setup#create-a-flutter-module)
                project.GetDependencies(verbose);

                return(project);
            }
            catch (Exception e)
            {
                throw new CommandLineException(CommandLineErrorCode.NewProject_CreateFlutterModuleFailed, e);
            }
        }
コード例 #2
0
        private static DartProject InitializePackage(string outputDir, string packageName, string packageDescription = null, bool verbose = false)
        {
            // Load or create Flutter package if it doesn't already exist

            string      packageFolder = Path.Combine(outputDir, packageName);
            DartProject dartProject   = new DartProject(new DirectoryInfo(packageFolder));

            try
            {
                dartProject.Load();
                if (verbose)
                {
                    Console.WriteLine($"Flutter package \"{packageFolder}\" loaded successfully.");
                    Console.WriteLine();
                }
            }
            catch (DartProjectException ex)
            {
                switch (ex.Error)
                {
                case DartProjectError.PrjFolderNotExists:
                    Console.Write($"Generating Flutter package \"{packageName}\" within directory {outputDir}... ");
                    dartProject = FlutterTools.CreatePackage(outputDir, packageName, !string.IsNullOrEmpty(packageDescription) ? packageDescription : DefaultPackageDescription, verbose);
                    Console.Write("Done.");
                    Console.WriteLine();
                    break;

                case DartProjectError.LibFolderNotExists:
                case DartProjectError.PubspecNotExists:
                case DartProjectError.PubspecInvalidFormat:
                    throw;
                }
            }

            return(dartProject);
        }