From bd548fe532fc2c941583ee8d08ec519ad9938232 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 17 Mar 2021 17:53:07 +0100 Subject: [PATCH] Improved post visibility picker dialog --- .../post_visibility_picker_dialog.dart} | 47 ++++++++++++------- lib/ui/tiles/post_tile.dart | 4 +- lib/ui/widgets/post_create_form_widget.dart | 4 +- 3 files changed, 35 insertions(+), 20 deletions(-) rename lib/{utils/post_utils.dart => ui/dialogs/post_visibility_picker_dialog.dart} (69%) diff --git a/lib/utils/post_utils.dart b/lib/ui/dialogs/post_visibility_picker_dialog.dart similarity index 69% rename from lib/utils/post_utils.dart rename to lib/ui/dialogs/post_visibility_picker_dialog.dart index b3d8075..d47c4c8 100644 --- a/lib/utils/post_utils.dart +++ b/lib/ui/dialogs/post_visibility_picker_dialog.dart @@ -9,7 +9,7 @@ import 'package:meta/meta.dart'; /// @author Pierre HUBERT /// Show post visibility level picker and return selected visibility level -Future showPostVisibilityPicker({ +Future showPostVisibilityPickerDialog({ @required BuildContext context, @required PostVisibilityLevel initialLevel, @required bool isGroup, @@ -20,11 +20,28 @@ Future showPostVisibilityPicker({ final newLevel = await showDialog( context: context, - builder: (c) => AlertDialog( - title: Text(tr("Select new post visibility level")), + builder: (c) => _PostVisibilityPickerWidget( + isGroup: isGroup, + ), + ); - // Show all options - content: Column( + return newLevel == null ? initialLevel : newLevel; +} + +class _PostVisibilityPickerWidget extends StatelessWidget { + final bool isGroup; + + const _PostVisibilityPickerWidget({Key key, @required this.isGroup}) + : super(key: key); + + @override + Widget build(BuildContext c) => AlertDialog( + title: Text(tr("Select new post visibility level")), + + // Show all options + content: ConstrainedBox( + constraints: BoxConstraints(maxHeight: 200), + child: Column( children: [ // Public PostVisibilityLevelTile( @@ -58,17 +75,15 @@ Future showPostVisibilityPicker({ ), ], ), - - // Dialog actions - actions: [ - // Cancel - TextButton( - child: Text(tr("Cancel").toUpperCase()), - onPressed: () => Navigator.pop(c, null), - ), - ], ), - ); - return newLevel == null ? initialLevel : newLevel; + // Dialog actions + actions: [ + // Cancel + TextButton( + child: Text(tr("Cancel").toUpperCase()), + onPressed: () => Navigator.pop(c, null), + ), + ], + ); } diff --git a/lib/ui/tiles/post_tile.dart b/lib/ui/tiles/post_tile.dart index f7c9b59..26fb3bb 100644 --- a/lib/ui/tiles/post_tile.dart +++ b/lib/ui/tiles/post_tile.dart @@ -10,6 +10,7 @@ import 'package:comunic/models/comment.dart'; import 'package:comunic/models/new_comment.dart'; import 'package:comunic/models/post.dart'; import 'package:comunic/models/user.dart'; +import 'package:comunic/ui/dialogs/post_visibility_picker_dialog.dart'; import 'package:comunic/ui/tiles/comment_tile.dart'; import 'package:comunic/ui/widgets/account_image_widget.dart'; import 'package:comunic/ui/widgets/countdown_widget.dart'; @@ -22,7 +23,6 @@ import 'package:comunic/utils/date_utils.dart'; import 'package:comunic/utils/files_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; import 'package:comunic/utils/navigation_utils.dart'; -import 'package:comunic/utils/post_utils.dart'; import 'package:comunic/utils/ui_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -573,7 +573,7 @@ class _PostTileState extends State { /// Update post visibility level Future updatePostVisibilityLevel() async { - final newLevel = await showPostVisibilityPicker( + final newLevel = await showPostVisibilityPickerDialog( context: context, initialLevel: widget.post.visibilityLevel, isGroup: widget.post.isGroupPost, diff --git a/lib/ui/widgets/post_create_form_widget.dart b/lib/ui/widgets/post_create_form_widget.dart index 9e472b5..9fd10e7 100644 --- a/lib/ui/widgets/post_create_form_widget.dart +++ b/lib/ui/widgets/post_create_form_widget.dart @@ -6,10 +6,10 @@ import 'package:comunic/models/new_post.dart'; import 'package:comunic/ui/dialogs/input_url_dialog.dart'; import 'package:comunic/ui/dialogs/input_youtube_link_dialog.dart'; import 'package:comunic/ui/dialogs/new_survey_dialog.dart'; +import 'package:comunic/ui/dialogs/post_visibility_picker_dialog.dart'; import 'package:comunic/ui/widgets/post_container_widget.dart'; import 'package:comunic/utils/files_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; -import 'package:comunic/utils/post_utils.dart'; import 'package:comunic/utils/ui_utils.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; @@ -219,7 +219,7 @@ class _PostCreateFormWidgetState extends State { /// Change post visibility level Future _changeVisibilityLevel() async { - final newLevel = await showPostVisibilityPicker( + final newLevel = await showPostVisibilityPickerDialog( context: context, initialLevel: _postVisibilityLevel, isGroup: widget.postTarget == PostTarget.GROUP_PAGE,