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 Widget content;
  final String contentKey;

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

  return MaterialApp(
    debugShowCheckedModeBanner: false,
    navigatorKey: StackedService.navigatorKey,
    theme: ThemeData(
      colorScheme: ColorScheme.fromSeed(
        seedColor: SmatPayColors.primaryIndigo,
      ),
      scaffoldBackgroundColor: SmatPayColors.softLavender,
      useMaterial3: true,
    ),
    home: Scaffold(
      backgroundColor: SmatPayColors.softLavender,
      body: SafeArea(
        child: AnimatedSwitcher(
          duration: const Duration(milliseconds: 220),
          child: KeyedSubtree(key: ValueKey(contentKey), child: content),
        ),
      ),
    ),
  );
}