builder method

  1. @override
Widget builder(
  1. BuildContext context,
  2. PaymentViewModel model,
  3. Widget? child
)

A function that builds the UI to be shown from the ViewModel - Required

viewModel is the ViewModel passed in and child is the staticChildBuilder result

Implementation

@override
Widget builder(BuildContext context, PaymentViewModel model, Widget? child) {
  final effectiveTheme = theme ?? SmatPayThemeData.defaults;

  return MaterialApp(
    debugShowCheckedModeBanner: false,
    navigatorKey: StackedService.navigatorKey,
    theme: _materialTheme(effectiveTheme),
    home: Builder(
      builder: (context) {
        final Widget content;
        final String contentKey;

        if (model.isForm) {
          content = cardWidget(context, model, effectiveTheme);
          contentKey = model.isWebView ? 'payment-web-view' : 'payment-form';
        } else if (model.isFailed) {
          content = paymentFailed(context, model, effectiveTheme);
          contentKey = 'payment-failed';
        } else if (model.isSuccess) {
          content = paymentSuccess(context, effectiveTheme);
          contentKey = 'payment-success';
        } else {
          content = const SizedBox.shrink();
          contentKey = 'payment-empty';
        }

        return Scaffold(
          backgroundColor: effectiveTheme.background,
          body: SafeArea(
            child: AnimatedSwitcher(
              duration: const Duration(milliseconds: 220),
              child: KeyedSubtree(key: ValueKey(contentKey), child: content),
            ),
          ),
        );
      },
    ),
  );
}