blob: 05dd0b45db843019894904d351cd1d66d9623646 [file] [log] [blame]
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart' show TextSelectionToolbarLayoutDelegate;
/// Positions the toolbar below [anchor] or adjusts it higher to fit above
/// the bottom view insets, if applicable.
/// See also:
/// * [SpellCheckSuggestionsToolbar], which uses this to position itself.
class SpellCheckSuggestionsToolbarLayoutDelegate extends SingleChildLayoutDelegate {
/// Creates an instance of [SpellCheckSuggestionsToolbarLayoutDelegate].
required this.anchor,
/// {@macro flutter.material.SpellCheckSuggestionsToolbar.anchor}
/// Should be provided in local coordinates.
final Offset anchor;
BoxConstraints getConstraintsForChild(BoxConstraints constraints) {
return constraints.loosen();
Offset getPositionForChild(Size size, Size childSize) {
return Offset(
// Positions child (of childSize) just enough upwards to fit within size
// if it otherwise does not fit below the anchor.
anchor.dy + childSize.height > size.height
? size.height - childSize.height
: anchor.dy,
bool shouldRelayout(SpellCheckSuggestionsToolbarLayoutDelegate oldDelegate) {
return anchor != oldDelegate.anchor;