title: Flutter GetX Re-Initialise GetX Controller Reset GetX Controller, Reset GetX Controller Values
body: <p>I am learning Flutter GetX to my own and stuck on a point. Actually I want to know why onInit method of GetX Controlled is not calling whenever I revisit that page/dialog again.</p>
  <p>Suppose that I have dialog with a simple TextField, a Listview the TextField is used for searching the listview. When the User enters any filter key inside the text field, the listview will be filtered.</p>
  <p>Here is the Sample Dialog:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'package:flutter_base_sample/util/apptheme/colors/app_colors.dart';
  import 'package:flutter_base_sample/util/apptheme/styles/text_styles_util.dart';
  import 'package:flutter_base_sample/util/commons/app_util.dart';
  import 'package:flutter_base_sample/util/widgets/alert/controllers/country_finder_alert_controller.dart';
  import 'package:flutter_base_sample/util/widgets/marquee/marquee_widget.dart';
  import 'package:flutter_base_sample/util/widgets/textfields/app_text_field.dart';
  import 'package:get/get.dart';
  
  class SampleDialogWidget extends StatelessWidget {
    final CountryFinderAlertController controller = Get.put(CountryFinderAlertController(),permanent: true);
  
    @override
    Widget build(BuildContext context) {
      return Dialog(
        insetPadding: AppUtil.dialogPadding(context),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(20),
        ),
        elevation: 0.0,
        backgroundColor: Colors.white,
        child: dialogContent(context),
      );
    }
  
    Widget dialogContent(BuildContext context) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        mainAxisAlignment: MainAxisAlignment.start,
        mainAxisSize: MainAxisSize.max,
        children: [
          Text(
            &quot;Hello Heading&quot;,
            style: TextStyleUtil.quickSandBold(context, fontSize: 16, color: Colors.blue),
            textAlign: TextAlign.center,
          ),
          SizedBox(
            height: 20,
          ),
          Expanded(
            child: SingleChildScrollView(
              child: Container(
                height: AppUtil.deviceHeight(context),
                padding: EdgeInsetsDirectional.all(20),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text(&quot;Hello Text1&quot;),
                    SizedBox(
                      height: 10,
                    ),
                    getSearchField(context),
                    SizedBox(
                      height: 5,
                    ),
                    Expanded(
                      child: Obx(()=&gt; getFavoritesListView(context)),
                    )
                  ],
                ),
              ),
            ),
          ),
          SizedBox(
            height: 20,
          ),
          Container(
            margin: EdgeInsetsDirectional.only(start: 20,end: 20),
            child: ElevatedButton(
              onPressed: () {},
              style: ButtonStyle(
                overlayColor: MaterialStateProperty.all&lt;Color&gt;(Colors.red),
                // splashFactory: NoSplash.splashFactory,
                elevation: MaterialStateProperty.all(0.5),
                backgroundColor: MaterialStateProperty.resolveWith&lt;Color&gt;(
                  (Set&lt;MaterialState&gt; states) {
                    if (states.contains(MaterialState.pressed)) {
                      return AppColors.instance.black.withOpacity(0.1);
                    } else {
                      return Colors.blue; // Use the component's default.
                    }
                  },
                ),
              ),
              child: Text(
                &quot;Hello Footer&quot;,
                style: TextStyleUtil.quickSandBold(context, fontSize: 16, color: Colors.yellow),
                textAlign: TextAlign.center,
              ),
            ),
          )
        ],
      );
    }
  
    Widget getFavoritesListView(BuildContext context) {
      if (controller.favoritesList.length &gt; 0) {
        return ListView.separated(
          shrinkWrap: true,
          itemCount: controller.favoritesList.length,
          itemBuilder: (BuildContext context, int index) =&gt; _topupFavoriteContent(context, index),
          separatorBuilder: (context, index) {
            return Divider(
              indent: 15,
              endIndent: 15,
            );
          },
        );
      } else {
        return Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: [
              Text(
                &quot;No Data Found!&quot;,
                textAlign: TextAlign.center,
              ),
              SizedBox(
                height: 20,
              ),
            ],
          ),
        );
      }
    }
  
    Widget _topupFavoriteContent(BuildContext context, int index) {
      final item = controller.favoritesList[index];
      return InkWell(
          onTap: () {
            Get.back(result:item);
            // AppUtil.pop(context: context, valueToReturn: item);
          },
          child: getChildItems(context, index));
    }
  
    Widget getChildItems(BuildContext context, int index) {
      return Directionality(textDirection: TextDirection.ltr, child: getContactNumberAndNameHolder(context, index));
    }
  
    Widget getContactNumberAndNameHolder(BuildContext context, int index) {
      final item = controller.favoritesList[index];
      return Container(
        padding: EdgeInsetsDirectional.only(start: 20, end: 20, top: 20, bottom: 10),
        child: Column(
          children: [
            Row(
              // crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Flexible(
                  child: Align(
                    alignment: AlignmentDirectional.centerStart,
                    child: Text(
                      item.name ?? &quot;&quot;,
                      style: TextStyleUtil.quickSandBold(context, fontSize: 15, color: AppColors.instance.black),
                    ),
                  ),
                ),
                SizedBox(
                  width: 5,
                ),
                Container(),
                Align(
                  alignment: AlignmentDirectional.centerEnd,
                  child: MarqueeWidget(
                    child: Text(
                      item.dialCode ?? &quot;&quot;,
                      style: TextStyleUtil.quickSandBold(context, fontSize: 15, color: Colors.blue),
                    ),
                  ),
                ),
              ],
            )
          ],
        ),
      );
    }
  
    Widget getSearchField(
      BuildContext context,
    ) {
      return Container(
          margin: EdgeInsetsDirectional.only(start: 20, end: 20, top: 20),
          child: Row(
            children: [
              Expanded(
                child: AppTextField(
                  onChanged: (String text) {
                    controller.performSearchOnForFavoriteContact(text);
                  },
                  isPasswordField: false,
                  keyboardType: TextInputType.text,
                  suffixIconClickCallBack: () {},
                ),
              )
            ],
          ));
    }
  }
  </code></pre>
  <p>and here is the GetX Controller:</p>
  <pre><code>class CountryFinderAlertController extends GetxController {
    TextEditingController countrySearchFieldEditController = TextEditingController();
    RxList&lt;CountryHelperModel&gt; favoritesList;
    RxList&lt;CountryHelperModel&gt; originalList;
  
    @override
    void onInit() {
      super.onInit();
      debugPrint(&quot;Hello222&quot;);
      favoritesList = &lt;CountryHelperModel&gt;[].obs;
      originalList = &lt;CountryHelperModel&gt;[].obs;
    }
  
    @override
    void onReady() {
      super.onReady();
      debugPrint(&quot;Hello111&quot;);
      originalList.addAll(JSONHelperUtil.getCountries());
      addAllCountries();
    }
  
    @override
    void dispose() {
      super.dispose();
      countrySearchFieldEditController.dispose();
    }
  
    @override
    void onClose() {
      super.onClose();
    }
  
    void performSearchOnForFavoriteContact(String filterKey) {
      if (filterKey != null &amp;&amp; filterKey.isNotEmpty) {
        List&lt;CountryHelperModel&gt; filteredFavoritesList = [];
  
        debugPrint(&quot;filterKey&quot; + filterKey);
        originalList.forEach((element) {
          if (element.name.toLowerCase().contains(filterKey.toLowerCase()) ||
              element.countryCode.toLowerCase().contains(filterKey.toLowerCase()) ||
              element.dialCode.toLowerCase().contains(filterKey.toLowerCase())) {
            filteredFavoritesList.add(element);
          }
        });
  
        if (filteredFavoritesList.isNotEmpty) {
          favoritesList.clear();
          favoritesList.addAll(filteredFavoritesList);
        } else {
          favoritesList.clear();
        }
      } else {
        //reset the list
        addAllCountries();
      }
    }
  
    void addAllCountries() {
      favoritesList.clear();
      favoritesList.addAll(originalList);
    }
  }
  </code></pre>
  <p>So what I want is to load fresh data each time when I open this dialog. For now, if user will search for any country and close the dialog and then if reopen it the user will see the older search results.</p>
  <p>In simple means how can GetX Controller be Reset/Destroyed or reinitialised !</p>
  <p>Thanks in advance</p>