1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-28 13:58:51 +00:00
comunicmobile/lib/ui/widgets/settings/text_settings_edit_tile.dart

66 lines
1.7 KiB
Dart
Raw Normal View History

2020-04-27 11:27:37 +00:00
import 'package:comunic/ui/dialogs/single_input_dialog.dart';
2021-04-27 07:44:11 +00:00
import 'package:comunic/utils/flutter_utils.dart';
2020-04-27 11:27:37 +00:00
import 'package:comunic/utils/intl_utils.dart';
2021-04-27 07:44:11 +00:00
import 'package:comunic/utils/string_utils.dart';
2020-04-27 11:27:37 +00:00
import 'package:flutter/material.dart';
2021-12-28 14:23:08 +00:00
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
2020-04-27 11:27:37 +00:00
/// Text edit settings tile
///
/// @author Pierre HUBERT
bool _defaultCheck(String s) => s.isNotEmpty;
class TextEditSettingsTile extends SettingsTile {
final String title;
final String currValue;
2022-03-11 15:36:42 +00:00
final void Function(String)? onChanged;
2020-04-27 11:27:37 +00:00
final bool Function(String) checkInput;
final bool allowEmptyValues;
2020-04-27 17:21:30 +00:00
final int maxLines;
final int? maxLength;
2020-04-27 11:27:37 +00:00
bool get readOnly => onChanged == null;
2021-12-28 14:23:08 +00:00
TextEditSettingsTile({
Key? key,
required this.title,
required this.currValue,
required this.onChanged,
2020-04-27 11:27:37 +00:00
this.checkInput = _defaultCheck,
this.allowEmptyValues = false,
2020-04-27 17:21:30 +00:00
this.maxLength,
this.maxLines = 1,
2022-03-11 15:36:42 +00:00
});
2020-04-27 11:27:37 +00:00
@override
Widget build(BuildContext context) {
return SettingsTile(
title: title,
2021-12-28 14:23:08 +00:00
subtitle: isIOS ? reduceString(currValue, 20) : currValue,
2021-02-12 21:36:22 +00:00
onPressed: readOnly ? null : (_) => _changeValue(context),
2020-04-27 11:27:37 +00:00
);
}
void _changeValue(BuildContext context) async {
final value = await showDialog<String>(
context: context,
builder: (b) => SingleInputDialog(
title: title,
icon: null,
initialValue: currValue,
label: title,
checkInput: checkInput,
errorMessage: tr("Invalid value!")!,
2020-04-27 11:27:37 +00:00
canBeEmpty: allowEmptyValues,
2020-04-27 17:21:30 +00:00
maxLines: maxLines,
maxLength: maxLength,
2020-04-27 11:27:37 +00:00
),
);
if (value == null) return;
2022-03-11 15:36:42 +00:00
onChanged!(value);
2020-04-27 11:27:37 +00:00
}
}