mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can change account image from tour
This commit is contained in:
		@@ -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<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 => [
 | 
			
		||||
        _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<TourRoute> {
 | 
			
		||||
  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: <Widget>[
 | 
			
		||||
          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),
 | 
			
		||||
      ],
 | 
			
		||||
    );
 | 
			
		||||
 
 | 
			
		||||
@@ -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<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!"));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user