bottomButtonRow method Null safety

Row bottomButtonRow()

Implementation

Row bottomButtonRow() {
  return Row(
    mainAxisSize: MainAxisSize.max,
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: [
      showInput
          ? Button(
              style: ButtonStyle(
                  padding: ButtonState.all<EdgeInsets>(const EdgeInsets.only(
                      top: 8.0, bottom: 8.0, left: 20.0, right: 20.0))),
              onPressed: () {
                setState(() {
                  showInput = false;
                });
              },
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  const Icon(FluentIcons.chrome_close),
                  const SizedBox(
                    width: 10.0,
                  ),
                  Text('close-text'.i18n()),
                ],
              ),
            )
          : Container(),
      Button(
        style: ButtonStyle(
            padding: ButtonState.all<EdgeInsets>(const EdgeInsets.only(
                top: 8.0, bottom: 8.0, left: 20.0, right: 20.0))),
        onPressed: () {
          if (!showInput) {
            setState(() {
              showInput = true;
            });
          } else if (nameController.text.isNotEmpty &&
              contentController.text.isNotEmpty) {
            plausible.event(page: 'add_action');

            // Load data
            List<String>? titles = prefs.getStringList('quickSettingsTitles');
            titles ??= [];
            List<String>? contents =
                prefs.getStringList('quickSettingsContents');
            contents ??= [];

            // Override if already exists
            if (titles.contains(nameController.text)) {
              int pos = titles.indexOf(nameController.text);
              titles.removeAt(pos);
              contents.removeAt(pos);
            }

            // Add title to list
            titles.add(nameController.text);
            prefs.setStringList('quickSettingsTitles', titles);

            // Add content to list
            contents.add(contentController.text);
            prefs.setStringList('quickSettingsContents', contents);

            setState(() {
              showInput = false;
            });
          } else {
            // Error
          }
        },
        child: Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            showInput
                ? Text('save-text'.i18n())
                : Text('addquickaction-text'.i18n()),
            const SizedBox(
              width: 10.0,
            ),
            Icon(
              showInput ? FluentIcons.save : FluentIcons.settings_add,
              size: 15.0,
            ),
          ],
        ),
      ),
    ],
  );
}