getBody method Null safety

  1. @override
List getBody()

Implementation

@override
List<Widget> getBody() => <Widget>[
      ListTile(
        title: Text(
          appLocalizations.dev_preferences_disable_mode,
        ),
        onTap: () async {
          // resetting back to "no dev mode"
          await userPreferences.setDevMode(0);
          // resetting back to PROD
          await userPreferences.setFlag(userPreferencesFlagProd, true);
          ProductQuery.setQueryType(userPreferences);
          setState(() {});
        },
      ),
      ListTile(
        title: Text(
          appLocalizations.dev_preferences_reset_onboarding_title,
        ),
        subtitle: Text(
          appLocalizations.dev_preferences_reset_onboarding_subtitle,
        ),
        onTap: () async {
          userPreferences
              .setLastVisitedOnboardingPage(OnboardingPage.NOT_STARTED);
          _showSuccessMessage();
        },
      ),
      ListTile(
        title: Text(
          appLocalizations.dev_preferences_environment_switch_title,
        ),
        subtitle: Text(
          appLocalizations.dev_preferences_environment_switch_subtitle(
            OpenFoodAPIConfiguration.globalQueryType.toString(),
          ),
        ),
        onTap: () async {
          await userPreferences.setFlag(userPreferencesFlagProd,
              !(userPreferences.getFlag(userPreferencesFlagProd) ?? true));
          ProductQuery.setQueryType(userPreferences);
          setState(() {});
        },
      ),
      ListTile(
        title: Text(
          appLocalizations.dev_preferences_test_environment_title,
        ),
        subtitle: Text(
          appLocalizations.dev_preferences_test_environment_subtitle(
            '${OpenFoodAPIConfiguration.uriScheme}://${OpenFoodAPIConfiguration.uriTestHost}/',
          ),
        ),
        onTap: () async => _changeTestEnvHost(),
      ),
      SwitchListTile(
        title: Text(
          appLocalizations.dev_preferences_ml_kit_title,
        ),
        subtitle: Text(
          appLocalizations.dev_preferences_ml_kit_subtitle,
        ),
        value: userPreferences.getFlag(userPreferencesFlagUseMLKit) ?? true,
        onChanged: (bool value) async {
          await userPreferences.setFlag(userPreferencesFlagUseMLKit, value);
          _showSuccessMessage();
        },
      ),
      ListTile(
        title: const Text('Change camera post frame callback duration'),
        onTap: () async => _changeCameraPostFrameCallbackDuration(),
      ),
      SwitchListTile(
        title: Text(
          appLocalizations.dev_preferences_product_additional_features_title,
        ),
        value: userPreferences.getFlag(userPreferencesFlagAdditionalButton) ??
            false,
        onChanged: (bool value) async {
          await userPreferences.setFlag(
              userPreferencesFlagAdditionalButton, value);
          _showSuccessMessage();
        },
      ),
      SwitchListTile(
        title: Text(
          appLocalizations.dev_preferences_edit_ingredients_title,
        ),
        value: userPreferences.getFlag(userPreferencesFlagEditIngredients) ??
            false,
        onChanged: (bool value) async {
          await userPreferences.setFlag(
              userPreferencesFlagEditIngredients, value);
          _showSuccessMessage();
        },
      ),
      ListTile(
        title: Text(
          appLocalizations.dev_preferences_export_history_title,
        ),
        onTap: () async {
          final LocalDatabase localDatabase = context.read<LocalDatabase>();
          final Map<String, dynamic> export =
              await DaoProductList(localDatabase).export(
            ProductList.history(),
          );
          final List<Widget> children = <Widget>[];
          for (final String barcode in export.keys) {
            final bool? exists = export[barcode] as bool?;
            children.add(
              ListTile(
                leading: Icon(exists == null
                    ? Icons.error
                    : exists
                        ? Icons.check
                        : Icons.help_outline),
                title: Text(barcode),
                subtitle: Text(exists == null
                    ? appLocalizations
                        .dev_preferences_export_history_progress_error
                    : exists
                        ? appLocalizations
                            .dev_preferences_export_history_progress_found
                        : appLocalizations
                            .dev_preferences_export_history_progress_not_found),
              ),
            );
          }
          showDialog<void>(
            context: context,
            builder: (BuildContext context) => AlertDialog(
              title: Text(
                appLocalizations.dev_preferences_export_history_dialog_title,
              ),
              content: SizedBox(
                height: 400,
                width: 300,
                child: ListView(children: children),
              ),
              actions: <Widget>[
                ElevatedButton(
                  child: Text(
                    appLocalizations.dev_preferences_button_positive,
                  ),
                  onPressed: () => Navigator.pop(context),
                ),
              ],
            ),
          );
        },
      ),
      ListTile(
        title: Text(
          appLocalizations.dev_preferences_import_history_title,
        ),
        subtitle: Text(
          appLocalizations.dev_preferences_import_history_subtitle,
        ),
        onTap: () async {
          final LocalDatabase localDatabase = context.read<LocalDatabase>();
          await ProductListImportExport().import(
            ProductListImportExport.TMP_IMPORT,
            localDatabase,
          );
          //ignore: use_build_context_synchronously
          ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(
              content: Text(
                appLocalizations
                    .dev_preferences_import_history_result_success,
              ),
            ),
          );
          localDatabase.notifyListeners();
        },
      ),
      ListTile(
        title: Text(
          appLocalizations.dev_mode_matching_mode_title,
        ),
        subtitle: Text(
          appLocalizations.dev_mode_matching_mode_subtitle(
            (userPreferences.getFlag(userPreferencesFlagStrongMatching) ??
                    false)
                ? appLocalizations.dev_mode_matching_mode_value_strong
                : appLocalizations.dev_mode_matching_mode_value_lenient,
          ),
        ),
        onTap: () async {
          await userPreferences.setFlag(
              userPreferencesFlagStrongMatching,
              !(userPreferences.getFlag(userPreferencesFlagStrongMatching) ??
                  false));
          setState(() {});
        },
      ),
      ListTile(
        title: Text(
          appLocalizations.dev_mode_scan_mode_title,
        ),
        subtitle: Text(
          appLocalizations
              .dev_mode_scan_mode_subtitle(DevModeScanModeExtension.fromIndex(
            userPreferences.getDevModeIndex(
              userPreferencesEnumScanMode,
            ),
          ).localizedLabel(appLocalizations)),
        ),
        onTap: () async {
          final DevModeScanMode? scanMode = await showDialog<DevModeScanMode>(
            context: context,
            builder: (BuildContext context) => AlertDialog(
              title: Text(
                appLocalizations.dev_mode_scan_mode_dialog_title,
              ),
              content: SizedBox(
                height: 400,
                width: 300,
                child: ListView.builder(
                  itemCount: DevModeScanMode.values.length,
                  itemBuilder: (final BuildContext context, final int index) {
                    final DevModeScanMode scanMode =
                        DevModeScanMode.values[index];
                    return ListTile(
                      title: Text(scanMode.localizedLabel(appLocalizations)),
                      onTap: () => Navigator.pop(context, scanMode),
                    );
                  },
                ),
              ),
              actions: <Widget>[
                ElevatedButton(
                  child: Text(
                    appLocalizations.dev_preferences_button_negative,
                  ),
                  onPressed: () => Navigator.pop(context),
                ),
              ],
            ),
          );
          if (scanMode != null) {
            await userPreferences.setDevModeIndex(
              userPreferencesEnumScanMode,
              scanMode.index,
            );
            setState(() {});
          }
        },
      ),
      SwitchListTile(
        title: Text(
          appLocalizations.dev_mode_hide_ecoscore_title,
        ),
        value: userPreferences
            .getExcludedAttributeIds()
            .contains(Attribute.ATTRIBUTE_ECOSCORE),
        onChanged: (bool value) async {
          const String tag = Attribute.ATTRIBUTE_ECOSCORE;
          final List<String> list = userPreferences.getExcludedAttributeIds();
          list.removeWhere((final String element) => element == tag);
          if (value) {
            list.add(tag);
          }
          await userPreferences.setExcludedAttributeIds(list);
          setState(() {});
        },
      ),
      ListTile(
        leading: const Icon(Icons.language),
        title: DropdownButton<String>(
          value: userPreferences.appLanguageCode ??
              Localizations.localeOf(context).toString(),
          elevation: 16,
          isExpanded: true,
          onChanged: (String? languageCode) async {
            await userPreferences.setAppLanguageCode(languageCode);
            setState(() {});
          },
          items: AppLocalizations.supportedLocales.map((Locale locale) {
            final String localeString = locale.toString();
            return DropdownMenuItem<String>(
              value: localeString,
              child: Text(localeString),
            );
          }).toList(),
        ),
      ),
      ListTile(
        title: Text(
          appLocalizations.dev_preferences_reset_app_language,
        ),
        onTap: () async {
          await userPreferences.setAppLanguageCode(null);
          setState(() {});
        },
      ),
    ];