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) {
  final controller = Get.put(SubscriptionsController());
  dobKey = GlobalKey();
  passportKey = GlobalKey();
  return AlertDialog(
    backgroundColor: Colors.white,
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(16.dp),
    ),
    content: SingleChildScrollView(
      child: Container(
        width: 720,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  "Add New Passenger",
                  style: TextStyle(
                    fontSize: 18.dp,
                    fontWeight: FontWeight.w600,
                    color: ColorHelper.neutralMediumText,
                  ),
                ),
                InkWell(
                  onTap: () => Get.back(),
                  child: Image.asset('assets/admins/close.png')),
              ],
            ),
            12.dp.SpaceX,
            ResponsiveGridRow(
              children: [
                ResponsiveGridCol(
                  xl: 6,
                  lg: 6,
                  md: 6,
                  sm: 8,
                  xs: 12,
                  child: _passengerTextField(
                    controller.firstNameController,
                    'John',
                    true,
                    'First Name',
                  ),
                ),
                ResponsiveGridCol(
                  xl: 6,
                  lg: 6,
                  md: 6,
                  sm: 8,
                  xs: 12,
                  child: _passengerTextField(
                    controller.lastNameController,
                    'Doe',
                    true,
                    'Last Name',
                  ),
                ),
                ResponsiveGridCol(
                  xl: 6,
                  lg: 6,
                  md: 6,
                  sm: 8,
                  xs: 12,
                  child:  Stack(
                    children: [
                      Container(
                      width: 330.dp,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(12.dp),
                        border: Border.all(
                          color: ColorHelper.grey01,
                          width: 1.dp,
                        ),
                      ),
                      padding: EdgeInsets.symmetric(horizontal: 4.dp, vertical: 11.dp),
                      margin: EdgeInsets.symmetric(vertical: 10.dp, horizontal: 8.dp),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Obx(
                                () => DropdownButtonHideUnderline(
                                  child: DropdownButton2<String>(
                                    isExpanded: true,
                                    hint: Text(
                                      'Select Nationality'.tr,
                                      style: TextStyle(
                                      fontSize: 16.dp,
                                      fontWeight: FontWeight.w400,
                                      color: ColorHelper.neutralLightText,
                                    ),
                                    ),
                                    value: controller
                                            .selectedNationality.value.isEmpty
                                        ? null
                                        : controller.selectedNationality.value,
                                    items: Constants.ALL_COUNTRIES_ALPHA_2.keys
                                        .map((String value) {
                                      return DropdownMenuItem(
                                        value: value,
                                        child: Row(
                                          children: [
                                            CountryFlag.fromCountryCode(
                                              Constants.ALL_COUNTRIES_ALPHA_2[
                                                      value] ??
                                                  "",
                                              height: 15,
                                              width: 15,
                                            ),
                                            const SizedBox(
                                              width: 10,
                                            ),
                                            Text(
                                              value,
                                              style: TextStyle(
                                                fontSize: 16.dp,
                                                fontWeight: FontWeight.w400,
                                                color: ColorHelper.neutralMediumText,
                                              ),
                                            ),
                                          ],
                                        ),
                                      );
                                    }).toList(),
                                    onChanged: (newValue) {
                                      print(
                                          'Drop Down Vale ============== $newValue');
                                      controller.selectedNationality.value =
                                          newValue ?? "";
                                    },
                                    iconStyleData: IconStyleData(
                                      icon:
                                          Image.asset('assets/home/dropdown.png'),
                                    ),
                                    buttonStyleData: const ButtonStyleData(
                                      padding:
                                          EdgeInsets.symmetric(horizontal: 20),
                                      height: 25,
                                    ),
                                    dropdownStyleData: DropdownStyleData(
                                      maxHeight: 250,
                                      width: 330,
                                      decoration: BoxDecoration(
                                        color: Colors.white,
                                        borderRadius: BorderRadius.circular(12),
                                      ),
                                    ),
                                    menuItemStyleData: const MenuItemStyleData(
                                      height: 25,
                                    ),
                                    dropdownSearchData: DropdownSearchData(
                                      searchController:
                                          controller.nationalitySearchController,
                                      searchInnerWidgetHeight: 50,
                                      searchInnerWidget: Container(
                                        height: 50,
                                        padding: const EdgeInsets.only(
                                          top: 8,
                                          bottom: 4,
                                          right: 8,
                                          left: 8,
                                        ),
                                        child: TextFormField(
                                          expands: true,
                                          maxLines: null,
                                          controller: controller
                                              .nationalitySearchController,
                                          decoration: InputDecoration(
                                            isDense: true,
                                            contentPadding:
                                                const EdgeInsets.symmetric(
                                              horizontal: 10,
                                              vertical: 8,
                                            ),
                                            hintText: 'Search for an item...',
                                            hintStyle:
                                                const TextStyle(fontSize: 12),
                                            border: OutlineInputBorder(
                                              borderRadius:
                                                  BorderRadius.circular(8),
                                            ),
                                          ),
                                        ),
                                      ),
                                      searchMatchFn: (item, searchValue) {
                                        return item.value
                                            .toString()
                                            .toLowerCase()
                                            .contains(searchValue.toLowerCase());
                                      },
                                    ),
                                    //This to clear the search value when you close the menu
                                    onMenuStateChange: (isOpen) {
                                      if (!isOpen) {
                                        controller.nationalitySearchController
                                            .clear();
                                      }
                                    },
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                    Positioned(
                    left: 16.dp,
                    top: 2.dp,
                    child: Container(
                      padding: EdgeInsets.symmetric(horizontal: 8.dp),
                      color: Colors.white,
                      child: Text(
                        'Nationality',
                        style: TextStyle(
                          fontSize: 12.dp,
                          fontWeight: FontWeight.w400,
                          color: ColorHelper.neutralLightText,
                        ),
                      ),
                    ),
                  ),
                    ],
                  ),
                ),
                ResponsiveGridCol(
                  xl: 6,
                  lg: 6,
                  md: 6,
                  sm: 8,
                  xs: 12,
                  child: Stack(
                    children: [
                      Container(
                        key: dobKey,
                      width: 330.dp,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(12.dp),
                        border: Border.all(
                          color: ColorHelper.grey01,
                          width: 1.dp,
                        ),
                      ),
                      padding: EdgeInsets.symmetric(horizontal: 24.dp, vertical: 12.5.dp),
                      margin: EdgeInsets.symmetric(vertical: 10.dp, horizontal: 8.dp),
                          child: InkWell(
                            onTap: () => controller.onTapDob(dobKey),
                            child: dateField(
                              controller.dobController,
                                  '2000-01-28', false, 'calender'),
                          ),
                        ),
                    Positioned(
                    left: 16.dp,
                    top: 2.dp,
                    child: Container(
                      padding: EdgeInsets.symmetric(horizontal: 8.dp),
                      color: Colors.white,
                      child: Text(
                        'Date of Birth',
                        style: TextStyle(
                          fontSize: 12.dp,
                          fontWeight: FontWeight.w400,
                          color: ColorHelper.neutralLightText,
                        ),
                      ),
                    ),
                  ),
                    ],
                  ),
                ),
                ResponsiveGridCol(
                  xl: 6,
                  lg: 6,
                  md: 6,
                  sm: 8,
                  xs: 12,
                  child: Stack(
                    children: [
                      Container(
                        width: 330.dp,
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(12.dp),
                            border: Border.all(
                              color: ColorHelper.grey01,
                              width: 1.dp,
                            ),
                          ),
                          padding: EdgeInsets.symmetric(horizontal: 24.dp, vertical: 12.5.dp),
                          margin: EdgeInsets.symmetric(vertical: 10.dp, horizontal: 8.dp),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Obx(
                                () => DropdownButton(
                                  menuMaxHeight: 200,
                                  borderRadius: BorderRadius.circular(16),
                                  dropdownColor: Colors.white,
                                  underline: Container(),
                                  isExpanded: true,
                                  isDense: true,
                                  hint: Text(
                                    'Select Gender'.tr,
                                    style: TextStyle(
                                      fontSize: 16.dp,
                                      fontWeight: FontWeight.w400,
                                      color: ColorHelper.neutralLightText,
                                    ),
                                  ),
                                  icon: Image.asset('assets/home/dropdown.png'),
                                  value: controller.selectedGender.value.isEmpty
                                      ? null
                                      : controller.selectedGender.value,
                                  items: Constants.PASSENGER_GENDER.keys
                                      .map((String value) {
                                    return DropdownMenuItem(
                                      value: value,
                                      child: Row(
                                        children: [
                                          Text(
                                            value,
                                            style: TextStyle(
                                                fontSize: 16.dp,
                                                fontWeight: FontWeight.w400,
                                                color: ColorHelper.neutralMediumText,
                                              ),
                                          ),
                                        ],
                                      ),
                                    );
                                  }).toList(),
                                  onChanged: (newValue) {
                                    print(
                                        'Drop Down Vale ============== $newValue');
                                    controller.selectedGender.value =
                                        newValue ?? "";
                                  },
                                ),
                              ),
                            ],
                          ),
                        ),
                        Positioned(
                    left: 16.dp,
                    top: 2.dp,
                    child: Container(
                      padding: EdgeInsets.symmetric(horizontal: 8.dp),
                      color: Colors.white,
                      child: Text(
                        'Gender',
                        style: TextStyle(
                          fontSize: 12.dp,
                          fontWeight: FontWeight.w400,
                          color: ColorHelper.neutralLightText,
                        ),
                      ),
                    ),
                  ),
                    ],
                  ),
                ),
                ResponsiveGridCol(
                  xl: 6,
                  lg: 6,
                  md: 6,
                  sm: 8,
                  xs: 12,
                  child: _passengerTextField(
                    controller.passportNumberController,
                    '123456',
                    true,
                    'Passport Number',
                  ),
                ),
                ResponsiveGridCol(
                  xl: 6,
                  lg: 6,
                  md: 6,
                  sm: 8,
                  xs: 12,
                  child:  Stack(
                    children: [
                      Container(
                      width: 330.dp,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(12.dp),
                        border: Border.all(
                          color: ColorHelper.grey01,
                          width: 1.dp,
                        ),
                      ),
                      padding: EdgeInsets.symmetric(horizontal: 4.dp, vertical: 11.dp),
                      margin: EdgeInsets.symmetric(vertical: 10.dp, horizontal: 8.dp),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Obx(
                                () => DropdownButtonHideUnderline(
                                  child: DropdownButton2<String>(
                                    isExpanded: true,
                                    hint: Text(
                                      'Select Country'.tr,
                                      style: TextStyle(
                                      fontSize: 16.dp,
                                      fontWeight: FontWeight.w400,
                                      color: ColorHelper.neutralLightText,
                                    ),
                                    ),
                                    value: controller
                                            .selectedCountry.value.isEmpty
                                        ? null
                                        : controller.selectedCountry.value,
                                    items: Constants.ALL_COUNTRIES_ALPHA_2.keys
                                        .map((String value) {
                                      return DropdownMenuItem(
                                        value: value,
                                        child: Row(
                                          children: [
                                            CountryFlag.fromCountryCode(
                                              Constants.ALL_COUNTRIES_ALPHA_2[
                                                      value] ??
                                                  "",
                                              height: 15,
                                              width: 15,
                                            ),
                                            const SizedBox(
                                              width: 10,
                                            ),
                                            Text(
                                              value,
                                              style: TextStyle(
                                                fontSize: 16.dp,
                                                fontWeight: FontWeight.w400,
                                                color: ColorHelper.neutralMediumText,
                                              ),
                                            ),
                                          ],
                                        ),
                                      );
                                    }).toList(),
                                    onChanged: (newValue) {
                                      print(
                                          'Drop Down Vale ============== $newValue');
                                      controller.selectedCountry.value =
                                          newValue ?? "";
                                    },
                                    iconStyleData: IconStyleData(
                                      icon:
                                          Image.asset('assets/home/dropdown.png'),
                                    ),
                                    buttonStyleData: const ButtonStyleData(
                                      padding:
                                          EdgeInsets.symmetric(horizontal: 20),
                                      height: 25,
                                    ),
                                    dropdownStyleData: DropdownStyleData(
                                      maxHeight: 250,
                                      width: 330,
                                      decoration: BoxDecoration(
                                        color: Colors.white,
                                        borderRadius: BorderRadius.circular(12),
                                      ),
                                    ),
                                    menuItemStyleData: const MenuItemStyleData(
                                      height: 25,
                                    ),
                                    dropdownSearchData: DropdownSearchData(
                                      searchController:
                                          controller.countrySearchController,
                                      searchInnerWidgetHeight: 50,
                                      searchInnerWidget: Container(
                                        height: 50,
                                        padding: const EdgeInsets.only(
                                          top: 8,
                                          bottom: 4,
                                          right: 8,
                                          left: 8,
                                        ),
                                        child: TextFormField(
                                          expands: true,
                                          maxLines: null,
                                          controller: controller
                                              .countrySearchController,
                                          decoration: InputDecoration(
                                            isDense: true,
                                            contentPadding:
                                                const EdgeInsets.symmetric(
                                              horizontal: 10,
                                              vertical: 8,
                                            ),
                                            hintText: 'Search for an item...',
                                            hintStyle:
                                                const TextStyle(fontSize: 12),
                                            border: OutlineInputBorder(
                                              borderRadius:
                                                  BorderRadius.circular(8),
                                            ),
                                          ),
                                        ),
                                      ),
                                      searchMatchFn: (item, searchValue) {
                                        return item.value
                                            .toString()
                                            .toLowerCase()
                                            .contains(searchValue.toLowerCase());
                                      },
                                    ),
                                    //This to clear the search value when you close the menu
                                    onMenuStateChange: (isOpen) {
                                      if (!isOpen) {
                                        controller.countrySearchController
                                            .clear();
                                      }
                                    },
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                    Positioned(
                    left: 16.dp,
                    top: 2.dp,
                    child: Container(
                      padding: EdgeInsets.symmetric(horizontal: 8.dp),
                      color: Colors.white,
                      child: Text(
                        'Passport Issuing Country',
                        style: TextStyle(
                          fontSize: 12.dp,
                          fontWeight: FontWeight.w400,
                          color: ColorHelper.neutralLightText,
                        ),
                      ),
                    ),
                  ),
                    ],
                  ),
                ),
                ResponsiveGridCol(
                  xl: 6,
                  lg: 6,
                  md: 6,
                  sm: 8,
                  xs: 12,
                  child: Stack(
                    children: [
                      Container(
                        key: passportKey,
                      width: 330.dp,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(12.dp),
                        border: Border.all(
                          color: ColorHelper.grey01,
                          width: 1.dp,
                        ),
                      ),
                      padding: EdgeInsets.symmetric(horizontal: 24.dp, vertical: 12.5.dp),
                      margin: EdgeInsets.symmetric(vertical: 10.dp, horizontal: 8.dp),
                          child: InkWell(
                            onTap: () => controller.onTapPassportExpiry(passportKey),
                            child: dateField(
                              controller.passportExpiryController,
                                  '2000-01-28', false, 'calender'),
                          ),
                        ),
                    Positioned(
                    left: 16.dp,
                    top: 2.dp,
                    child: Container(
                      padding: EdgeInsets.symmetric(horizontal: 8.dp),
                      color: Colors.white,
                      child: Text(
                        'Passport Expiry Date',
                        style: TextStyle(
                          fontSize: 12.dp,
                          fontWeight: FontWeight.w400,
                          color: ColorHelper.neutralLightText,
                        ),
                      ),
                    ),
                  ),
                    ],
                  ),
                ),
                ResponsiveGridCol(
                xl: 12,
                lg: 12,
                md: 12,
                sm: 12,
                xs: 12,
                child: _passengerTypeWidget(
                  controller,
                ),
              ),
              ],
            ),
            15.SpaceX,
            Row(
              children: [
                Expanded(
                  child: InkWell(
                    onTap: () {
                      Get.back();
                    },
                    child: Container(
                      height: 50.dp,
                      width: Get.width,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(8.dp),
                        border: Border.all(
                          width: 1.dp,
                          color: ColorHelper.primaryBlue,
                        ),
                      ),
                      child: Center(
                        child: Text(
                          "Cancel",
                          style: TextStyle(
                            fontSize: 18.dp,
                            fontWeight: FontWeight.w500,
                            color: ColorHelper.primaryBlue,
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
                12.dp.SpaceY,
                Expanded(
                  child: CustomButton(
                    buttonText: "Save",
                    onTap:() {
                      controller.validateFields(id);
                    },
                    fontSize: 18.dp,
                    buttonHeight: 50.dp,
                    buttonWidth: Get.width,
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    ),
  );
}