Flutter Engine
dart_project.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_
7 
8 #include <string>
9 #include <vector>
10 
11 namespace flutter {
12 
13 // A set of Flutter and Dart assets used to initialize a Flutter engine.
14 class DartProject {
15  public:
16  // Creates a DartProject from a series of absolute paths.
17  // The three paths are:
18  // - assets_path: Path to the assets directory as built by the Flutter tool.
19  // - icu_data_path: Path to the icudtl.dat file.
20  // - aot_library_path: Path to the AOT snapshot file.
21  //
22  // The paths must be absolute in a UWP app. In a win32 app, they can be
23  // relative to the directory containing the running executable.
24  explicit DartProject(const std::wstring& assets_path,
25  const std::wstring& icu_data_path,
26  const std::wstring& aot_library_path) {
27  assets_path_ = assets_path;
28  icu_data_path_ = icu_data_path;
29  aot_library_path_ = aot_library_path;
30  }
31 
32 #ifndef WINUWP
33  // Creates a DartProject from a directory path. The directory should contain
34  // the following top-level items:
35  // - icudtl.dat (provided as a resource by the Flutter tool)
36  // - flutter_assets (as built by the Flutter tool)
37  // - app.so, for an AOT build (as built by the Flutter tool)
38  //
39  // The path can either be absolute, or relative to the directory containing
40  // the running executable.
41  explicit DartProject(const std::wstring& path) {
42  assets_path_ = path + L"\\flutter_assets";
43  icu_data_path_ = path + L"\\icudtl.dat";
44  aot_library_path_ = path + L"\\app.so";
45  }
46 #endif
47 
48  ~DartProject() = default;
49 
50  // Sets the command line arguments that should be passed to the Dart
51  // entrypoint.
52  void set_dart_entrypoint_arguments(std::vector<std::string> arguments) {
53  dart_entrypoint_arguments_ = std::move(arguments);
54  }
55 
56  // Returns any command line arguments that should be passed to the Dart
57  // entrypoint.
58  const std::vector<std::string>& dart_entrypoint_arguments() const {
59  return dart_entrypoint_arguments_;
60  }
61 
62  private:
63  // Accessors for internals are private, so that they can be changed if more
64  // flexible options for project structures are needed later without it
65  // being a breaking change. Provide access to internal classes that need
66  // them.
67  friend class FlutterEngine;
68  friend class FlutterViewController;
69  friend class DartProjectTest;
70 
71  const std::wstring& assets_path() const { return assets_path_; }
72  const std::wstring& icu_data_path() const { return icu_data_path_; }
73  const std::wstring& aot_library_path() const { return aot_library_path_; }
74 
75  // The path to the assets directory.
76  std::wstring assets_path_;
77  // The path to the ICU data.
78  std::wstring icu_data_path_;
79  // The path to the AOT library. This will always return a path, but non-AOT
80  // builds will not be expected to actually have a library at that path.
81  std::wstring aot_library_path_;
82  // The list of arguments to pass through to the Dart entrypoint.
83  std::vector<std::string> dart_entrypoint_arguments_;
84 };
85 
86 } // namespace flutter
87 
88 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_CLIENT_WRAPPER_INCLUDE_FLUTTER_DART_PROJECT_H_
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32
DartProject(const std::wstring &path)
Definition: dart_project.h:41
const std::vector< std::string > & dart_entrypoint_arguments() const
Definition: dart_project.h:58
DartProject(const std::wstring &assets_path, const std::wstring &icu_data_path, const std::wstring &aot_library_path)
Definition: dart_project.h:24
void set_dart_entrypoint_arguments(std::vector< std::string > arguments)
Definition: dart_project.h:52