1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 04:49:21 +00:00

Can change account image from tour

This commit is contained in:
Pierre HUBERT 2021-04-17 18:33:08 +02:00
parent 7c8a82566f
commit 899270961a
2 changed files with 62 additions and 22 deletions

View File

@ -1,5 +1,11 @@
import 'package:comunic/helpers/preferences_helper.dart'; import 'package:comunic/helpers/preferences_helper.dart';
import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/routes/settings/account_image_settings.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
import 'package:comunic/ui/widgets/login_routes_theme.dart'; import 'package:comunic/ui/widgets/login_routes_theme.dart';
import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -18,8 +24,31 @@ class TourRoute extends StatefulWidget {
} }
class _TourRouteState extends State<TourRoute> { class _TourRouteState extends State<TourRoute> {
final key = GlobalKey<AsyncScreenWidgetState>();
User currUser;
int _defaultIndex = 0;
Future<void> _init() async {
currUser =
await UsersHelper().getSingleWithThrow(userID(), forceDownload: true);
}
List<Widget> get _list => [ List<Widget> get _list => [
_FirstPane(), _FirstPane(),
_PresentationPane(
iconWidget: AccountImageWidget(user: currUser, width: 50),
title: tr("Account image"),
text: tr(
"Account image allow to quickly recognize people.\n\nYou can decide to define one now!"),
actionTitle: tr("Upload an account image"),
onActionTap: (ctx) async {
await uploadNewAccountImage(context);
_defaultIndex = DefaultTabController.of(ctx).index;
await key.currentState.refresh();
},
),
_PresentationPane( _PresentationPane(
icon: Icons.group_add, icon: Icons.group_add,
title: tr("Friends"), title: tr("Friends"),
@ -51,11 +80,16 @@ class _TourRouteState extends State<TourRoute> {
Widget build(BuildContext context) => LoginRoutesTheme( Widget build(BuildContext context) => LoginRoutesTheme(
child: Scaffold( child: Scaffold(
body: SafeArea( body: SafeArea(
child: DefaultTextStyle( child: AsyncScreenWidget(
style: TextStyle(color: Colors.white), key: key,
child: DefaultTabController( onReload: _init,
errorMessage: tr("Failed to load tour!"),
onBuild: () => DefaultTabController(
initialIndex: _defaultIndex,
length: _list.length, length: _list.length,
child: _RouteBody(panes: _list), child: _RouteBody(
panes: _list,
),
), ),
), ),
), ),
@ -128,19 +162,21 @@ class __RouteBodyState extends State<_RouteBody> {
class _PresentationPane extends StatelessWidget { class _PresentationPane extends StatelessWidget {
final IconData icon; final IconData icon;
final Widget iconWidget;
final String title; final String title;
final String text; final String text;
final String actionTitle; final String actionTitle;
final Function() onActionTap; final Function(BuildContext) onActionTap;
const _PresentationPane({ const _PresentationPane({
Key key, Key key,
@required this.icon, this.icon,
this.iconWidget,
@required this.title, @required this.title,
@required this.text, @required this.text,
this.actionTitle, this.actionTitle,
this.onActionTap, this.onActionTap,
}) : assert(icon != null), }) : assert(icon != null || iconWidget != null),
assert(title != null), assert(title != null),
assert(text != null), assert(text != null),
super(key: key); super(key: key);
@ -151,7 +187,7 @@ class _PresentationPane extends StatelessWidget {
Widget build(BuildContext context) => Column( Widget build(BuildContext context) => Column(
children: <Widget>[ children: <Widget>[
Spacer(flex: 3), Spacer(flex: 3),
Icon(icon, color: Colors.white, size: 50), icon != null ? Icon(icon, color: Colors.white, size: 50) : iconWidget,
Spacer(flex: 1), Spacer(flex: 1),
Text( Text(
title, title,
@ -162,7 +198,7 @@ class _PresentationPane extends StatelessWidget {
Spacer(flex: 1), Spacer(flex: 1),
_hasAction _hasAction
? OutlinedButton( ? OutlinedButton(
onPressed: onActionTap, onPressed: () => onActionTap(context),
child: Text( child: Text(
actionTitle, actionTitle,
style: TextStyle(color: Colors.white), style: TextStyle(color: Colors.white),
@ -195,8 +231,8 @@ class _FirstPane extends StatelessWidget {
_FixedSizeTextArea(tr( _FixedSizeTextArea(tr(
"Welcome to Comunic, the social network that respect your privacy !")), "Welcome to Comunic, the social network that respect your privacy !")),
Spacer(flex: 1), Spacer(flex: 1),
_FixedSizeTextArea( _FixedSizeTextArea(tr(
tr("Let us present you some of the features of the network...")), "Let's configure a few things and present you some features of the network...")),
Spacer(flex: 3), Spacer(flex: 3),
], ],
); );

View File

@ -160,17 +160,7 @@ class _AccountImageSettingsScreenState
/// Upload a new account image /// Upload a new account image
void _uploadAccountImage() async { void _uploadAccountImage() async {
try { await uploadNewAccountImage(context);
final image = await pickImage(context,
aspectRatio: CropAspectRatio(ratioX: 5, ratioY: 5));
if (image == null) return;
await SettingsHelper.uploadAccountImage(image);
} catch (e, s) {
logError(e, s);
snack(context, tr("Failed to upload new account image!"));
}
_key.currentState.refresh(); _key.currentState.refresh();
} }
@ -203,3 +193,17 @@ class _AccountImageSettingsScreenState
_key.currentState.refresh(); _key.currentState.refresh();
} }
} }
Future<void> uploadNewAccountImage(BuildContext context) async {
try {
final image = await pickImage(context,
aspectRatio: CropAspectRatio(ratioX: 5, ratioY: 5));
if (image == null) return;
await SettingsHelper.uploadAccountImage(image);
} catch (e, s) {
logError(e, s);
snack(context, tr("Failed to upload new account image!"));
}
}