# settingsWidget method

Widget settingsWidget(

1. BuildContext context,
2. {String title = '',
3. String name = '',
4. String tooltip = '',
5. dynamic suffix = 0,
6. String placeholder = '',
7. SettingsType type = SettingsType.text,
8. String sizePostfix = '',
9. int sizeMax = 0,
10. int sizeMin = 0}

)

## Implementation

    Widget settingsWidget(
      BuildContext context, {
      String title = '',
      String name = '',
      String tooltip = '',
      dynamic suffix = 0,
      String placeholder = '',
      SettingsType type = SettingsType.text,
      String sizePostfix = '',
      int sizeMax = 0,
      int sizeMin = 0,
    }) {
      if (name.isEmpty) {
        name = title;
      }
      if (_settings[name] == null) {
        _settings[name] = TextEditingController(text: '');
      }
      // First letter to capital
      title = title.replaceFirst(title[0], title[0].toUpperCase());
      return Padding(
        padding: const EdgeInsets.all(8.0),
        child: Expander(
          header:
              Text(title, style: const TextStyle(fontWeight: FontWeight.w500)),
          content: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(tooltip),
              Padding(
                padding: const EdgeInsets.only(top: 8.0),
                child: Builder(
                  builder: (context) {
                    double size = double.tryParse(
                            _settings[name]!.text.replaceAll(sizePostfix, '')) ??
                        sizeMin.toDouble();
                    switch (type) {
                      case SettingsType.text:
                        return TextBox(
                          controller: _settings[name],
                          placeholder: placeholder,
                          suffix: suffix != 0 ? suffix : Container(),
                        );
                      case SettingsType.bool:
                        return ToggleSwitch(
                            checked: _settings[name]!.text == 'true',
                            onChanged: (value) {
                              _settings[name]!.text = value ? 'true' : 'false';
                              setState(() {
                                _settings = _settings;
                              });
                            },
                            content: Text(_settings[name]!.text));
                      case SettingsType.size:
                        if (_settings[name] == null) {
                          _settings[name] = TextEditingController(
                              text: sizeMin.toDouble().toString());
                        }
                        return SizedBox(
                            width: MediaQuery.of(context).size.width,
                            child: Slider(
                                min: sizeMin.toDouble(),
                                max: sizeMax.toDouble(),
                                //divisions: 1,
                                value: size,
                                style: SliderThemeData(
                                  labelBackgroundColor: AppTheme().color,
                                ),
                                onChanged: (value) {
                                  setState(() {
                                    _settings[name]!.text =
                                        value.toInt().toString() + sizePostfix;
                                  });
                                },
                                label: _settings[name]!.text));
                      default:
                        return TextBox(
                          controller: _settings[name],
                          placeholder: placeholder,
                          suffix: suffix != 0 ? suffix : Container(),
                        );
                    }
                  },
                ),
              ),
            ],
          ),
        ),
      );
    }