mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Can generate a random logo for the group
This commit is contained in:
		@@ -16,6 +16,8 @@ import 'package:comunic/utils/input_utils.dart';
 | 
				
			|||||||
import 'package:comunic/utils/intl_utils.dart';
 | 
					import 'package:comunic/utils/intl_utils.dart';
 | 
				
			||||||
import 'package:comunic/utils/ui_utils.dart';
 | 
					import 'package:comunic/utils/ui_utils.dart';
 | 
				
			||||||
import 'package:flutter/material.dart';
 | 
					import 'package:flutter/material.dart';
 | 
				
			||||||
 | 
					import 'package:identicon/identicon.dart';
 | 
				
			||||||
 | 
					import 'package:random_string/random_string.dart';
 | 
				
			||||||
import 'package:settings_ui/settings_ui.dart';
 | 
					import 'package:settings_ui/settings_ui.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Groups settings screen
 | 
					/// Groups settings screen
 | 
				
			||||||
@@ -254,11 +256,17 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
 | 
				
			|||||||
          title: tr("Upload a new logo"),
 | 
					          title: tr("Upload a new logo"),
 | 
				
			||||||
          onTap: _uploadNewLogo,
 | 
					          onTap: _uploadNewLogo,
 | 
				
			||||||
        ),
 | 
					        ),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Generate a new random logo
 | 
				
			||||||
 | 
					        SettingsTile(
 | 
				
			||||||
 | 
					          title: tr("Generate a new random logo"),
 | 
				
			||||||
 | 
					          onTap: _generateRandomLogo,
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
      ],
 | 
					      ],
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Upload a new logo for the group
 | 
					  /// Upload a new logo for the group
 | 
				
			||||||
  void _uploadNewLogo() async {
 | 
					  void _uploadNewLogo() async {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      final logo = await pickImage(context);
 | 
					      final logo = await pickImage(context);
 | 
				
			||||||
@@ -270,6 +278,18 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /// Generate a new random logo for the group
 | 
				
			||||||
 | 
					  void _generateRandomLogo() async {
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      final newLogo =
 | 
				
			||||||
 | 
					          Identicon(rows: 10, cols: 10).generate(randomString(20), size: 100);
 | 
				
			||||||
 | 
					      await _doUploadLogo(newLogo);
 | 
				
			||||||
 | 
					    } catch (e, stack) {
 | 
				
			||||||
 | 
					      print("Could not generate new logo! $e\n$stack");
 | 
				
			||||||
 | 
					      showSimpleSnack(context, tr("Could not generate new random logo!"));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Future<void> _doUploadLogo(Uint8List bytes) async {
 | 
					  Future<void> _doUploadLogo(Uint8List bytes) async {
 | 
				
			||||||
    await GroupsHelper.uploadNewLogo(_groupSettings.id, bytes);
 | 
					    await GroupsHelper.uploadNewLogo(_groupSettings.id, bytes);
 | 
				
			||||||
    _key.currentState.refresh();
 | 
					    _key.currentState.refresh();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user