BeagleService constructor

BeagleService({
  1. required String baseUrl,
  2. required Map<String, ComponentBuilder Function()> components,
  3. UrlBuilder? urlBuilder,
  4. BeagleImageDownloader? imageDownloader,
  5. BeagleLogger logger = const DefaultLogger(),
  6. AnalyticsProvider? analyticsProvider,
  7. HttpClient httpClient = const DefaultHttpClient(),
  8. ViewClient? viewClient,
  9. Map<String, ActionHandler>? actions,
  10. NavigationController? defaultNavigationController,
  11. Map<String, NavigationController> navigationControllers = const {},
  12. Map<String, Operation> operations = const {},
  13. BeagleEnvironment environment = kDebugMode ? BeagleEnvironment.debug : BeagleEnvironment.production,
  14. bool enableStyles = true,
  15. bool enableHotReloading = false,
  16. String? hotReloadingUrl,
})

Implementation

BeagleService({
  /// URL to the backend providing the views (JSON) for Beagle.
  required this.baseUrl,

  /// The map of components to be used when rendering a view. The key must be the
  /// `_beagleComponent_` identifier and the value must be a ComponentBuilder, which is a function
  /// that transforms a BeagleUIElement into a Widget. The key must always start with `beagle:` or
  /// `custom:`.
  required Map<String, ComponentBuilder Function()> components,

  /// todo documentation
  UrlBuilder? urlBuilder,

  /// todo documentation
  BeagleImageDownloader? imageDownloader,

  /// todo documentation
  this.logger = const DefaultLogger(),

  /// todo documentation
  this.analyticsProvider,

  /// Custom client to make HTTP requests. You can use this to implement your own HTTP client,
  /// calculating your own headers, cookies, response transformation, etc. The client provided
  /// here must implement the HttpClient interface. By default, the DefaultHttpClient will be
  /// used.
  this.httpClient = const DefaultHttpClient(),

  /// todo documentation
  ViewClient? viewClient,

  /// The map of custom actions. The key must be the `_beagleAction_` identifier and the value
  /// must be the action handler. The key must always start with `beagle:` or `custom:`.
  Map<String, ActionHandler>? actions,

  /// Sets the default navigation controller.
  NavigationController? defaultNavigationController,

  /// Controls the behavior of the navigator when handling events like loading, error and success.
  this.navigationControllers = const {},

  /// todo documentation
  this.operations = const {},

  /// Sets the environment: debug or production. Beagle will log more data and also enables hot reloading
  /// when the environment is BeagleEnvironment.debug. The hot reloading also depends on the property watchInterval,
  /// which by default, disables it.
  ///
  /// If not set, the environment is determined by Flutter's global constant kDebugMode.
  this.environment = kDebugMode ? BeagleEnvironment.debug : BeagleEnvironment.production,

  /// Enables or disables the automatic styling of all components according to the "style" property. Be aware that
  /// setting this to false will break most default Beagle components. Set this to false if you need to create your
  /// own layout engine.
  this.enableStyles = true,

  /// Enables/disables Beagle's hot reloading. This setting is only valid when the environment is
  /// BeagleEnvironment.debug.
  ///
  /// Attention: this feature only works in conjunction with the backend-typescript for Beagle. It doesn't work
  /// for any other type of backend.
  ///
  /// Default value: false
  this.enableHotReloading = false,

  /// URL for the Hot Reloading websocket server. This setting is taken into account only if enableHotReloading is
  /// true.
  ///
  /// Default value: "ws://localhost:3001" for iOS and "ws://10.0.2.2:3001" for Android.
  String? hotReloadingUrl,
})  : urlBuilder = urlBuilder ?? UrlBuilder(baseUrl),
      components = _toLowercaseKeys(components),
      actions = _toLowercaseKeys({...defaultActions, ...(actions ?? {})}) {
  this.imageDownloader = imageDownloader ?? DefaultBeagleImageDownloader(httpClient: httpClient);
  this.viewClient =
      viewClient ?? DefaultViewClient(httpClient: httpClient, logger: logger, urlBuilder: this.urlBuilder);
  this.defaultNavigationController = defaultNavigationController ?? DefaultNavigationController(logger);
  js = BeagleJS(this);
  globalContext = GlobalContextJS(js.engine);
  this.hotReloadingUrl = hotReloadingUrl ?? 'ws://${(Platform.isAndroid ? '10.0.2.2' : 'localhost')}:3001';
}