refactor(ui): rename portal to overlays

This commit is contained in:
Salvatore Giordano
2021-09-22 09:24:36 +02:00
parent 152adfc8b0
commit 9a1cb38e2a
2 changed files with 30 additions and 30 deletions
@@ -192,15 +192,15 @@ class MessageInput extends StatefulWidget {
this.onAttachmentLimitExceed, this.onAttachmentLimitExceed,
this.attachmentButtonBuilder, this.attachmentButtonBuilder,
this.commandButtonBuilder, this.commandButtonBuilder,
this.customPortalOptions = const [], this.customOverlays = const [],
}) : assert( }) : assert(
initialMessage == null || editMessage == null, initialMessage == null || editMessage == null,
"Can't provide both `initialMessage` and `editMessage`", "Can't provide both `initialMessage` and `editMessage`",
), ),
super(key: key); super(key: key);
/// List of portal options for showing overlays /// List of options for showing overlays
final List<PortalOptions> customPortalOptions; final List<OverlayOptions> customOverlays;
/// Message to edit /// Message to edit
final Message? editMessage; final Message? editMessage;
@@ -466,15 +466,15 @@ class MessageInputState extends State<MessageInput> {
); );
} }
return MultiPortal( return MultiOverlay(
childAnchor: Alignment.topCenter, childAnchor: Alignment.topCenter,
portalAnchor: Alignment.bottomCenter, overlayAnchor: Alignment.bottomCenter,
portalOptions: [ overlayOptions: [
PortalOptions( OverlayOptions(
visible: _showCommandsOverlay, visible: _showCommandsOverlay,
widget: _buildCommandsOverlayEntry(), widget: _buildCommandsOverlayEntry(),
), ),
PortalOptions( OverlayOptions(
visible: _focusNode.hasFocus && visible: _focusNode.hasFocus &&
textEditingController.text.isNotEmpty && textEditingController.text.isNotEmpty &&
textEditingController.selection.baseOffset > 0 && textEditingController.selection.baseOffset > 0 &&
@@ -486,11 +486,11 @@ class MessageInputState extends State<MessageInput> {
.contains(':'), .contains(':'),
widget: _buildEmojiOverlay(), widget: _buildEmojiOverlay(),
), ),
PortalOptions( OverlayOptions(
visible: _showMentionsOverlay, visible: _showMentionsOverlay,
widget: _buildMentionsOverlayEntry(), widget: _buildMentionsOverlayEntry(),
), ),
...widget.customPortalOptions, ...widget.customOverlays,
], ],
child: child, child: child,
); );
@@ -2,47 +2,47 @@ import 'package:collection/collection.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_portal/flutter_portal.dart'; import 'package:flutter_portal/flutter_portal.dart';
/// Class that contains the parameters for building a portal entry /// Class that contains the parameters for building an overlay entry
class PortalOptions { class OverlayOptions {
/// Constructs a new portal options object /// Constructs a new overlay options object
/// [visible] - the visibility of the portal /// [visible] - the visibility of the overlay
/// [widget] - the widget to be displayed /// [widget] - the widget to be displayed
PortalOptions({ OverlayOptions({
required this.visible, required this.visible,
required this.widget, required this.widget,
}); });
/// the visibility of the portal /// the visibility of the overlay
final bool visible; final bool visible;
/// the widget to be displayed /// the widget to be displayed
final Widget widget; final Widget widget;
} }
/// Widget that renders a single portal widget from a list of [portalOptions] /// Widget that renders a single overlay widget from a list of [overlayOptions]
/// It shows the first one that is visible /// It shows the first one that is visible
class MultiPortal extends StatelessWidget { class MultiOverlay extends StatelessWidget {
/// Constructs a new MultiPortal widget /// Constructs a new MultiOverlay widget
/// [portalOptions] - the list of portal options /// [overlayOptions] - the list of overlay options
/// [portalAnchor] - the anchor relative to the portal /// [overlayAnchor] - the anchor relative to the overlay
/// [childAnchor] - the anchor relative to the child /// [childAnchor] - the anchor relative to the child
/// [child] - the child widget /// [child] - the child widget
const MultiPortal({ const MultiOverlay({
Key? key, Key? key,
required this.portalOptions, required this.overlayOptions,
required this.child, required this.child,
required this.portalAnchor, required this.overlayAnchor,
required this.childAnchor, required this.childAnchor,
}) : super(key: key); }) : super(key: key);
/// The list of portal options /// The list of overlay options
final List<PortalOptions> portalOptions; final List<OverlayOptions> overlayOptions;
/// The child widget /// The child widget
final Widget child; final Widget child;
/// The anchor relative to the portal /// The anchor relative to the overlay
final Alignment? portalAnchor; final Alignment? overlayAnchor;
/// The anchor relative to the child /// The anchor relative to the child
final Alignment? childAnchor; final Alignment? childAnchor;
@@ -50,11 +50,11 @@ class MultiPortal extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final visibleOverlay = final visibleOverlay =
portalOptions.firstWhereOrNull((element) => element.visible); overlayOptions.firstWhereOrNull((element) => element.visible);
return PortalEntry( return PortalEntry(
childAnchor: childAnchor, childAnchor: childAnchor,
portalAnchor: portalAnchor, portalAnchor: overlayAnchor,
visible: visibleOverlay != null, visible: visibleOverlay != null,
portal: visibleOverlay?.widget, portal: visibleOverlay?.widget,
child: child, child: child,