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) {
  if ((typeList[0] == "document" ||
      typeList[0] == "document_two" ||
      typeList[0] == "address" ||
      typeList[0] == "consent")) {
    documentPayloadObj = requestedPayload[typeList[0]] as Map<String,Object>;
    supportedTypesObj =
        printVal(documentPayloadObj['supported_types'].toString());
    supportedTypesObj = supportedTypesObj.replaceAll('[', '');
    supportedTypesObj = supportedTypesObj.replaceAll(']', '');
  }

  // Image verification UI
  Widget ImageText() {
    Map<String, Object> reqPassport = requestedPayload[typeList[0]] as Map<String,Object>;

    if (nationality == null) {
      nationality = "";
    }
    return Column(
      children: [
        Padding(
            padding: EdgeInsets.only(
              left: 20.w,
              bottom: 5.w,
              right: 20.w,
            ),
            child: typeList[0] == 'face'
                ? Image(
                    image: AssetImage("assets/sdk/face.png"),
                    height: 100.h,
                    width: 0.17.sw,
                  )
                : Image(
                    image: AssetImage("assets/sdk/document.png"),
                    height: 100.h,
                    width: 0.17.sw,
                  )),
        new Text(
          "Ready to take a photo?",
          style: new TextStyle(
              fontFamily: 'OpenSans',
              fontSize: 20.sp,
              color: Colors.black,
              fontWeight: FontWeight.bold),
        ),
        Padding(
          padding: EdgeInsets.only(
            top: 13.w,
            left: 30.w,
            bottom: 5.w,
            right: 30.w,
          ),
          child: typeList[0] == 'face'
              ? new Text(
                  "Take a photo of your entire face",
                  textAlign: TextAlign.center,
                  style: new TextStyle(
                    fontFamily: 'OpenSans',
                    fontSize: 16.sp,
                    color: Colors.black,
                    fontWeight: FontWeight.w600,
                  ),
                )
              : typeList[0] == 'consent'
                  ? new Text(
                      "Take a photo of the consent note along with your face",
                      textAlign: TextAlign.center,
                      style: new TextStyle(
                        fontFamily: 'OpenSans',
                        fontSize: 16.sp,
                        color: Colors.black,
                        fontWeight: FontWeight.w600,
                      ),
                    )
                  : typeList[0] == 'address'
                      ? reqPassport['supported_types']
                              .toString()
                              .contains("passport")
                          ? new Text(
                              "Take a picture of the photo page of your $nationality $supportedTypesObj",
                              textAlign: TextAlign.center,
                              style: new TextStyle(
                                fontFamily: 'OpenSans',
                                fontSize: 16.sp,
                                color: Colors.black,
                                fontWeight: FontWeight.w600,
                              ),
                            )
                          : new Text(
                              "Take a photo of your $nationality $supportedTypesObj",
                              textAlign: TextAlign.center,
                              style: new TextStyle(
                                fontFamily: 'OpenSans',
                                fontSize: 16.sp,
                                color: Colors.black,
                                fontWeight: FontWeight.w600,
                              ),
                            )
                      : !isBackside
                          ? reqPassport['supported_types']
                                  .toString()
                                  .contains("passport")
                              ? new Text(
                                  "Take a picture of the photo page of your $nationality $supportedTypesObj",
                                  textAlign: TextAlign.center,
                                  style: new TextStyle(
                                    fontFamily: 'OpenSans',
                                    fontSize: 16.sp,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w600,
                                  ),
                                )
                              : new Text(
                                  "Take a photo of the front side of your $nationality $supportedTypesObj",
                                  textAlign: TextAlign.center,
                                  style: new TextStyle(
                                    fontFamily: 'OpenSans',
                                    fontSize: 16.sp,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w600,
                                  ),
                                )
                          : reqPassport['supported_types']
                                  .toString()
                                  .contains("passport")
                              ? new Text(
                                  "Take a picture of the second page of your $nationality $supportedTypesObj",
                                  textAlign: TextAlign.center,
                                  style: new TextStyle(
                                    fontFamily: 'OpenSans',
                                    fontSize: 16.sp,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w600,
                                  ),
                                )
                              : new Text(
                                  "Take a photo of the backside of your $nationality $supportedTypesObj",
                                  textAlign: TextAlign.center,
                                  style: new TextStyle(
                                    fontFamily: 'OpenSans',
                                    fontSize: 16.sp,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
        ),
        Spacer(),
      ],
    );
  }
  // Video verification UI
  Widget VideoText() {
    Map<String, Object> reqPassport = requestedPayload[typeList[0]] as Map<String,Object>;

    if (nationality == null) {
      nationality = "";
    }
    return Column(
      children: [
        Padding(
          padding: EdgeInsets.only(
            left: 20.w,
            bottom: 5.w,
            right: 20.w,
          ),
          child: requestedPayload.containsKey('face')
              ? Image(
                  image: AssetImage("assets/sdk/face.png"),
                  height: 100.h,
                  width: 0.17.sw,
                )
              : Image(
                  image: AssetImage("assets/sdk/document.png"),
                  height: 100.h,
                  width: 0.17.sw,
                ),
        ),
        new Text(
          "Ready to record a video?",
          style: new TextStyle(
              fontFamily: 'OpenSans',
              fontSize: 20.sp,
              color: Colors.black,
              fontWeight: FontWeight.bold),
        ),
        Padding(
          padding: EdgeInsets.only(
            top: 13.w,
            left: 30.w,
            bottom: 5.w,
            right: 30.w,
          ),
          child: requestedPayload.containsKey("face") &&
                  verificationTypeList[0] == "face"
              ? new Text(
                  "Record a video of your entire face",
                  textAlign: TextAlign.center,
                  style: new TextStyle(
                    fontFamily: 'OpenSans',
                    fontSize: 16.sp,
                    color: Colors.black,
                    fontWeight: FontWeight.w600,
                  ),
                )
              : requestedPayload.containsKey("consent") &&
                      verificationTypeList[0] == "consent"
                  ? new Text(
                      "Record a video of the consent note with your face",
                      textAlign: TextAlign.center,
                      style: new TextStyle(
                        fontFamily: 'OpenSans',
                        fontSize: 16.sp,
                        color: Colors.black,
                        fontWeight: FontWeight.w600,
                      ),
                    )
                  : typeList[0] == 'address'
                      ? reqPassport['supported_types']
                              .toString()
                              .contains("passport")
                          ? new Text(
                              "Record a video of the photo page of your $nationality $supportedTypesObj",
                              textAlign: TextAlign.center,
                              style: new TextStyle(
                                fontFamily: 'OpenSans',
                                fontSize: 16.sp,
                                color: Colors.black,
                                fontWeight: FontWeight.w600,
                              ),
                            )
                          : new Text(
                              "Record a video of your $nationality $supportedTypesObj",
                              textAlign: TextAlign.center,
                              style: new TextStyle(
                                fontFamily: 'OpenSans',
                                fontSize: 16.sp,
                                color: Colors.black,
                                fontWeight: FontWeight.w600,
                              ),
                            )
                      : !isBackside
                          ? reqPassport['supported_types']
                                  .toString()
                                  .contains("passport")
                              ? new Text(
                                  "Record a video of the photo page of your $nationality $supportedTypesObj",
                                  textAlign: TextAlign.center,
                                  style: new TextStyle(
                                    fontFamily: 'OpenSans',
                                    fontSize: 16.sp,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w600,
                                  ),
                                )
                              : new Text(
                                  "Record a video of the front side of your $nationality $supportedTypesObj",
                                  textAlign: TextAlign.center,
                                  style: new TextStyle(
                                    fontFamily: 'OpenSans',
                                    fontSize: 16.sp,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w600,
                                  ),
                                )
                          : reqPassport['supported_types']
                                  .toString()
                                  .contains("passport")
                              ? new Text(
                                  "Record a video of the second page of your $nationality $supportedTypesObj",
                                  textAlign: TextAlign.center,
                                  style: new TextStyle(
                                    fontFamily: 'OpenSans',
                                    fontSize: 16.sp,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w600,
                                  ),
                                )
                              : new Text(
                                  "Record a video of the backside of your $nationality $supportedTypesObj",
                                  textAlign: TextAlign.center,
                                  style: new TextStyle(
                                    fontFamily: 'OpenSans',
                                    fontSize: 16.sp,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
        ),
        Spacer(),
      ],
    );
  }
  //back press override. navigate to previous screen
  void _onBackPressed() {
    if (isBackside && isBacksideProcessing) {
      camCount = frontCamCountCopy;
      isBacksideProcessing = false;
    }
    isBackside = false;
    turn = 2;
    Navigator.of(context).pop();
  }

  String verificationType = printVal(typeList[0]);

  // border resource
  BoxDecoration myBoxDecoration() {
    return BoxDecoration(
      border: Border.all(
        color: Colors.black12,
        width: 0.9,
      ),
    );
  }
  // UI of Ready to capture screen
  return WillPopScope(
      onWillPop:  () async {
        if (isBackside && isBacksideProcessing) {
          camCount = frontCamCountCopy;
          isBacksideProcessing = false;
        }
        isBackside = false;
        turn = 2;
        Navigator.of(context).pop();
        return true;
      } ,
      // _onBackPressed,
      child: Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          elevation: 0.0,
          centerTitle: true,
          title: Text(
            "$verificationType Verification",
            style: TextStyle(
              color: Colors.black,
              fontFamily: 'OpenSans',
              fontWeight: FontWeight.bold,
            ),
          ),
          backgroundColor: white,
          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/sdk/back_icon.png"),
                height: 20,
                width: 20,
              ),
            ),
          ),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              Spacer(),
              Expanded(
                flex: 2,
                child: requestedPayload['verification_mode'] == 'image_only'
                    ? ImageText()
                    : VideoText(),
              ),
              Padding(
                padding: EdgeInsets.only(
                  top: 7.w,
                  left: 10.w,
                  bottom: 5.w,
                  right: 10.w,
                ),
                child: Container(
                  height: 45.h,
                  width: 1.sw,
                  child: OutlinedButton(
                    onPressed: () {
                      _current = 10;
                      turn = 1;
                      if (isBackside) {
                        frontCamCountCopy = camCount;
                        isBacksideProcessing = true;
                      }
                      camCount = 1;
                      requestedPayload['verification_mode'] == 'image_only'
                          ? Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) => ImageCapture(
                                        callback: (res) {
                                          callback(res);
                                          // print("\n\ncalling preview: " +
                                          //     res.toString());
                                        },
                                      )),
                            )
                          : Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) => VideoRecorder(
                                        callback: (res) {
                                          callback(res);
                                          // print("\n\ncalling preview: " +
                                          //     res.toString());
                                        },
                                      )),
                            );
                    },
                    style: OutlinedButton.styleFrom(
                      backgroundColor: Color(0xff2b6ad8),
                    ),
                    child: new Text(
                      "Yes, I'm Ready",
                      textAlign: TextAlign.center,
                      style: new TextStyle(
                        fontFamily: 'OpenSans',
                        fontSize: 17.sp,
                        fontWeight: FontWeight.bold,
                        color: Colors.white,
                      ),
                    ),
                  ),
                ),
              ),
              typeList[0] == "document" || typeList[0] == "document_two"
                  ? requestedPayloadTemp
                              .containsKey("backside_proof_required") &&
                          (requestedPayloadTemp["backside_proof_required"] ==
                                  "0" ||
                              (requestedPayloadTemp["supported_types"]
                                          .toString()
                                          .toLowerCase() ==
                                      "[passport]" &&
                                  requestedPayloadTemp[
                                          "backside_proof_required"] ==
                                      "1")) &&
                          isBackside
                      ? Padding(
                          padding: EdgeInsets.only(
                            top: 7.w,
                            left: 10.w,
                            bottom: 5.w,
                            right: 10.w,
                          ),
                          child: Container(
                            height: 45.h,
                            width: 1.sw,
                            decoration: myBoxDecoration(),
                            child: OutlinedButton(
                              onPressed: () {
                                verificationTypeList.removeAt(0);
                                supportedTypes_list = [];
                                typeList = verificationTypeList.asMap();
                                isBackside = 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");
                                      }
                                      isCheck = false;
                                      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);
                                                  // print("\n\ncalling preview: " +
                                                  //     res.toString());
                                                }, title: '',
                                              )),
                                    );
                                  }
                                } else {
                                  Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                        builder: (context) =>
                                            ShowInstructions(
                                              callback: (res) {
                                                callback(res);
                                                // print("\n\ncalling preview: " +
                                                //     res.toString());
                                              },
                                            )),
                                  );
                                }
                              },
                              style: OutlinedButton.styleFrom(
                                backgroundColor: Colors.white,
                              ),
                              child: new Text(
                                "Skip",
                                textAlign: TextAlign.center,
                                style: new TextStyle(
                                  fontFamily: 'OpenSans',
                                  fontSize: 17.sp,
                                  fontWeight: FontWeight.bold,
                                  color: Colors.black,
                                ),
                              ),
                            ),
                          ),
                        )
                      : new Text("")
                  : new Text(""),
              Spacer(),
              Padding(
                padding: EdgeInsets.only(
                  bottom: 14.w,
                ),
                child: Container(
                    height: 13.h,
                    child: Image.asset("assets/sdk/footerImage.png")),
              ),
            ],
          ),
        ),
      ));
}