mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Can change group visibility
This commit is contained in:
		
							
								
								
									
										46
									
								
								lib/ui/widgets/settings/multi_choices_settings_tile.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								lib/ui/widgets/settings/multi_choices_settings_tile.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
import 'package:comunic/ui/dialogs/multi_choices_dialog.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:settings_ui/settings_ui.dart';
 | 
			
		||||
 | 
			
		||||
/// Multiple choices settings tile
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
 | 
			
		||||
class MultiChoicesSettingsTile<T> extends SettingsTile {
 | 
			
		||||
  final String title;
 | 
			
		||||
  final List<MultiChoiceEntry<T>> choices;
 | 
			
		||||
  final T currentValue;
 | 
			
		||||
  final Function(T) onChanged;
 | 
			
		||||
 | 
			
		||||
  const MultiChoicesSettingsTile({
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.title,
 | 
			
		||||
    @required this.choices,
 | 
			
		||||
    @required this.currentValue,
 | 
			
		||||
    @required this.onChanged,
 | 
			
		||||
  })  : assert(title != null),
 | 
			
		||||
        assert(choices != null),
 | 
			
		||||
        assert(currentValue != null),
 | 
			
		||||
        assert(onChanged != null);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return SettingsTile(
 | 
			
		||||
      title: title,
 | 
			
		||||
      subtitle: choices.firstWhere((f) => f.id == currentValue).title,
 | 
			
		||||
      onTap: () => _changeValue(context),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// When the user request to change the current value
 | 
			
		||||
  void _changeValue(BuildContext context) async {
 | 
			
		||||
    final newChoice = await showMultiChoicesDialog(
 | 
			
		||||
      context: context,
 | 
			
		||||
      choices: choices,
 | 
			
		||||
      defaultChoice: currentValue,
 | 
			
		||||
      title: title,
 | 
			
		||||
    );
 | 
			
		||||
    if (newChoice == null) return;
 | 
			
		||||
    onChanged(newChoice);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user