2019-05-23 16:27:43 +00:00
|
|
|
import 'package:comunic/enums/post_visibility_level.dart';
|
|
|
|
import 'package:comunic/ui/tiles/post_visibility_level_tile.dart';
|
|
|
|
import 'package:comunic/utils/intl_utils.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// Post utilities
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
|
|
|
/// Show post visibility level picker and return selected visibility level
|
2021-03-17 16:53:07 +00:00
|
|
|
Future<PostVisibilityLevel> showPostVisibilityPickerDialog({
|
2022-03-10 18:39:57 +00:00
|
|
|
required BuildContext context,
|
|
|
|
required PostVisibilityLevel initialLevel,
|
|
|
|
required bool isGroup,
|
2019-05-23 16:27:43 +00:00
|
|
|
}) async {
|
|
|
|
final newLevel = await showDialog<PostVisibilityLevel>(
|
|
|
|
context: context,
|
2021-03-17 16:53:07 +00:00
|
|
|
builder: (c) => _PostVisibilityPickerWidget(
|
|
|
|
isGroup: isGroup,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
return newLevel == null ? initialLevel : newLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PostVisibilityPickerWidget extends StatelessWidget {
|
|
|
|
final bool isGroup;
|
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
const _PostVisibilityPickerWidget({Key? key, required this.isGroup})
|
2021-03-17 16:53:07 +00:00
|
|
|
: super(key: key);
|
2019-05-23 16:27:43 +00:00
|
|
|
|
2021-03-17 16:53:07 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext c) => AlertDialog(
|
2022-03-10 18:39:57 +00:00
|
|
|
title: Text(tr("Select new post visibility level")!),
|
2021-03-17 16:53:07 +00:00
|
|
|
|
|
|
|
// Show all options
|
|
|
|
content: ConstrainedBox(
|
|
|
|
constraints: BoxConstraints(maxHeight: 200),
|
|
|
|
child: Column(
|
2019-05-23 16:27:43 +00:00
|
|
|
children: <Widget>[
|
|
|
|
// Public
|
|
|
|
PostVisibilityLevelTile(
|
|
|
|
level: PostVisibilityLevel.PUBLIC,
|
2022-03-10 18:39:57 +00:00
|
|
|
title: tr("Public")!,
|
2019-05-23 16:27:43 +00:00
|
|
|
onSelect: (o) => Navigator.pop(c, o),
|
|
|
|
),
|
|
|
|
|
|
|
|
// Friends only (User page only)
|
|
|
|
PostVisibilityLevelTile(
|
|
|
|
level: PostVisibilityLevel.FRIENDS,
|
2022-03-10 18:39:57 +00:00
|
|
|
title: tr("Friends only")!,
|
2019-05-23 16:27:43 +00:00
|
|
|
onSelect: (o) => Navigator.pop(c, o),
|
|
|
|
visible: !isGroup,
|
|
|
|
),
|
|
|
|
|
|
|
|
// User only (User page only)
|
|
|
|
PostVisibilityLevelTile(
|
|
|
|
level: PostVisibilityLevel.USER,
|
2022-03-10 18:39:57 +00:00
|
|
|
title: tr("Me only")!,
|
2019-05-23 16:27:43 +00:00
|
|
|
onSelect: (o) => Navigator.pop(c, o),
|
|
|
|
visible: !isGroup,
|
|
|
|
),
|
|
|
|
|
|
|
|
// Group members only (Group page only)
|
|
|
|
PostVisibilityLevelTile(
|
|
|
|
level: PostVisibilityLevel.GROUP_MEMBERS,
|
2022-03-10 18:39:57 +00:00
|
|
|
title: tr("Group members only")!,
|
2019-05-23 16:27:43 +00:00
|
|
|
onSelect: (o) => Navigator.pop(c, o),
|
|
|
|
visible: isGroup,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
2021-03-17 16:53:07 +00:00
|
|
|
// Dialog actions
|
|
|
|
actions: <Widget>[
|
|
|
|
// Cancel
|
|
|
|
TextButton(
|
2022-03-10 18:39:57 +00:00
|
|
|
child: Text(tr("Cancel")!.toUpperCase()),
|
2021-03-17 16:53:07 +00:00
|
|
|
onPressed: () => Navigator.pop(c, null),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2019-05-23 16:27:43 +00:00
|
|
|
}
|