mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Add user profile route
This commit is contained in:
		
							
								
								
									
										175
									
								
								lib/forez/ui/routes/forez_member_profile_route.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										175
									
								
								lib/forez/ui/routes/forez_member_profile_route.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,175 @@
 | 
			
		||||
import 'package:cached_network_image/cached_network_image.dart';
 | 
			
		||||
import 'package:comunic/forez/helpers/forez_group_helper.dart';
 | 
			
		||||
import 'package:comunic/helpers/forez_groups_helper.dart';
 | 
			
		||||
import 'package:comunic/helpers/forez_presence_helper.dart';
 | 
			
		||||
import 'package:comunic/lists/forez_presences_set.dart';
 | 
			
		||||
import 'package:comunic/models/advanced_user_info.dart';
 | 
			
		||||
import 'package:comunic/models/displayed_content.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/async_screen_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/copy_icon.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/forez_presence_calendar_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/text_widget.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/ui_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:url_launcher/url_launcher.dart';
 | 
			
		||||
 | 
			
		||||
/// Show information about a Forez member
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
 | 
			
		||||
class ForezMemberProfileRoute extends StatefulWidget {
 | 
			
		||||
  final int userID;
 | 
			
		||||
 | 
			
		||||
  const ForezMemberProfileRoute({
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.userID,
 | 
			
		||||
  })  : assert(userID != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  _ForezMemberProfileRouteState createState() =>
 | 
			
		||||
      _ForezMemberProfileRouteState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _ForezMemberProfileRouteState extends State<ForezMemberProfileRoute> {
 | 
			
		||||
  final double _appBarHeight = 256.0;
 | 
			
		||||
 | 
			
		||||
  final _key = GlobalKey<AsyncScreenWidgetState>();
 | 
			
		||||
 | 
			
		||||
  AdvancedUserInfo _user;
 | 
			
		||||
  PresenceSet _presence;
 | 
			
		||||
 | 
			
		||||
  Future<void> _load() async {
 | 
			
		||||
    _user = await ForezGroupsHelper.getMemberInfo(forezGroup.id, widget.userID);
 | 
			
		||||
    _presence =
 | 
			
		||||
        await ForezPresenceHelper.getForUser(forezGroup.id, widget.userID);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) => AsyncScreenWidget(
 | 
			
		||||
      onReload: _load,
 | 
			
		||||
      onBuild: _buildProfile,
 | 
			
		||||
      loadingWidget: _buildLoading(),
 | 
			
		||||
      errorWidget: _buildError(),
 | 
			
		||||
      errorMessage: tr(
 | 
			
		||||
          "Failed to load user information, maybe it is not a Forez member yet?"));
 | 
			
		||||
 | 
			
		||||
  Widget _buildLoading() => Scaffold(
 | 
			
		||||
        appBar: AppBar(
 | 
			
		||||
          title: Text(tr("Loading...")),
 | 
			
		||||
        ),
 | 
			
		||||
        body: buildCenteredProgressBar(),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  Widget _buildError() => Scaffold(
 | 
			
		||||
        appBar: AppBar(
 | 
			
		||||
          title: Text(tr("Error")),
 | 
			
		||||
        ),
 | 
			
		||||
        body: buildErrorCard(
 | 
			
		||||
            tr("Failed to load user information, maybe it is not a Forez member yet?"),
 | 
			
		||||
            actions: [
 | 
			
		||||
              MaterialButton(
 | 
			
		||||
                onPressed: () => _key.currentState.refresh(),
 | 
			
		||||
                child: Text(tr("Try again")),
 | 
			
		||||
                textColor: Colors.white,
 | 
			
		||||
              )
 | 
			
		||||
            ]),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  Widget _buildProfile() => Scaffold(
 | 
			
		||||
        body: CustomScrollView(
 | 
			
		||||
          slivers: <Widget>[
 | 
			
		||||
            _buildAppBar(),
 | 
			
		||||
            _buildList(),
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  Widget _buildAppBar() => SliverAppBar(
 | 
			
		||||
        expandedHeight: _appBarHeight,
 | 
			
		||||
        pinned: true,
 | 
			
		||||
        flexibleSpace: FlexibleSpaceBar(
 | 
			
		||||
          title: Text(_user.fullName),
 | 
			
		||||
          background: Stack(
 | 
			
		||||
            fit: StackFit.expand,
 | 
			
		||||
            children: <Widget>[
 | 
			
		||||
              _user.accountImageURL == null
 | 
			
		||||
                  ? Container()
 | 
			
		||||
                  : CachedNetworkImage(
 | 
			
		||||
                      fit: BoxFit.cover,
 | 
			
		||||
                      imageUrl: _user.accountImageURL,
 | 
			
		||||
                      height: _appBarHeight,
 | 
			
		||||
                    ),
 | 
			
		||||
              // This gradient ensures that the toolbar icons are distinct
 | 
			
		||||
              // against the background image.
 | 
			
		||||
              const DecoratedBox(
 | 
			
		||||
                decoration: BoxDecoration(
 | 
			
		||||
                  gradient: LinearGradient(
 | 
			
		||||
                    begin: Alignment(0.0, -1.0),
 | 
			
		||||
                    end: Alignment(0.0, -0.4),
 | 
			
		||||
                    colors: <Color>[Color(0x60000000), Color(0x00000000)],
 | 
			
		||||
                  ),
 | 
			
		||||
                ),
 | 
			
		||||
              ),
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  Widget _buildList() => SliverList(
 | 
			
		||||
          delegate: SliverChildListDelegate(<Widget>[
 | 
			
		||||
        // Public note
 | 
			
		||||
        !_user.hasPublicNote
 | 
			
		||||
            ? Container()
 | 
			
		||||
            : ListTile(
 | 
			
		||||
                leading: Icon(Icons.note),
 | 
			
		||||
                title: TextWidget(content: DisplayedString(_user.publicNote)),
 | 
			
		||||
                subtitle: Text(tr("Note")),
 | 
			
		||||
              ),
 | 
			
		||||
 | 
			
		||||
        // Email address
 | 
			
		||||
        !_user.hasEmailAddress
 | 
			
		||||
            ? Container()
 | 
			
		||||
            : ListTile(
 | 
			
		||||
                leading: Icon(Icons.email),
 | 
			
		||||
                title: Text(_user.emailAddress),
 | 
			
		||||
                subtitle: Text(tr("Email address")),
 | 
			
		||||
                trailing: CopyIcon(_user.emailAddress),
 | 
			
		||||
              ),
 | 
			
		||||
 | 
			
		||||
        // Location
 | 
			
		||||
        !_user.hasLocation
 | 
			
		||||
            ? Container()
 | 
			
		||||
            : ListTile(
 | 
			
		||||
                leading: Icon(Icons.location_on),
 | 
			
		||||
                title: Text(_user.location),
 | 
			
		||||
                subtitle: Text(tr("Location")),
 | 
			
		||||
                trailing: CopyIcon(_user.location),
 | 
			
		||||
              ),
 | 
			
		||||
 | 
			
		||||
        // Website
 | 
			
		||||
        !_user.hasPersonalWebsite
 | 
			
		||||
            ? Container()
 | 
			
		||||
            : ListTile(
 | 
			
		||||
                leading: Icon(Icons.link),
 | 
			
		||||
                title: Text(_user.personalWebsite),
 | 
			
		||||
                subtitle: Text(tr("Website")),
 | 
			
		||||
                trailing: IconButton(
 | 
			
		||||
                  icon: Icon(Icons.open_in_new),
 | 
			
		||||
                  onPressed: () => launch(_user.personalWebsite),
 | 
			
		||||
                ),
 | 
			
		||||
              ),
 | 
			
		||||
 | 
			
		||||
        Divider(),
 | 
			
		||||
        ListTile(
 | 
			
		||||
          leading: Icon(Icons.calendar_today),
 | 
			
		||||
          title: Text(tr("Presence in Forez")),
 | 
			
		||||
          subtitle: Text(_presence.containsDate(DateTime.now())
 | 
			
		||||
              ? tr("Present today")
 | 
			
		||||
              : tr("Absent")),
 | 
			
		||||
        ),
 | 
			
		||||
        PresenceCalendarWidget(presenceSet: _presence),
 | 
			
		||||
        Divider(),
 | 
			
		||||
      ]));
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
import 'package:comunic/forez/helpers/forez_group_helper.dart';
 | 
			
		||||
import 'package:comunic/forez/ui/routes/forez_member_profile_route.dart';
 | 
			
		||||
import 'package:comunic/forez/ui/screens/forez_directory_screen.dart';
 | 
			
		||||
import 'package:comunic/helpers/events_helper.dart';
 | 
			
		||||
import 'package:comunic/models/conversation.dart';
 | 
			
		||||
@@ -72,7 +73,13 @@ class _MainRouteState extends MainController {
 | 
			
		||||
  void openGroup(int groupID, {int conversationID}) => _unsupportedFeature();
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void openUserPage(int userID) => _unsupportedFeature();
 | 
			
		||||
  void openUserPage(int userID) => pushPage(PageInfo(
 | 
			
		||||
        child: ForezMemberProfileRoute(userID: userID),
 | 
			
		||||
        hideNavBar: true,
 | 
			
		||||
        canShowAsDialog: true,
 | 
			
		||||
        type: PageType.USER_PAGE,
 | 
			
		||||
        id: userID,
 | 
			
		||||
      ));
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void openFriendsList() => _unsupportedFeature();
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ import 'package:comunic/lists/group_members_list.dart';
 | 
			
		||||
import 'package:comunic/lists/users_list.dart';
 | 
			
		||||
import 'package:comunic/models/group_membership.dart';
 | 
			
		||||
import 'package:comunic/models/user.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/async_screen_widget.dart';
 | 
			
		||||
import 'package:comunic/utils/account_utils.dart';
 | 
			
		||||
@@ -123,9 +124,8 @@ class _ForezDirectoryScreenState extends State<ForezDirectoryScreen> {
 | 
			
		||||
    if (user != null) _openUserProfile(user);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void _openUserProfile(User user) {
 | 
			
		||||
    print("Open user profile ${user.fullName}");
 | 
			
		||||
  }
 | 
			
		||||
  void _openUserProfile(User user) =>
 | 
			
		||||
      MainController.of(context).openUserPage(user.id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _ForezMemberTile extends StatelessWidget {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user