diff --git a/lib/ui/routes/TourRoute.dart b/lib/ui/routes/TourRoute.dart index 0e650eb..d0f2539 100644 --- a/lib/ui/routes/TourRoute.dart +++ b/lib/ui/routes/TourRoute.dart @@ -1,5 +1,11 @@ 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/utils/account_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:flutter/material.dart'; @@ -18,8 +24,31 @@ class TourRoute extends StatefulWidget { } class _TourRouteState extends State { + final key = GlobalKey(); + + User currUser; + + int _defaultIndex = 0; + + Future _init() async { + currUser = + await UsersHelper().getSingleWithThrow(userID(), forceDownload: true); + } + List get _list => [ _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( icon: Icons.group_add, title: tr("Friends"), @@ -51,11 +80,16 @@ class _TourRouteState extends State { Widget build(BuildContext context) => LoginRoutesTheme( child: Scaffold( body: SafeArea( - child: DefaultTextStyle( - style: TextStyle(color: Colors.white), - child: DefaultTabController( + child: AsyncScreenWidget( + key: key, + onReload: _init, + errorMessage: tr("Failed to load tour!"), + onBuild: () => DefaultTabController( + initialIndex: _defaultIndex, length: _list.length, - child: _RouteBody(panes: _list), + child: _RouteBody( + panes: _list, + ), ), ), ), @@ -128,19 +162,21 @@ class __RouteBodyState extends State<_RouteBody> { class _PresentationPane extends StatelessWidget { final IconData icon; + final Widget iconWidget; final String title; final String text; final String actionTitle; - final Function() onActionTap; + final Function(BuildContext) onActionTap; const _PresentationPane({ Key key, - @required this.icon, + this.icon, + this.iconWidget, @required this.title, @required this.text, this.actionTitle, this.onActionTap, - }) : assert(icon != null), + }) : assert(icon != null || iconWidget != null), assert(title != null), assert(text != null), super(key: key); @@ -151,7 +187,7 @@ class _PresentationPane extends StatelessWidget { Widget build(BuildContext context) => Column( children: [ Spacer(flex: 3), - Icon(icon, color: Colors.white, size: 50), + icon != null ? Icon(icon, color: Colors.white, size: 50) : iconWidget, Spacer(flex: 1), Text( title, @@ -162,7 +198,7 @@ class _PresentationPane extends StatelessWidget { Spacer(flex: 1), _hasAction ? OutlinedButton( - onPressed: onActionTap, + onPressed: () => onActionTap(context), child: Text( actionTitle, style: TextStyle(color: Colors.white), @@ -195,8 +231,8 @@ class _FirstPane extends StatelessWidget { _FixedSizeTextArea(tr( "Welcome to Comunic, the social network that respect your privacy !")), Spacer(flex: 1), - _FixedSizeTextArea( - tr("Let us present you some of the features of the network...")), + _FixedSizeTextArea(tr( + "Let's configure a few things and present you some features of the network...")), Spacer(flex: 3), ], ); diff --git a/lib/ui/routes/settings/account_image_settings.dart b/lib/ui/routes/settings/account_image_settings.dart index 53cccab..fd10b53 100644 --- a/lib/ui/routes/settings/account_image_settings.dart +++ b/lib/ui/routes/settings/account_image_settings.dart @@ -160,17 +160,7 @@ class _AccountImageSettingsScreenState /// Upload a new account image void _uploadAccountImage() 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!")); - } + await uploadNewAccountImage(context); _key.currentState.refresh(); } @@ -203,3 +193,17 @@ class _AccountImageSettingsScreenState _key.currentState.refresh(); } } + +Future 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!")); + } +}