mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Simplify image picking code
This commit is contained in:
		@@ -15,6 +15,9 @@ import 'package:identicon/identicon.dart';
 | 
			
		||||
import 'package:random_string/random_string.dart';
 | 
			
		||||
import 'package:settings_ui/settings_ui.dart';
 | 
			
		||||
 | 
			
		||||
import '../../../utils/log_utils.dart';
 | 
			
		||||
import '../../../utils/ui_utils.dart';
 | 
			
		||||
 | 
			
		||||
/// Account image settings section
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
@@ -156,15 +159,16 @@ class _AccountImageSettingsScreenState
 | 
			
		||||
 | 
			
		||||
  /// Upload a new account image
 | 
			
		||||
  void _uploadAccountImage() async {
 | 
			
		||||
    final image = await pickImage(context);
 | 
			
		||||
    try {
 | 
			
		||||
      final image = await pickImage(context);
 | 
			
		||||
 | 
			
		||||
    if (image == null) return;
 | 
			
		||||
      if (image == null) return;
 | 
			
		||||
 | 
			
		||||
    if (!await SettingsHelper.uploadAccountImage(image)) {
 | 
			
		||||
      showSimpleSnack(context, tr("Could not upload your account image!"));
 | 
			
		||||
      return;
 | 
			
		||||
      await SettingsHelper.uploadAccountImage(image);
 | 
			
		||||
    } catch (e, s) {
 | 
			
		||||
      logError(e, s);
 | 
			
		||||
      snack(context, tr("Failed to upload new account image!"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    _key.currentState.refresh();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,9 @@ import 'package:comunic/utils/input_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/ui_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:image_picker/image_picker.dart';
 | 
			
		||||
 | 
			
		||||
import '../../../models/api_request.dart';
 | 
			
		||||
import '../../../utils/ui_utils.dart';
 | 
			
		||||
 | 
			
		||||
/// Emojies account settings
 | 
			
		||||
///
 | 
			
		||||
@@ -136,7 +138,7 @@ class _NewCustomEmojiDialog extends StatefulWidget {
 | 
			
		||||
 | 
			
		||||
class _NewCustomEmojiDialogState extends State<_NewCustomEmojiDialog> {
 | 
			
		||||
  final _controller = TextEditingController();
 | 
			
		||||
  PickedFile _file;
 | 
			
		||||
  BytesFile _file;
 | 
			
		||||
 | 
			
		||||
  bool get _hasImage => _file != null;
 | 
			
		||||
 | 
			
		||||
@@ -209,6 +211,7 @@ class _NewCustomEmojiDialogState extends State<_NewCustomEmojiDialog> {
 | 
			
		||||
      });
 | 
			
		||||
    } catch (e, stack) {
 | 
			
		||||
      print("Could not pick an image! $e\n$stack");
 | 
			
		||||
      snack(context, tr("Failed to pick an image!"));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user