View

  • View is a context-independent function that outputs Widget. It receives the following parameters
    • T state
    • Dispatch
    • ViewService
  • It mainly contains three aspects of information
    • The view is completely driven by data.
    • The event/callback triggered by the view, use Dispatch to send “intent”, but never do a specific implementation.
    • Use dependent component/adapter, by explicitly configuring it on the parent component, and then standardizing calls through the ViewService.
      • Where ViewService provides three capabilities
        • BuildContext context: Ability to get widget’s BuildContext
        • Widget buildView(String name): Ability to create subcomponents directly
          • The name passed in here is the name configured on Dependencies.
          • Creating subcomponents does not require passing in any other parameters, since the parameters required by the subcomponents have been passed through the Dependencies configuration, and their data relationships are established via the connector.
        • ListAdapter buildAdapter(): Ability to create adapter directly
  • Sample Code
  1. Widget buildMessageView(String message, Dispatch dispatch, ViewService viewService) {
  2. return Column(children: [
  3. viewService.buildComponent('profile'),
  4. InkWell(
  5. child: Text('$message'),
  6. onTap: () => dispatch(const Action('onShare')),
  7. ),
  8. ]);
  9. }
  10. class MessageComponent extends Component<String> {
  11. MessageComponent(): super(
  12. view: buildMessageView,
  13. );
  14. }