mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Start to update general settings
This commit is contained in:
		
							
								
								
									
										60
									
								
								lib/ui/widgets/settings/text_settings_edit_tile.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								lib/ui/widgets/settings/text_settings_edit_tile.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
			
		||||
import 'package:comunic/ui/dialogs/single_input_dialog.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:settings_ui/settings_ui.dart';
 | 
			
		||||
 | 
			
		||||
/// Text edit settings tile
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
bool _defaultCheck(String s) => s.isNotEmpty;
 | 
			
		||||
 | 
			
		||||
class TextEditSettingsTile extends SettingsTile {
 | 
			
		||||
  final String title;
 | 
			
		||||
  final String currValue;
 | 
			
		||||
  final void Function(String) onChanged;
 | 
			
		||||
  final bool Function(String) checkInput;
 | 
			
		||||
  final bool allowEmptyValues;
 | 
			
		||||
 | 
			
		||||
  bool get readOnly => onChanged == null;
 | 
			
		||||
 | 
			
		||||
  const TextEditSettingsTile({
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.title,
 | 
			
		||||
    @required this.currValue,
 | 
			
		||||
    @required this.onChanged,
 | 
			
		||||
    this.checkInput = _defaultCheck,
 | 
			
		||||
    this.allowEmptyValues = false,
 | 
			
		||||
  })  : assert(title != null),
 | 
			
		||||
        assert(currValue != null),
 | 
			
		||||
        assert(checkInput != null),
 | 
			
		||||
        assert(allowEmptyValues != null);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return SettingsTile(
 | 
			
		||||
      title: title,
 | 
			
		||||
      subtitle: currValue,
 | 
			
		||||
      onTap: readOnly ? null : () => _changeValue(context),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  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!"),
 | 
			
		||||
        canBeEmpty: allowEmptyValues,
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (value == null) return;
 | 
			
		||||
 | 
			
		||||
    onChanged(value);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user