build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the user interface represented by this widget.

The framework calls this method in a number of different situations. For example:

This method can potentially be called in every frame and should not have any side effects beyond building a widget.

The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.

Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor, the given BuildContext, and the internal state of this State object.

The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. The BuildContext argument is always the same as the context property of this State object and will remain the same for the lifetime of this object. The BuildContext argument is provided redundantly here so that this method matches the signature for a WidgetBuilder.

Design discussion

Why is the build method on State, and not StatefulWidget?

Putting a Widget build(BuildContext context) method on State rather than putting a Widget build(BuildContext context, State state) method on StatefulWidget gives developers more flexibility when subclassing StatefulWidget.

For example, AnimatedWidget is a subclass of StatefulWidget that introduces an abstract Widget build(BuildContext context) method for its subclasses to implement. If StatefulWidget already had a build method that took a State argument, AnimatedWidget would be forced to provide its State object to subclasses even though its State object is an internal implementation detail of AnimatedWidget.

Conceptually, StatelessWidget could also be implemented as a subclass of StatefulWidget in a similar manner. If the build method were on StatefulWidget rather than State, that would not be possible anymore.

Putting the build function on State rather than StatefulWidget also helps avoid a category of bugs related to closures implicitly capturing this. If you defined a closure in a build function on a StatefulWidget, that closure would implicitly capture this, which is the current widget instance, and would have the (immutable) fields of that instance in scope:

// (this is not valid Flutter code)
class MyButton extends StatefulWidgetX {
  MyButton({super.key, required this.color});

  final Color color;

  @override
  Widget build(BuildContext context, State state) {
    return SpecialWidget(
      handler: () { print('color: $color'); },
    );
  }
}

For example, suppose the parent builds MyButton with color being blue, the $color in the print function refers to blue, as expected. Now, suppose the parent rebuilds MyButton with green. The closure created by the first build still implicitly refers to the original widget and the $color still prints blue even through the widget has been updated to green; should that closure outlive its widget, it would print outdated information.

In contrast, with the build function on the State object, closures created during build implicitly capture the State instance instead of the widget instance:

class MyButton extends StatefulWidget {
  const MyButton({super.key, this.color = Colors.teal});

  final Color color;
  // ...
}

class MyButtonState extends State<MyButton> {
  // ...
  @override
  Widget build(BuildContext context) {
    return SpecialWidget(
      handler: () { print('color: ${widget.color}'); },
    );
  }
}

Now when the parent rebuilds MyButton with green, the closure created by the first build still refers to State object, which is preserved across rebuilds, but the framework has updated that State object's widget property to refer to the new MyButton instance and ${widget.color} prints green, as expected.

See also:

  • StatefulWidget, which contains the discussion on performance considerations.

Implementation

@override
Widget build(BuildContext context) {
  bool isBackgroundColorBlack =
      (widget.config.color ?? AppColors.white) == AppColors.primaryColor;

  final defaultPinTheme = PinTheme(
    width: 60,
    height: 60,
    textStyle: const TextStyle(
      fontSize: 22,
      color: Colors.black,
      fontWeight: FontWeight.bold,
      height: 1.4,
    ),
    decoration: BoxDecoration(
      border: Border.all(
        color: AppColors.greyFFD9D9D9,
        width: 1,
      ),
      borderRadius: BorderRadius.circular(8),
    ),
  );
  final focusedPinTheme = PinTheme(
    width: 60,
    height: 60,
    textStyle: const TextStyle(
      fontSize: 22,
      color: Colors.black,
      fontWeight: FontWeight.bold,
      height: 1.4,
    ),
    decoration: BoxDecoration(
      border: Border.all(
        color: AppColors.primaryColor,
        width: 2,
      ),
      borderRadius: BorderRadius.circular(8),
    ),
  );

  return ChangeNotifierProvider<PaymentViewModel>.value(
    value: _viewModel,
    key: widget.key,
    child: Scaffold(
      backgroundColor: AppColors.white,
      appBar: AppBar(
        backgroundColor: widget.config.color ?? AppColors.white,
        elevation: 0,
        title: Text(
          "Retour",
          style: GoogleFonts.poppins(
            fontSize: 14,
            color: isBackgroundColorBlack ? AppColors.white : AppColors.black,
            fontWeight: FontWeight.w500,
          ),
        ),
        centerTitle: false,
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back_ios,
            color: isBackgroundColorBlack ? AppColors.white : AppColors.black,
          ),
          onPressed: () {
            if (_viewModel.interfacePayment == null) {
              Navigator.of(context).pop();
            } else {
              _viewModel.interfacePayment = null;
            }
          },
        ),
      ),
      body: Consumer<PaymentViewModel>(
        builder: (context, model, child) => Stack(
          children: [
            SingleChildScrollView(
              child: Column(
                children: [
                  (_viewModel.statusPayment == EnumStatusPayment.cancel)
                      ? CancelPaymentWidget(
                          config: widget.config,
                        )
                      : (_viewModel.statusPayment ==
                              EnumStatusPayment.pending)
                          ? widget.pendingBuilder
                                  ?.call(_viewModel.responsePayment!) ??
                              PendingPaymentWidget(
                                responsePayment: _viewModel.responsePayment!,
                                config: widget.config,
                                callBack: () {
                                  _viewModel.getStatusPayment(
                                      token: widget.accessToken);
                                },
                              )
                          : (_viewModel.statusPayment ==
                                  EnumStatusPayment.successful)
                              ? widget.successBuilder
                                      ?.call(_viewModel.responsePayment!) ??
                                  SuccessPaymentWidget(
                                    responsePayment:
                                        _viewModel.responsePayment!,
                                    config: widget.config,
                                  )
                              : (_viewModel.statusPayment ==
                                      EnumStatusPayment.failed)
                                  ? widget.errorBuilder?.call(
                                          _viewModel.responsePayment!) ??
                                      FailedPaymentWidget(
                                        responsePayment:
                                            _viewModel.responsePayment!,
                                        config: widget.config,
                                      )
                                  : Column(
                                      children: [
                                        _viewModel.interfacePayment ==
                                                EnumTypePayment.orange.value
                                            ? Container(
                                                padding:
                                                    const EdgeInsets.all(20),
                                                color: AppColors.white,
                                                child: Column(
                                                  crossAxisAlignment:
                                                      CrossAxisAlignment
                                                          .start,
                                                  children: [
                                                    Column(
                                                      crossAxisAlignment:
                                                          CrossAxisAlignment
                                                              .center,
                                                      children: [
                                                        if (_viewModel
                                                            .showError)
                                                          AnimatedOpacity(
                                                            duration:
                                                                const Duration(
                                                                    milliseconds:
                                                                        300),
                                                            opacity: _viewModel
                                                                    .showError
                                                                ? 1.0
                                                                : 0.0,
                                                            child: Container(
                                                              height: 50,
                                                              width: MediaQuery.of(
                                                                      context)
                                                                  .size
                                                                  .width,
                                                              padding:
                                                                  const EdgeInsets
                                                                      .all(5),
                                                              decoration:
                                                                  BoxDecoration(
                                                                color: AppColors
                                                                    .dangerColor,
                                                                borderRadius:
                                                                    BorderRadius
                                                                        .circular(
                                                                            8),
                                                              ),
                                                              child: Row(
                                                                children: [
                                                                  const Icon(
                                                                    CupertinoIcons
                                                                        .info,
                                                                    color: AppColors
                                                                        .white,
                                                                  ),
                                                                  horizontalSpaceSmall,
                                                                  Expanded(
                                                                    child:
                                                                        Text(
                                                                      "${_viewModel.messageError}",
                                                                      style: GoogleFonts
                                                                          .poppins(
                                                                        fontSize:
                                                                            14,
                                                                        color:
                                                                            AppColors.white,
                                                                        fontWeight:
                                                                            FontWeight.w400,
                                                                      ),
                                                                    ),
                                                                  ),
                                                                ],
                                                              ),
                                                            ),
                                                          ),
                                                        verticalSpaceRegular,
                                                        Center(
                                                          child: Image.asset(
                                                            width: 50,
                                                            _viewModel
                                                                    .selectedPayment
                                                                    ?.svgSelected ??
                                                                "",
                                                            package:
                                                                "digitalpaye_sdk_flutter",
                                                          ),
                                                        ),
                                                        verticalSpaceRegular,
                                                        Text(
                                                          "Confirmer la transaction",
                                                          style: GoogleFonts
                                                              .poppins(
                                                            fontSize: 20,
                                                            color: AppColors
                                                                .black,
                                                            fontWeight:
                                                                FontWeight
                                                                    .w500,
                                                          ),
                                                        ),
                                                        verticalSpaceRegular,
                                                        Container(
                                                          width:
                                                              MediaQuery.of(
                                                                      context)
                                                                  .size
                                                                  .width,
                                                          alignment: Alignment
                                                              .center,
                                                          padding:
                                                              const EdgeInsets
                                                                  .all(5),
                                                          decoration:
                                                              BoxDecoration(
                                                            color: const Color(
                                                                0xFFF4A50C),
                                                            borderRadius:
                                                                BorderRadius
                                                                    .circular(
                                                                        8),
                                                          ),
                                                          child: Row(
                                                            crossAxisAlignment:
                                                                CrossAxisAlignment
                                                                    .center,
                                                            children: [
                                                              const Icon(
                                                                CupertinoIcons
                                                                    .info,
                                                                color:
                                                                    AppColors
                                                                        .white,
                                                              ),
                                                              horizontalSpaceSmall,
                                                              Expanded(
                                                                child: Text(
                                                                  "Composez #144*82# pour générer un code à 4 chiffres afin de valider la transaction.",
                                                                  textAlign:
                                                                      TextAlign
                                                                          .center,
                                                                  style: GoogleFonts
                                                                      .poppins(
                                                                    fontSize:
                                                                        14,
                                                                    color: AppColors
                                                                        .black,
                                                                    fontWeight:
                                                                        FontWeight
                                                                            .w300,
                                                                  ),
                                                                ),
                                                              ),
                                                            ],
                                                          ),
                                                        ),
                                                        verticalSpaceLarge,
                                                        Pinput(
                                                          length: 4,
                                                          defaultPinTheme:
                                                              defaultPinTheme,
                                                          focusedPinTheme:
                                                              focusedPinTheme,
                                                          listenForMultipleSmsOnAndroid:
                                                              true,
                                                          controller:
                                                              otpController,
                                                          pinAnimationType:
                                                              PinAnimationType
                                                                  .none,
                                                          keyboardType:
                                                              TextInputType
                                                                  .number,
                                                          inputFormatters: <TextInputFormatter>[
                                                            LengthLimitingTextInputFormatter(
                                                                4),
                                                            FilteringTextInputFormatter
                                                                .digitsOnly
                                                          ],
                                                          showCursor: true,
                                                          onChanged: (value) {
                                                            _viewModel
                                                                    .codePin =
                                                                value;
                                                          },
                                                        ),
                                                        verticalSpaceLarge,
                                                        SizedBox(
                                                          height: 50,
                                                          width:
                                                              MediaQuery.of(
                                                                      context)
                                                                  .size
                                                                  .width,
                                                          child:
                                                              ElevatedButton(
                                                            style:
                                                                ButtonStyle(
                                                              shape: MaterialStateProperty
                                                                  .all<
                                                                      RoundedRectangleBorder>(
                                                                RoundedRectangleBorder(
                                                                  borderRadius:
                                                                      BorderRadius
                                                                          .circular(8),
                                                                ),
                                                              ),
                                                              elevation:
                                                                  MaterialStateProperty
                                                                      .all<double>(
                                                                          0.0),
                                                              backgroundColor:
                                                                  MaterialStateProperty
                                                                      .all<
                                                                          Color>(
                                                                _viewModel
                                                                        .buttomOrangeMoneyisEnabled
                                                                    ? widget.config
                                                                            .color ??
                                                                        AppColors
                                                                            .primaryColor
                                                                    : AppColors
                                                                        .greyFFD9D9D9,
                                                              ),
                                                            ),
                                                            onPressed: () {
                                                              if (_viewModel
                                                                  .buttomOrangeMoneyisEnabled) {
                                                                _viewModel.createPayment(
                                                                    token: widget
                                                                        .accessToken,
                                                                    params: widget
                                                                        .payment);
                                                              }
                                                            },
                                                            child: Text(
                                                              "Payer maintenant",
                                                              style:
                                                                  GoogleFonts
                                                                      .poppins(
                                                                fontSize: 14,
                                                                color:
                                                                    AppColors
                                                                        .white,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w400,
                                                              ),
                                                            ),
                                                          ),
                                                        ),
                                                        verticalSpaceExtraLarge,
                                                        MouseRegion(
                                                          cursor:
                                                              SystemMouseCursors
                                                                  .click,
                                                          child:
                                                              GestureDetector(
                                                            onTap: () {
                                                              Navigator.of(
                                                                      context)
                                                                  .pop();
                                                            },
                                                            child: Text(
                                                              "Annuler la transaction",
                                                              style:
                                                                  GoogleFonts
                                                                      .poppins(
                                                                fontSize: 14,
                                                                color:
                                                                    AppColors
                                                                        .black,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w400,
                                                              ),
                                                            ),
                                                          ),
                                                        )
                                                      ],
                                                    ),
                                                  ],
                                                ),
                                              )
                                            : _viewModel.interfacePayment ==
                                                    EnumTypePayment.mtn.value
                                                ? Container(
                                                    padding:
                                                        const EdgeInsets.all(
                                                            20),
                                                    color: AppColors.white,
                                                    child: Column(
                                                      crossAxisAlignment:
                                                          CrossAxisAlignment
                                                              .start,
                                                      children: [
                                                        if (_viewModel
                                                            .showError)
                                                          AnimatedOpacity(
                                                            duration:
                                                                const Duration(
                                                                    milliseconds:
                                                                        300),
                                                            opacity: _viewModel
                                                                    .showError
                                                                ? 1.0
                                                                : 0.0,
                                                            child: Container(
                                                              height: 50,
                                                              width: MediaQuery.of(
                                                                      context)
                                                                  .size
                                                                  .width,
                                                              padding:
                                                                  const EdgeInsets
                                                                      .all(5),
                                                              decoration:
                                                                  BoxDecoration(
                                                                color: AppColors
                                                                    .dangerColor,
                                                                borderRadius:
                                                                    BorderRadius
                                                                        .circular(
                                                                            8),
                                                              ),
                                                              child: Row(
                                                                children: [
                                                                  const Icon(
                                                                    CupertinoIcons
                                                                        .info,
                                                                    color: AppColors
                                                                        .white,
                                                                  ),
                                                                  horizontalSpaceSmall,
                                                                  Expanded(
                                                                    child:
                                                                        Text(
                                                                      "${_viewModel.messageError}",
                                                                      style: GoogleFonts
                                                                          .poppins(
                                                                        fontSize:
                                                                            14,
                                                                        color:
                                                                            AppColors.white,
                                                                        fontWeight:
                                                                            FontWeight.w400,
                                                                      ),
                                                                    ),
                                                                  ),
                                                                ],
                                                              ),
                                                            ),
                                                          ),
                                                        verticalSpaceRegular,
                                                        Column(
                                                          crossAxisAlignment:
                                                              CrossAxisAlignment
                                                                  .center,
                                                          children: [
                                                            Center(
                                                              child:
                                                                  Image.asset(
                                                                width: 50,
                                                                _viewModel
                                                                        .selectedPayment
                                                                        ?.svgSelected ??
                                                                    "",
                                                                package:
                                                                    "digitalpaye_sdk_flutter",
                                                              ),
                                                            ),
                                                            verticalSpaceRegular,
                                                            Text(
                                                              "Confirmer la transaction",
                                                              textAlign:
                                                                  TextAlign
                                                                      .center,
                                                              style:
                                                                  GoogleFonts
                                                                      .poppins(
                                                                fontSize: 20,
                                                                color:
                                                                    AppColors
                                                                        .black,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w500,
                                                              ),
                                                            ),
                                                            verticalSpaceRegular,
                                                            SizedBox(
                                                              width: 400,
                                                              child: Text(
                                                                "Pour confirmer la transaction, veuillez composer cette syntaxe et suivez les instructions.",
                                                                textAlign:
                                                                    TextAlign
                                                                        .center,
                                                                style: GoogleFonts
                                                                    .poppins(
                                                                  fontSize:
                                                                      14,
                                                                  color: AppColors
                                                                      .black,
                                                                  fontWeight:
                                                                      FontWeight
                                                                          .w300,
                                                                ),
                                                              ),
                                                            ),
                                                            verticalSpaceMedium,
                                                            DottedBorder(
                                                              dashPattern: const [
                                                                10,
                                                                20
                                                              ],
                                                              strokeWidth: 1,
                                                              borderType:
                                                                  BorderType
                                                                      .RRect,
                                                              padding:
                                                                  const EdgeInsets
                                                                      .all(8),
                                                              radius:
                                                                  const Radius
                                                                      .circular(
                                                                      30),
                                                              child:
                                                                  Container(
                                                                width: 400,
                                                                height: 100,
                                                                alignment:
                                                                    Alignment
                                                                        .center,
                                                                decoration:
                                                                    BoxDecoration(
                                                                  color: AppColors
                                                                      .white,
                                                                  borderRadius:
                                                                      BorderRadius.circular(
                                                                          30),
                                                                ),
                                                                child: Text(
                                                                  "*133#",
                                                                  textAlign:
                                                                      TextAlign
                                                                          .center,
                                                                  style: GoogleFonts
                                                                      .poppins(
                                                                    fontSize:
                                                                        32,
                                                                    color: AppColors
                                                                        .black,
                                                                    fontWeight:
                                                                        FontWeight
                                                                            .w700,
                                                                  ),
                                                                ),
                                                              ),
                                                            ),
                                                            verticalSpaceExtraLarge,
                                                            SizedBox(
                                                              height: 50,
                                                              width: MediaQuery.of(
                                                                      context)
                                                                  .size
                                                                  .width,
                                                              child:
                                                                  ElevatedButton(
                                                                style:
                                                                    ButtonStyle(
                                                                  shape: MaterialStateProperty
                                                                      .all<
                                                                          RoundedRectangleBorder>(
                                                                    RoundedRectangleBorder(
                                                                      borderRadius:
                                                                          BorderRadius.circular(8),
                                                                    ),
                                                                  ),
                                                                  elevation: MaterialStateProperty
                                                                      .all<double>(
                                                                          0.0),
                                                                  backgroundColor: MaterialStateProperty.all<
                                                                          Color>(
                                                                      AppColors
                                                                          .primaryColor),
                                                                ),
                                                                onPressed:
                                                                    () {
                                                                  _viewModel.getStatusPayment(
                                                                      token: widget
                                                                          .accessToken);
                                                                },
                                                                child: Text(
                                                                  "Vérifier le paiement",
                                                                  style: GoogleFonts
                                                                      .poppins(
                                                                    fontSize:
                                                                        14,
                                                                    color: AppColors
                                                                        .white,
                                                                    fontWeight:
                                                                        FontWeight
                                                                            .w400,
                                                                  ),
                                                                ),
                                                              ),
                                                            ),
                                                            verticalSpaceExtraLarge,
                                                            MouseRegion(
                                                              cursor:
                                                                  SystemMouseCursors
                                                                      .click,
                                                              child:
                                                                  GestureDetector(
                                                                onTap: () {
                                                                  Navigator.of(
                                                                          context)
                                                                      .pop();
                                                                },
                                                                child: Text(
                                                                  "Annuler la transaction",
                                                                  style: GoogleFonts
                                                                      .poppins(
                                                                    fontSize:
                                                                        14,
                                                                    color: AppColors
                                                                        .black,
                                                                    fontWeight:
                                                                        FontWeight
                                                                            .w400,
                                                                  ),
                                                                ),
                                                              ),
                                                            ),
                                                          ],
                                                        ),
                                                      ],
                                                    ),
                                                  )
                                                : Container(
                                                    padding:
                                                        const EdgeInsets.all(
                                                            20),
                                                    color: AppColors.white,
                                                    child: Column(
                                                      crossAxisAlignment:
                                                          CrossAxisAlignment
                                                              .start,
                                                      children: [
                                                        Column(
                                                          crossAxisAlignment:
                                                              CrossAxisAlignment
                                                                  .start,
                                                          children: [
                                                            Text(
                                                              widget.payment
                                                                  .designation,
                                                              style:
                                                                  GoogleFonts
                                                                      .poppins(
                                                                fontSize: 14,
                                                                color: AppColors
                                                                    .colorTexte,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w400,
                                                              ),
                                                            ),
                                                            verticalSpaceSmall,
                                                            Text(
                                                              widget.payment
                                                                  .transactionId,
                                                              style:
                                                                  GoogleFonts
                                                                      .poppins(
                                                                fontSize: 14,
                                                                color: AppColors
                                                                    .colorTexte,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w400,
                                                              ),
                                                            ),
                                                            verticalSpaceSmall,
                                                            Text(
                                                              "${formatNumber(widget.payment.amount.toInt())} ${widget.payment.currency.value}",
                                                              style:
                                                                  GoogleFonts
                                                                      .poppins(
                                                                fontSize: 22,
                                                                color:
                                                                    AppColors
                                                                        .black,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w800,
                                                              ),
                                                            ),
                                                          ],
                                                        ),
                                                        verticalSpaceRegular,
                                                        if (_viewModel
                                                            .showError)
                                                          AnimatedOpacity(
                                                            duration:
                                                                const Duration(
                                                                    milliseconds:
                                                                        300),
                                                            opacity: _viewModel
                                                                    .showError
                                                                ? 1.0
                                                                : 0.0,
                                                            child: Container(
                                                              height: 50,
                                                              width: MediaQuery.of(
                                                                      context)
                                                                  .size
                                                                  .width,
                                                              padding:
                                                                  const EdgeInsets
                                                                      .all(5),
                                                              decoration:
                                                                  BoxDecoration(
                                                                color: AppColors
                                                                    .dangerColor,
                                                                borderRadius:
                                                                    BorderRadius
                                                                        .circular(
                                                                            8),
                                                              ),
                                                              child: Row(
                                                                children: [
                                                                  const Icon(
                                                                    Icons
                                                                        .info,
                                                                    color: AppColors
                                                                        .white,
                                                                  ),
                                                                  horizontalSpaceSmall,
                                                                  Expanded(
                                                                    child:
                                                                        Text(
                                                                      "${_viewModel.messageError}",
                                                                      style: GoogleFonts
                                                                          .poppins(
                                                                        fontSize:
                                                                            14,
                                                                        color:
                                                                            AppColors.white,
                                                                        fontWeight:
                                                                            FontWeight.w400,
                                                                      ),
                                                                    ),
                                                                  ),
                                                                ],
                                                              ),
                                                            ),
                                                          ),
                                                        verticalSpaceRegular,
                                                        Text(
                                                          "Sélectionner un moyen de paiement",
                                                          style: GoogleFonts
                                                              .poppins(
                                                            fontSize: 16,
                                                            color: AppColors
                                                                .black,
                                                            fontWeight:
                                                                FontWeight
                                                                    .w500,
                                                          ),
                                                        ),
                                                        verticalSpaceRegular,
                                                        Row(
                                                          children:
                                                              List.generate(
                                                            _viewModel
                                                                .paymentTypes
                                                                .length,
                                                            (index) => Row(
                                                              children: [
                                                                MouseRegion(
                                                                  cursor:
                                                                      SystemMouseCursors
                                                                          .click,
                                                                  child:
                                                                      GestureDetector(
                                                                    onTap:
                                                                        () {
                                                                      _viewModel
                                                                          .selectPayment(_viewModel.paymentTypes[index]);
                                                                    },
                                                                    child: Image
                                                                        .asset(
                                                                      width:
                                                                          55,
                                                                      package:
                                                                          "digitalpaye_sdk_flutter",
                                                                      key:
                                                                          UniqueKey(),
                                                                      _viewModel.selectedPayment?.value ==
                                                                              _viewModel.paymentTypes[index].value
                                                                          ? _viewModel.paymentTypes[index].svgSelected
                                                                          : _viewModel.paymentTypes[index].svgUnSelected,
                                                                    ),
                                                                  ),
                                                                ),
                                                                horizontalSpaceRegular,
                                                              ],
                                                            ),
                                                          ),
                                                        ),
                                                        verticalSpaceRegular,
                                                        Text(
                                                          "Nom complet",
                                                          style: GoogleFonts
                                                              .poppins(
                                                            fontSize: 14,
                                                            color: AppColors
                                                                .black,
                                                            fontWeight:
                                                                FontWeight
                                                                    .w400,
                                                          ),
                                                        ),
                                                        verticalSpaceSmall,
                                                        Container(
                                                          alignment: Alignment
                                                              .center,
                                                          height: 50,
                                                          decoration:
                                                              BoxDecoration(
                                                            border:
                                                                Border.all(
                                                              color: AppColors
                                                                  .greyFFD9D9D9,
                                                              width: 1,
                                                            ),
                                                            color: AppColors
                                                                .white,
                                                            borderRadius:
                                                                BorderRadius
                                                                    .circular(
                                                                        8),
                                                          ),
                                                          child: Container(
                                                            margin:
                                                                const EdgeInsets
                                                                    .only(
                                                              left: 10,
                                                              right: 10,
                                                            ),
                                                            child:
                                                                TextFormField(
                                                              style:
                                                                  const TextStyle(
                                                                fontSize: 14,
                                                                color: Colors
                                                                    .black,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w500,
                                                              ),
                                                              autofocus:
                                                                  false,
                                                              controller:
                                                                  customerNameController,
                                                              decoration:
                                                                  const InputDecoration(
                                                                border:
                                                                    InputBorder
                                                                        .none,
                                                                enabledBorder:
                                                                    InputBorder
                                                                        .none,
                                                                focusedBorder:
                                                                    InputBorder
                                                                        .none,
                                                              ),
                                                              textInputAction:
                                                                  TextInputAction
                                                                      .next,
                                                              keyboardType:
                                                                  TextInputType
                                                                      .text,
                                                              onChanged:
                                                                  (value) {
                                                                _viewModel
                                                                        .name =
                                                                    value;
                                                              },
                                                            ),
                                                          ),
                                                        ),
                                                        verticalSpaceSmall,
                                                        Text(
                                                          "Adresse email",
                                                          style: GoogleFonts
                                                              .poppins(
                                                            fontSize: 14,
                                                            color: AppColors
                                                                .black,
                                                            fontWeight:
                                                                FontWeight
                                                                    .w400,
                                                          ),
                                                        ),
                                                        verticalSpaceSmall,
                                                        Container(
                                                          alignment: Alignment
                                                              .center,
                                                          height: 50,
                                                          decoration:
                                                              BoxDecoration(
                                                            border:
                                                                Border.all(
                                                              color: AppColors
                                                                  .greyFFD9D9D9,
                                                              width: 1,
                                                            ),
                                                            color: AppColors
                                                                .white,
                                                            borderRadius:
                                                                BorderRadius
                                                                    .circular(
                                                                        8),
                                                          ),
                                                          child: Container(
                                                            margin:
                                                                const EdgeInsets
                                                                    .only(
                                                              left: 10,
                                                              right: 10,
                                                            ),
                                                            child:
                                                                TextFormField(
                                                              style:
                                                                  const TextStyle(
                                                                fontSize: 14,
                                                                color: Colors
                                                                    .black,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w500,
                                                              ),
                                                              autofocus:
                                                                  false,
                                                              controller:
                                                                  customerEmailController,
                                                              decoration:
                                                                  const InputDecoration(
                                                                border:
                                                                    InputBorder
                                                                        .none,
                                                                enabledBorder:
                                                                    InputBorder
                                                                        .none,
                                                                focusedBorder:
                                                                    InputBorder
                                                                        .none,
                                                              ),
                                                              textInputAction:
                                                                  TextInputAction
                                                                      .next,
                                                              keyboardType:
                                                                  TextInputType
                                                                      .emailAddress,
                                                              onChanged:
                                                                  (value) {
                                                                _viewModel
                                                                        .email =
                                                                    value;
                                                              },
                                                            ),
                                                          ),
                                                        ),
                                                        verticalSpaceSmall,
                                                        Text(
                                                          "Numéro de téléphone",
                                                          style: GoogleFonts
                                                              .poppins(
                                                            fontSize: 14,
                                                            color: AppColors
                                                                .black,
                                                            fontWeight:
                                                                FontWeight
                                                                    .w400,
                                                          ),
                                                        ),
                                                        verticalSpaceSmall,
                                                        Row(
                                                          children: [
                                                            Expanded(
                                                              flex: 0,
                                                              child:
                                                                  Container(
                                                                      alignment: Alignment
                                                                          .center,
                                                                      padding: const EdgeInsets
                                                                          .all(
                                                                          5),
                                                                      height:
                                                                          50,
                                                                      decoration:
                                                                          BoxDecoration(
                                                                        border:
                                                                            Border.all(
                                                                          color:
                                                                              AppColors.greyFFD9D9D9,
                                                                          width:
                                                                              1,
                                                                        ),
                                                                        color:
                                                                            AppColors.white,
                                                                        borderRadius:
                                                                            BorderRadius.circular(8),
                                                                      ),
                                                                      child:
                                                                          Row(
                                                                        children: [
                                                                          Image.asset(
                                                                            "assets/images/flag_ivory_coast.png",
                                                                            package: "digitalpaye_sdk_flutter",
                                                                            width: 20,
                                                                          ),
                                                                          horizontalSpaceSmall,
                                                                          Text(
                                                                            "+225",
                                                                            style: GoogleFonts.poppins(
                                                                              fontSize: 14,
                                                                              color: AppColors.black,
                                                                              fontWeight: FontWeight.w400,
                                                                            ),
                                                                          ),
                                                                        ],
                                                                      )),
                                                            ),
                                                            horizontalSpaceTiny,
                                                            Expanded(
                                                              child:
                                                                  Container(
                                                                alignment:
                                                                    Alignment
                                                                        .center,
                                                                height: 50,
                                                                decoration:
                                                                    BoxDecoration(
                                                                  border:
                                                                      Border
                                                                          .all(
                                                                    color: AppColors
                                                                        .greyFFD9D9D9,
                                                                    width: 1,
                                                                  ),
                                                                  color: AppColors
                                                                      .white,
                                                                  borderRadius:
                                                                      BorderRadius
                                                                          .circular(8),
                                                                ),
                                                                child:
                                                                    Container(
                                                                  margin:
                                                                      const EdgeInsets
                                                                          .only(
                                                                    left: 10,
                                                                    right: 10,
                                                                  ),
                                                                  child:
                                                                      TextFormField(
                                                                    style:
                                                                        const TextStyle(
                                                                      fontSize:
                                                                          14,
                                                                      color: Colors
                                                                          .black,
                                                                      fontWeight:
                                                                          FontWeight.w500,
                                                                    ),
                                                                    autofocus:
                                                                        false,
                                                                    decoration:
                                                                        const InputDecoration(
                                                                      border:
                                                                          InputBorder.none,
                                                                      enabledBorder:
                                                                          InputBorder.none,
                                                                      focusedBorder:
                                                                          InputBorder.none,
                                                                    ),
                                                                    textInputAction:
                                                                        TextInputAction
                                                                            .done,
                                                                    keyboardType:
                                                                        TextInputType
                                                                            .number,
                                                                    controller:
                                                                        customerPhoneController,
                                                                    inputFormatters: <TextInputFormatter>[
                                                                      LengthLimitingTextInputFormatter(
                                                                          10),
                                                                      FilteringTextInputFormatter
                                                                          .digitsOnly
                                                                    ],
                                                                    onChanged:
                                                                        (value) {
                                                                      _viewModel.phone =
                                                                          value;
                                                                    },
                                                                  ),
                                                                ),
                                                              ),
                                                            ),
                                                          ],
                                                        ),
                                                        verticalSpaceLarge,
                                                        SizedBox(
                                                          height: 50,
                                                          width:
                                                              MediaQuery.of(
                                                                      context)
                                                                  .size
                                                                  .width,
                                                          child:
                                                              ElevatedButton(
                                                            style:
                                                                ButtonStyle(
                                                              shape: MaterialStateProperty
                                                                  .all<
                                                                      RoundedRectangleBorder>(
                                                                RoundedRectangleBorder(
                                                                  borderRadius:
                                                                      BorderRadius
                                                                          .circular(8),
                                                                ),
                                                              ),
                                                              elevation:
                                                                  MaterialStateProperty
                                                                      .all<double>(
                                                                          0.0),
                                                              backgroundColor:
                                                                  MaterialStateProperty
                                                                      .all<
                                                                          Color>(
                                                                !_viewModel
                                                                        .isButtonDisabled
                                                                    ? widget.config
                                                                            .color ??
                                                                        AppColors
                                                                            .primaryColor
                                                                    : AppColors
                                                                        .greyFFD9D9D9,
                                                              ),
                                                            ),
                                                            onPressed: () {
                                                              if (!_viewModel
                                                                  .isButtonDisabled) {
                                                                if (_viewModel
                                                                        .selectedPayment
                                                                        ?.value ==
                                                                    EnumTypePayment
                                                                        .orange
                                                                        .value) {
                                                                  _viewModel
                                                                          .interfacePayment =
                                                                      EnumTypePayment
                                                                          .orange
                                                                          .value;
                                                                } else {
                                                                  _viewModel.createPayment(
                                                                      token: widget
                                                                          .accessToken,
                                                                      params:
                                                                          widget.payment);
                                                                }
                                                              }
                                                            },
                                                            child: Text(
                                                              "Payer maintenant",
                                                              style:
                                                                  GoogleFonts
                                                                      .poppins(
                                                                fontSize: 14,
                                                                color:
                                                                    AppColors
                                                                        .white,
                                                                fontWeight:
                                                                    FontWeight
                                                                        .w400,
                                                              ),
                                                            ),
                                                          ),
                                                        )
                                                      ],
                                                    ),
                                                  ),
                                      ],
                                    )
                ],
              ),
            ),
            if (_viewModel.isLoader)
              Container(
                color: Colors.white.withOpacity(0.9),
                height: MediaQuery.of(context).size.height,
                child: Center(
                  child: SizedBox(
                    width: 250,
                    height: 100,
                    child: Lottie.asset(
                      'assets/animations/loader.json',
                      package: "digitalpaye_sdk_flutter",
                      height: 100,
                      fit: BoxFit.cover,
                    ),
                  ), // Indicateur de chargement
                ),
              ),
          ],
        ),
      ),
    ),
  );
}