mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 04:04:18 +00:00 
			
		
		
		
	Can update following status of a group
This commit is contained in:
		lib
							
								
								
									
										55
									
								
								lib/ui/widgets/group_following_widget.dart
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										55
									
								
								lib/ui/widgets/group_following_widget.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
import 'package:comunic/helpers/groups_helper.dart';
 | 
			
		||||
import 'package:comunic/models/group.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/safe_state.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/ui_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
/// Group following status widget
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
 | 
			
		||||
class GroupFollowingWidget extends StatefulWidget {
 | 
			
		||||
  final Group group;
 | 
			
		||||
  final Function() onUpdated;
 | 
			
		||||
 | 
			
		||||
  const GroupFollowingWidget(
 | 
			
		||||
      {Key key, @required this.group, @required this.onUpdated})
 | 
			
		||||
      : assert(group != null),
 | 
			
		||||
        assert(onUpdated != null),
 | 
			
		||||
        super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  _GroupFollowingWidgetState createState() => _GroupFollowingWidgetState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _GroupFollowingWidgetState extends SafeState<GroupFollowingWidget> {
 | 
			
		||||
  Group get _group => widget.group;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    if (!_group.isAtLeastMember) return Container();
 | 
			
		||||
 | 
			
		||||
    return InkWell(
 | 
			
		||||
      child: Text(
 | 
			
		||||
        _group.following ? tr("Following") : tr("Follow"),
 | 
			
		||||
        style: TextStyle(color: Colors.blue),
 | 
			
		||||
      ),
 | 
			
		||||
      onTap: () => _toggleFollowing(),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Toggle following status
 | 
			
		||||
  void _toggleFollowing() async {
 | 
			
		||||
    if (!await GroupsHelper().setFollowing(_group.id, !_group.following)) {
 | 
			
		||||
      showSimpleSnack(context, tr("Could not update following status!"));
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setState(() {
 | 
			
		||||
      _group.following = !_group.following;
 | 
			
		||||
 | 
			
		||||
      this.widget.onUpdated();
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user