BeagleWidget

In this section, you will find information on how to use BeagleWidget in Beagle Flutter.

What is it?

A widget that displays Beagle’s contents. This is the entry point to load server-driven screens and server-driven UI components to your Flutter application. The BeagleWidget is a StatefulWidget that renders widgets through a local JSON or an HTTP request.

See how the structure is represented:

AttributeTypeRequiredDefinition
keyKeyIdentifier for Widgets, Elements and SemanticsNodes.
screenRequestBeagleScreenRequestProvides the url, method, headers and body to the request.
screenJsonStringRepresents a local screen to be shown.
onCreateViewOnCreateViewListenerFunction that returns the current BeagleView.

BeagleScreenRequest

It’s a class used to make requests in Beagle Flutter. It implements the BeagleNetworkOptions which brings the method, headers and strategy attributes. Also, the BeagleScreenRequest class has the url and body properties. See the structure below:

AttributeTypeRequiredDefinition
urlStringRepresents the request relative server URL.
bodyStringContent that will be deliver with the request.
headersMap<String, String>Headers to be used in the request.
methodBeagleHttpMethodHttp method to indicate the desired action to be performed for a given resource. This could be put, get, post, delete, patch and head.
strategyBeagleNetworkStrategyCache strategy applied to the request. This could be beagleCacheOnly, beagleWithFallbackToCache, networkWithFallbackToCache, cacheWithFallbackToNetwork, cacheOnly, networkOnly and cacheFirst.

OnCreateViewListener

A function that follows the struct void Function(BeagleView view) and provides the current BeagleView when it’s available.

How to use it?

You can use it wherever you want to show server-driven content.

  • Place the BeagleWidget there informing at least a local JSON or a BeagleScreenRequest with the url of your BFF.

In the example below, you will see it in the Scaffold widget body:

Scaffold(
  appBar: AppBar(
    title: const Text('Beagle Sample'),
  ),
  body: BeagleWidget(
    screenRequest: BeagleScreenRequest('components'),
  ),
);