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 when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). 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 and from the given BuildContext.

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. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.

The implementation of this method must only depend on:

If a widget's build method is to depend on anything else, use a StatefulWidget instead.

See also:

  • StatelessWidget, which contains the discussion on performance considerations.

Implementation

@override
Widget build(BuildContext context) {
  var typeList = verificationTypeList.asMap();
  // on "Yes Continue" button click. create base 64 of captured image and save in proof param of respective service
  // checks for further verifications, calls API if none left, navigates to other screen accordingly
  void YesContinue() {
    turn = 1;
    File file = File(imagePath);
    Uint8List bytes = file.readAsBytesSync();
    String base64Image = base64Encode(bytes);

    typeList = verificationTypeList.asMap();
    if (typeList[0] == "face") {
      requestedPayloadTemp = requestedPayload["face"] as Map<String,Object>;
      requestedPayloadTemp["proof"] = base64Image;
      requestedPayload["face"] = requestedPayloadTemp;
    } else if (typeList[0] == "document") {
      if (!isBackside) {
        requestedPayloadTemp = requestedPayload["document"] as Map<String,Object>;
        requestedPayloadTemp["proof"] = base64Image;
        requestedPayload["document"] = requestedPayloadTemp;
      } else {
        requestedPayloadTemp = requestedPayload["document"] as Map<String,Object>;
        requestedPayloadTemp["additional_proof"] = base64Image;
        requestedPayload["document"] = requestedPayloadTemp;
      }
    } else if (typeList[0] == "document_two") {
      if (!isBackside) {
        requestedPayloadTemp = requestedPayload["document_two"] as Map<String,Object>;
        requestedPayloadTemp["proof"] = base64Image;
        requestedPayload["document_two"] = requestedPayloadTemp;
      } else {
        requestedPayloadTemp = requestedPayload["document_two"] as Map<String,Object>;
        requestedPayloadTemp["additional_proof"] = base64Image;
        requestedPayload["document_two"] = requestedPayloadTemp;
      }
    } else if (typeList[0] == "address") {
      requestedPayloadTemp = requestedPayload["address"] as Map<String,Object>;
      requestedPayloadTemp["proof"] = base64Image;
      requestedPayload["address"] = requestedPayloadTemp;
    } else if (typeList[0] == "consent") {
      requestedPayloadTemp = requestedPayload["consent"] as Map<String,Object>;
      requestedPayloadTemp["proof"] = base64Image;
      requestedPayload["consent"] = requestedPayloadTemp;
    }

    requestedPayloadTemp = requestedPayload[typeList[0]] as Map<String,Object>;

    if (requestedPayloadTemp["supported_types"].toString().toLowerCase() ==
            "[passport]" &&
        !isBackside &&
        (typeList[0] == "document" || typeList[0] == "document_two")) {
      if (requestedPayloadTemp["backside_proof_required"].toString() ==
              null ||
          requestedPayloadTemp["backside_proof_required"].toString() == "" ||
          requestedPayloadTemp["backside_proof_required"].toString() == "0") {
        verificationTypeList.removeAt(0);
        supportedTypes_list = [];
        typeList = verificationTypeList.asMap();
        isBackside = false;
        isCheck = false;
        if (verificationTypeList.length == 0) {
          if (asyncSDK &&
              !requestedPayload.containsKey('background_checks') &&
              !requestedPayload.containsKey('phone')) {
            check().then((intenet) {
              if (intenet != null && intenet) {
                ApiMethods().apiRequest().then((response) {
                  callback(response);
                });
              } else {
                callback("internet.connection.problem");
              }
              Navigator.pushAndRemoveUntil(
                  context,
                  MaterialPageRoute(builder: (context) => userHome),
                  (route) => false);
              callback("event: request.pending, error: '', reference: " +
                  createdPayloadSDK["reference"].toString());
            });
          } else {
            Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => Result(
                        callback: (res) {
                          callback(res);
                        }, title: '',
                      )),
            );
          }
        } else {
          Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => ShowInstructions(
                      callback: (res) {
                        callback(res);
                      },
                    )),
          );
        }
      } else if (requestedPayloadTemp["backside_proof_required"].toString() ==
          "1") {
        isBackside = true;
        Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => Ready(
                    callback: (res) {
                      callback(res);
                    },
                  )),
        );
      }
    } else if (!isBackside &&
        (typeList[0] == "document" || typeList[0] == "document_two")) {
      isBackside = true;
      Navigator.push(
        context,
        MaterialPageRoute(
            builder: (context) => Ready(
                  callback: (res) {
                    callback(res);
                  },
                )),
      );
    } else {
      verificationTypeList.removeAt(0);
      supportedTypes_list = [];
      typeList = verificationTypeList.asMap();
      isBackside = false;
      isCheck = false;
      if (verificationTypeList.length == 0) {
        if (asyncSDK &&
            !requestedPayload.containsKey('background_checks') &&
            !requestedPayload.containsKey('phone')) {
          check().then((intenet) {
            if (intenet != null && intenet) {
              ApiMethods().apiRequest().then((response) {
                callback(response);
              });
            } else {
              callback("internet.connection.problem");
            }
            Navigator.pushAndRemoveUntil(
                context,
                MaterialPageRoute(builder: (context) => userHome),
                (route) => false);
            callback("event: request.pending, error: '', reference: " +
                createdPayloadSDK["reference"].toString());
          });
        } else {
          Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => Result(
                      callback: (res) {
                        callback(res);
                      }, title: '',
                    )),
          );
        }
      } else {
        Navigator.push(
          context,
          MaterialPageRoute(
              builder: (context) => ShowInstructions(
                    callback: (res) {
                      callback(res);
                    },
                  )),
        );
      }
    }
  }
  // On backpress navigate to previous screen
  void _onBackPressed() {
    for (int i = 0; i < camCount; i++) {
      Navigator.pop(context);
    }
    camCount = 1;
  }
  // UI for preview screen
  return WillPopScope(
      onWillPop: () async {
        for (int i = 0; i < camCount; i++) {
          Navigator.pop(context);
        }
        camCount = 1;
        return true;
      },
      // _onBackPressed,
      child: Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          backgroundColor: white,
          elevation: 0.0,
          centerTitle: true,
          title: Padding(
            padding: const EdgeInsets.only(
              top: 15,
            ),
            child: Text(
              " Confirmation",
              style: TextStyle(
                color: Colors.black,
                fontFamily: 'OpenSans',
                fontWeight: FontWeight.bold,
                fontSize: 20.sp,
              ),
            ),
          ),
          automaticallyImplyLeading: true,
          leading: GestureDetector(
            onTap: () {
              _onBackPressed();
            },
            child: Container(
              height: 27,
              width: 27,
              alignment: Alignment.centerLeft,
              margin: const EdgeInsets.fromLTRB(20, 0, 0, 0),
              child: Image(
                image: AssetImage("assets/images/back_icon.png"),
                height: 20,
                width: 20,
              ),
            ),
          ),
        ),
        body: Column(
          children: <Widget>[
            Expanded(
                flex: 1,
                child: Container(
                  height: 50.h,
                  color: Colors.white,
                  child: Column(
                    children: [
                      Spacer(),
                      typeList[0] == 'face'
                          ? Padding(
                              padding: EdgeInsets.only(
                                left: 15.w,
                                right: 15.w,
                              ),
                              child: Container(
                                alignment: Alignment.topLeft,
                                child: Text(
                                  "Can you see your full face in the photo?",
                                  textAlign: TextAlign.start,
                                  style: new TextStyle(
                                    fontFamily: 'OpenSans',
                                    fontSize: 16.sp,
                                    fontWeight: FontWeight.w600,
                                    color: Colors.black,
                                  ),
                                ),
                              ),
                            )
                          : typeList[0] == 'document'
                              ? Padding(
                                  padding: EdgeInsets.only(
                                    left: 15.w,
                                    right: 15.w,
                                  ),
                                  child: Container(
                                    alignment: Alignment.topLeft,
                                    child: Text(
                                      "Can you see the entire document clearly in the photo?",
                                      textAlign: TextAlign.start,
                                      style: new TextStyle(
                                        fontFamily: 'OpenSans',
                                        fontSize: 16.sp,
                                        fontWeight: FontWeight.w600,
                                        color: Colors.black,
                                      ),
                                    ),
                                  ),
                                )
                              : typeList[0] == 'document_two'
                                  ? Padding(
                                      padding: EdgeInsets.only(
                                        left: 15.w,
                                        right: 15.w,
                                      ),
                                      child: Container(
                                        alignment: Alignment.topLeft,
                                        child: Text(
                                          "Can you see the entire document clearly in the photo?",
                                          textAlign: TextAlign.start,
                                          style: new TextStyle(
                                            fontFamily: 'OpenSans',
                                            fontSize: 16.sp,
                                            fontWeight: FontWeight.w600,
                                            color: Colors.black,
                                          ),
                                        ),
                                      ),
                                    )
                                  : typeList[0] == 'address'
                                      ? Padding(
                                          padding: EdgeInsets.only(
                                            left: 15.w,
                                            right: 15.w,
                                          ),
                                          child: Container(
                                            alignment: Alignment.topLeft,
                                            child: Text(
                                              "Can you see the entire address document clearly in the photo?",
                                              textAlign: TextAlign.start,
                                              style: new TextStyle(
                                                fontFamily: 'OpenSans',
                                                fontSize: 16.sp,
                                                fontWeight: FontWeight.w600,
                                                color: Colors.black,
                                              ),
                                            ),
                                          ),
                                        )
                                      : Padding(
                                          padding: EdgeInsets.only(
                                            left: 15.w,
                                            right: 15.w,
                                          ),
                                          child: Container(
                                            alignment: Alignment.topLeft,
                                            child: Text(
                                              "Can you see your entire face and consent note clearly in the photo?",
                                              textAlign: TextAlign.start,
                                              style: new TextStyle(
                                                fontFamily: 'OpenSans',
                                                fontSize: 16.sp,
                                                fontWeight: FontWeight.w600,
                                                color: Colors.black,
                                              ),
                                            ),
                                          ),
                                        ),
                      Spacer(),
                    ],
                  ),
                )),
            Expanded(
              flex: 8,
              child: Padding(
                padding: EdgeInsets.only(
                  left: 10.w,
                  right: 15.w,
                ),
                child: cameraDirection == 1
                    ? Transform(
                        alignment: Alignment.center,
                        child: Image.file(File(imagePath)),
                        transform: Matrix4.rotationY(Math.pi))
                    : Image.file(File(imagePath)),
              ),
            ),
            Expanded(
              flex: 2,
              child: Column(
                children: <Widget>[
                  Expanded(
                    flex: 9,
                    child: Row(
                      children: [
                        Expanded(
                          flex: 1,
                          child: Padding(
                            padding: EdgeInsets.only(
                              left: 15.w,
                              right: 5.w,
                            ),
                            child: Container(
                              height: 45.h,
                              child: OutlinedButton(
                                child: Text(
                                  "Retake",
                                  style: TextStyle(
                                      fontFamily: 'OpenSans',
                                      fontSize: 18.sp,
                                      fontWeight: FontWeight.bold,
                                      color: Colors.black),
                                ),
                                style: OutlinedButton.styleFrom(
                                  shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(5)),
                                ),
                                onPressed: () {
                                  turn = 3;
                                  camCount = camCount + 1;
                                  Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                        builder: (context) => ImageCapture(
                                              callback: (res) {
                                                callback(res);
                                              },
                                            )),
                                  );
                                },
                              ),
                            ),
                          ),
                        ),
                        Expanded(
                          flex: 1,
                          child: Padding(
                            padding: EdgeInsets.only(
                              left: 0.w,
                              right: 15.w,
                            ),
                            child: Container(
                              height: 45.h,
                              child: OutlinedButton(
                                style: OutlinedButton.styleFrom(
                                  shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(5)),
                                  backgroundColor: Color(0xff2b6ad8),
                                ),
                                child: Text(
                                  'Yes, Continue',
                                  style: TextStyle(
                                    fontFamily: 'OpenSans',
                                    fontSize: 18.sp,
                                    fontWeight: FontWeight.bold,
                                    color: Colors.white,
                                  ),
                                ),
                                onPressed: () => YesContinue(),
                              ),
                            ),
                          ),
                        )
                      ],
                    ),
                  ),
                  Expanded(
                    flex: 2,
                    child: Padding(
                      padding: EdgeInsets.only(
                        bottom: 14.w,
                      ),
                      child: Container(
                          height: 13.h,
                          child: Image.asset("assets/sdk/footerImage.png")),
                    ),
                  ),
                ],
              ),
            )
          ],
        ),
      ));
}