mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-09-18 21:38:48 +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!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -259,19 +259,19 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
|
||||
// Upload a new logo
|
||||
SettingsTile(
|
||||
title: tr("Upload a new logo"),
|
||||
onPressed: (_) => _uploadNewLogo,
|
||||
onPressed: (_) => _uploadNewLogo(),
|
||||
),
|
||||
|
||||
// Generate a new random logo
|
||||
SettingsTile(
|
||||
title: tr("Generate a new random logo"),
|
||||
onPressed: (_) => _generateRandomLogo,
|
||||
onPressed: (_) => _generateRandomLogo(),
|
||||
),
|
||||
|
||||
// Delete current logo
|
||||
SettingsTile(
|
||||
title: tr("Delete logo"),
|
||||
onPressed: (_) => _deleteLogo,
|
||||
onPressed: (_) => _deleteLogo(),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -281,8 +281,8 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
|
||||
void _uploadNewLogo() async {
|
||||
try {
|
||||
final logo = await pickImage(context);
|
||||
final bytes = await logo.readAsBytes();
|
||||
await _doUploadLogo(bytes);
|
||||
if (logo == null) return;
|
||||
await _doUploadLogo(logo.bytes);
|
||||
} catch (e, stack) {
|
||||
print("Could not upload new logo! $e\n$stack");
|
||||
showSimpleSnack(context, tr("Could not upload new logo!"));
|
||||
@@ -328,7 +328,7 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
|
||||
tiles: [
|
||||
SettingsTile(
|
||||
title: tr("Delete group"),
|
||||
onPressed: (_) => _deleteGroup,
|
||||
onPressed: (_) => _deleteGroup(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
@@ -26,9 +26,11 @@ import 'package:comunic/utils/post_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../models/api_request.dart';
|
||||
import '../../utils/log_utils.dart';
|
||||
|
||||
/// Single posts tile
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
@@ -77,7 +79,7 @@ class _PostTileState extends State<PostTile> {
|
||||
|
||||
// Class members
|
||||
TextEditingController _commentController = TextEditingController();
|
||||
PickedFile _commentImage;
|
||||
BytesFile _commentImage;
|
||||
bool _submitting = false;
|
||||
int _maxNumberOfCommentToShow = 10;
|
||||
|
||||
@@ -493,11 +495,16 @@ class _PostTileState extends State<PostTile> {
|
||||
return;
|
||||
}
|
||||
|
||||
// Pick a new image
|
||||
final newImage = await pickImage(context);
|
||||
setState(() {
|
||||
_commentImage = newImage;
|
||||
});
|
||||
try {
|
||||
// Pick a new image
|
||||
final newImage = await pickImage(context);
|
||||
setState(() {
|
||||
_commentImage = newImage;
|
||||
});
|
||||
} catch (e, s) {
|
||||
logError(e, s);
|
||||
snack(context, tr("Failed to choose an image!"));
|
||||
}
|
||||
}
|
||||
|
||||
/// Submit comment entered by the user
|
||||
|
@@ -13,7 +13,10 @@ import 'package:comunic/utils/post_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import '../../models/api_request.dart';
|
||||
import '../../utils/log_utils.dart';
|
||||
import '../../utils/ui_utils.dart';
|
||||
|
||||
/// Widget that allows to create posts
|
||||
///
|
||||
@@ -48,7 +51,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
bool _isCreating = false;
|
||||
final TextEditingController _postTextController = TextEditingController();
|
||||
PostVisibilityLevel _postVisibilityLevel;
|
||||
PickedFile _postImage;
|
||||
BytesFile _postImage;
|
||||
String _postURL;
|
||||
List<int> _postPDF;
|
||||
DateTime _timeEnd;
|
||||
@@ -239,15 +242,20 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
|
||||
/// Pick an image for the new post
|
||||
Future<void> _pickImageForPost() async {
|
||||
final image = await pickImage(context);
|
||||
try {
|
||||
final image = await pickImage(context);
|
||||
|
||||
if (image == null) return;
|
||||
if (image == null) return;
|
||||
|
||||
_resetPostSelection();
|
||||
_resetPostSelection();
|
||||
|
||||
setState(() {
|
||||
this._postImage = image;
|
||||
});
|
||||
setState(() {
|
||||
this._postImage = image;
|
||||
});
|
||||
} catch (e, s) {
|
||||
logError(e, s);
|
||||
snack(context, tr("Failed to pick image for post!"));
|
||||
}
|
||||
}
|
||||
|
||||
/// Choose a new URL for the post
|
||||
|
Reference in New Issue
Block a user