mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Simplify code
This commit is contained in:
		@@ -1,15 +1,11 @@
 | 
			
		||||
import 'package:comunic/enums/post_target.dart';
 | 
			
		||||
import 'package:comunic/helpers/posts_helper.dart';
 | 
			
		||||
import 'package:comunic/models/advanced_group_info.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
 | 
			
		||||
import 'package:comunic/ui/screens/group_members_screen.dart';
 | 
			
		||||
import 'package:comunic/ui/screens/group_sections/group_posts_section.dart';
 | 
			
		||||
import 'package:comunic/ui/screens/group_settings_screen.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/group_following_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/group_icon_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/group_membership_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/like_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/posts_list_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/safe_state.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
@@ -20,8 +16,6 @@ import 'package:flutter/material.dart';
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
 | 
			
		||||
enum _MenuItems { OPEN_MEMBERS, OPEN_SETTINGS }
 | 
			
		||||
 | 
			
		||||
Color get _headerTextColor => Colors.white;
 | 
			
		||||
 | 
			
		||||
Color get _headerColor => Colors.blueAccent.shade700;
 | 
			
		||||
@@ -50,10 +44,12 @@ class _AuthorizedGroupPageScreenState
 | 
			
		||||
 | 
			
		||||
  TabController _tabController;
 | 
			
		||||
 | 
			
		||||
  final _postsKey = GlobalKey<PostsListWidgetState>();
 | 
			
		||||
 | 
			
		||||
  List<_GroupPageTab> get _tabs => [
 | 
			
		||||
        _GroupPageTab(widget: _buildGroupPagePostsList(), label: tr("Posts")),
 | 
			
		||||
        // Posts list
 | 
			
		||||
        _GroupPageTab(
 | 
			
		||||
          widget: GroupPostsSection(group: _group),
 | 
			
		||||
          label: tr("Posts"),
 | 
			
		||||
        ),
 | 
			
		||||
      ];
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
@@ -97,10 +93,10 @@ class _AuthorizedGroupPageScreenState
 | 
			
		||||
 | 
			
		||||
  /// Build group page header
 | 
			
		||||
  Widget _buildGroupPageHeader() {
 | 
			
		||||
    return DefaultTextStyle(
 | 
			
		||||
      style: TextStyle(color: _headerTextColor),
 | 
			
		||||
      child: Container(
 | 
			
		||||
        color: _headerColor,
 | 
			
		||||
    return Material(
 | 
			
		||||
      color: _headerColor,
 | 
			
		||||
      child: DefaultTextStyle(
 | 
			
		||||
        style: TextStyle(color: _headerTextColor),
 | 
			
		||||
        child: Padding(
 | 
			
		||||
          padding: const EdgeInsets.all(8.0),
 | 
			
		||||
          child: Row(
 | 
			
		||||
@@ -140,65 +136,20 @@ class _AuthorizedGroupPageScreenState
 | 
			
		||||
                  ),
 | 
			
		||||
                ],
 | 
			
		||||
              ),
 | 
			
		||||
              PopupMenuButton<_MenuItems>(
 | 
			
		||||
                itemBuilder: (c) => [
 | 
			
		||||
                  PopupMenuItem(
 | 
			
		||||
                    child: Text(tr("Group members")),
 | 
			
		||||
                    value: _MenuItems.OPEN_MEMBERS,
 | 
			
		||||
                    enabled: _group.isAtLeastModerator,
 | 
			
		||||
                  ),
 | 
			
		||||
                  PopupMenuItem(
 | 
			
		||||
                    child: Text(tr("Group settings")),
 | 
			
		||||
                    value: _MenuItems.OPEN_SETTINGS,
 | 
			
		||||
                    enabled: _group.isAdmin,
 | 
			
		||||
                  ),
 | 
			
		||||
                ],
 | 
			
		||||
                onSelected: _handleMenuSelection,
 | 
			
		||||
              ),
 | 
			
		||||
 | 
			
		||||
              // Settings button
 | 
			
		||||
              _group.isAdmin
 | 
			
		||||
                  ? IconButton(
 | 
			
		||||
                      icon: Icon(Icons.settings, color: _headerTextColor),
 | 
			
		||||
                      onPressed: () => MainController.of(context)
 | 
			
		||||
                          .push(GroupSettingsScreen(groupID: _group.id)))
 | 
			
		||||
                  : Container(),
 | 
			
		||||
            ],
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Add create post target
 | 
			
		||||
  Widget _buildPostCreationArea() {
 | 
			
		||||
    if (!_group.canCreatePost) return Container();
 | 
			
		||||
 | 
			
		||||
    return PostCreateFormWidget(
 | 
			
		||||
        postTarget: PostTarget.GROUP_PAGE,
 | 
			
		||||
        targetID: _group.id,
 | 
			
		||||
        onCreated: () => _postsKey.currentState.loadPostsList(getOlder: false));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Build the list of posts of the group
 | 
			
		||||
  Widget _buildGroupPagePostsList() {
 | 
			
		||||
    return PostsListWidget(
 | 
			
		||||
      key: _postsKey,
 | 
			
		||||
      topWidgets: <Widget>[
 | 
			
		||||
        _buildPostCreationArea(),
 | 
			
		||||
      ],
 | 
			
		||||
      getPostsList: () => PostsHelper().getGroupPosts(_group.id),
 | 
			
		||||
      showPostsTarget: false,
 | 
			
		||||
      userNamesClickable: true,
 | 
			
		||||
      getOlder: (from) => PostsHelper().getGroupPosts(_group.id, from: from),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Handles menu selection
 | 
			
		||||
  void _handleMenuSelection(_MenuItems item) {
 | 
			
		||||
    switch (item) {
 | 
			
		||||
      case _MenuItems.OPEN_MEMBERS:
 | 
			
		||||
        MainController.of(context).push(GroupMembersScreen(groupID: _group.id));
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      case _MenuItems.OPEN_SETTINGS:
 | 
			
		||||
        MainController.of(context)
 | 
			
		||||
            .push(GroupSettingsScreen(groupID: _group.id));
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _GroupPageTab {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										53
									
								
								lib/ui/screens/group_sections/group_posts_section.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								lib/ui/screens/group_sections/group_posts_section.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
			
		||||
import 'package:comunic/enums/post_target.dart';
 | 
			
		||||
import 'package:comunic/helpers/posts_helper.dart';
 | 
			
		||||
import 'package:comunic/models/advanced_group_info.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/posts_list_widget.dart';
 | 
			
		||||
/// Group posts section
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
class GroupPostsSection extends StatefulWidget {
 | 
			
		||||
  final AdvancedGroupInfo group;
 | 
			
		||||
 | 
			
		||||
  const GroupPostsSection({
 | 
			
		||||
    Key key,
 | 
			
		||||
    @required this.group,
 | 
			
		||||
  })  : assert(group != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  _GroupPostsSectionState createState() => _GroupPostsSectionState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _GroupPostsSectionState extends State<GroupPostsSection> {
 | 
			
		||||
  final _postsKey = GlobalKey<PostsListWidgetState>();
 | 
			
		||||
 | 
			
		||||
  /// Add create post target
 | 
			
		||||
  Widget _buildPostCreationArea() {
 | 
			
		||||
    if (!widget.group.canCreatePost) return Container();
 | 
			
		||||
 | 
			
		||||
    return PostCreateFormWidget(
 | 
			
		||||
      postTarget: PostTarget.GROUP_PAGE,
 | 
			
		||||
      targetID: widget.group.id,
 | 
			
		||||
      onCreated: () => _postsKey.currentState.loadPostsList(getOlder: false),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Build the list of posts of the group
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return PostsListWidget(
 | 
			
		||||
      key: _postsKey,
 | 
			
		||||
      topWidgets: <Widget>[
 | 
			
		||||
        _buildPostCreationArea(),
 | 
			
		||||
      ],
 | 
			
		||||
      getPostsList: () => PostsHelper().getGroupPosts(widget.group.id),
 | 
			
		||||
      showPostsTarget: false,
 | 
			
		||||
      userNamesClickable: true,
 | 
			
		||||
      getOlder: (from) =>
 | 
			
		||||
          PostsHelper().getGroupPosts(widget.group.id, from: from),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user