mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Can upload new account image
This commit is contained in:
@ -1,11 +1,18 @@
|
||||
import 'package:comunic/helpers/settings_helper.dart';
|
||||
import 'package:comunic/models/account_image_settings.dart';
|
||||
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
||||
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
||||
import 'package:comunic/utils/files_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:settings_ui/settings_ui.dart';
|
||||
|
||||
/// Account image settings section
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
class AccountImageSettings extends StatelessWidget {
|
||||
class AccountImageSettingsScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -17,15 +24,75 @@ class AccountImageSettings extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class _AccountImageSettingsBody extends StatefulWidget {
|
||||
@override
|
||||
__AccountImageSettingsBodyState createState() => __AccountImageSettingsBodyState();
|
||||
__AccountImageSettingsBodyState createState() =>
|
||||
__AccountImageSettingsBodyState();
|
||||
}
|
||||
|
||||
class __AccountImageSettingsBodyState extends State<_AccountImageSettingsBody> {
|
||||
AccountImageSettings _settings;
|
||||
|
||||
final _key = GlobalKey<AsyncScreenWidgetState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container();
|
||||
return AsyncScreenWidget(
|
||||
key: _key,
|
||||
onReload: () async =>
|
||||
_settings = await SettingsHelper.getAccountImageSettings(),
|
||||
onBuild: () => _buildLayout(),
|
||||
errorMessage: tr("Could not get account image settings!"),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLayout() {
|
||||
return SettingsList(
|
||||
sections: [
|
||||
SettingsSection(
|
||||
title: tr("General"),
|
||||
tiles: _settings.hasImage
|
||||
? _buildHasAccountImageTiles()
|
||||
: _buildNoAccountImageTiles(),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// When user has no account image yet
|
||||
List<SettingsTile> _buildNoAccountImageTiles() {}
|
||||
|
||||
/// When the user has an account image
|
||||
List<SettingsTile> _buildHasAccountImageTiles() {
|
||||
return [
|
||||
// Current account image (if any)
|
||||
SettingsTile(
|
||||
title: tr("Current account image"),
|
||||
leading: NetworkImageWidget(
|
||||
url: _settings.imageURL,
|
||||
width: 40,
|
||||
),
|
||||
),
|
||||
SettingsTile(
|
||||
title: tr("Upload new account image"),
|
||||
onTap: () => _uploadAccountImage(),
|
||||
),
|
||||
SettingsTile(title: tr("Change account image visibility")),
|
||||
SettingsTile(title: tr("Delete account image"))
|
||||
];
|
||||
}
|
||||
|
||||
/// Upload a new account image
|
||||
void _uploadAccountImage() async {
|
||||
final image = await pickImage(context);
|
||||
|
||||
if (image == null) return;
|
||||
|
||||
if (!await SettingsHelper.uploadAccountImage(image)) {
|
||||
showSimpleSnack(context, tr("Could not upload your account image!"));
|
||||
return;
|
||||
}
|
||||
|
||||
_key.currentState.refresh();
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class __AccountSettingsBodyState extends State<_AccountSettingsBody> {
|
||||
title: tr("Account image"),
|
||||
subtitle: tr("Customize your account image"),
|
||||
leading: Icon(Icons.account_circle),
|
||||
onTap: () => _openSection(AccountImageSettings()),
|
||||
onTap: () => _openSection(AccountImageSettingsScreen()),
|
||||
)
|
||||
],
|
||||
)
|
||||
|
Reference in New Issue
Block a user