2020-04-15 16:39:07 +00:00
|
|
|
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;
|
2022-03-10 18:39:57 +00:00
|
|
|
final Color? inactiveColor;
|
|
|
|
final Color? activeColor;
|
2020-04-15 16:39:07 +00:00
|
|
|
|
2021-03-16 17:27:02 +00:00
|
|
|
const GroupFollowingWidget({
|
2022-03-10 18:39:57 +00:00
|
|
|
Key? key,
|
|
|
|
required this.group,
|
|
|
|
required this.onUpdated,
|
2021-03-16 17:27:02 +00:00
|
|
|
this.activeColor,
|
|
|
|
this.inactiveColor,
|
2022-03-11 15:40:56 +00:00
|
|
|
}) : super(key: key);
|
2020-04-15 16:39:07 +00:00
|
|
|
|
|
|
|
@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(
|
2021-03-16 17:27:02 +00:00
|
|
|
child: RichText(
|
|
|
|
text: TextSpan(children: [
|
|
|
|
WidgetSpan(
|
|
|
|
child: Icon(
|
|
|
|
Icons.notifications,
|
|
|
|
size: 16.0,
|
|
|
|
color: _group.following ? widget.activeColor : widget.inactiveColor,
|
|
|
|
)),
|
|
|
|
TextSpan(
|
2022-03-11 15:40:56 +00:00
|
|
|
text:
|
|
|
|
" " + (_group.following ? tr("Following")! : tr("Follow")!)),
|
2021-03-16 17:27:02 +00:00
|
|
|
]),
|
2020-04-15 16:39:07 +00:00
|
|
|
),
|
|
|
|
onTap: () => _toggleFollowing(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Toggle following status
|
|
|
|
void _toggleFollowing() async {
|
|
|
|
if (!await GroupsHelper().setFollowing(_group.id, !_group.following)) {
|
2022-03-10 18:39:57 +00:00
|
|
|
showSimpleSnack(context, tr("Could not update following status!")!);
|
2020-04-15 16:39:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
_group.following = !_group.following;
|
|
|
|
|
|
|
|
this.widget.onUpdated();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|