Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [MDS-1003] Fix TextInput overflow issues #355

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/lib/src/storybook/stories/text_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class TextAreaStory extends StatelessWidget {
children: [
MoonTextArea(
enabled: enabledKnob,
expands: growableKnob,
height: growableKnob ? null : 200,
textColor: textColor,
hintTextColor: hintTextColor,
Expand Down
10 changes: 8 additions & 2 deletions lib/src/widgets/common/border_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:moon_design/moon_design.dart';

class BorderContainer extends StatefulWidget {
final bool expands;
final Clip clipBehavior;
final Color? backgroundColor;
final Decoration? decoration;
Expand All @@ -17,6 +18,7 @@ class BorderContainer extends StatefulWidget {
/// Primarily utilized in [MoonTextInput] and [MoonTextInputGroup].
const BorderContainer({
super.key,
this.expands = false,
this.clipBehavior = Clip.none,
this.backgroundColor,
this.decoration,
Expand Down Expand Up @@ -84,8 +86,12 @@ class _BorderContainerState extends State<BorderContainer> with SingleTickerProv
animation: _borderAnimation,
builder: (context, child) {
return Container(
height: widget.height,
width: widget.width,
constraints: BoxConstraints(
minHeight: widget.height ?? 0,
minWidth: widget.width ?? 0,
maxHeight: widget.expands ? double.infinity : widget.height ?? double.infinity,
maxWidth: widget.expands ? double.infinity : widget.width ?? double.infinity,
),
clipBehavior: widget.clipBehavior,
decoration: widget.decoration ??
ShapeDecorationWithPremultipliedAlpha(
Expand Down
6 changes: 5 additions & 1 deletion lib/src/widgets/text_area/text_area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class MoonTextArea extends StatelessWidget {
/// {@macro flutter.services.TextInputConfiguration.enableSuggestions}
final bool enableSuggestions;

/// {@macro flutter.widgets.editableText.expands}
final bool expands;

/// {@macro flutter.widgets.editableText.readOnly}
final bool readOnly;

Expand Down Expand Up @@ -224,6 +227,7 @@ class MoonTextArea extends StatelessWidget {
this.enableIMEPersonalizedLearning = true,
this.enableInteractiveSelection,
this.enableSuggestions = true,
this.expands = false,
this.readOnly = false,
this.scribbleEnabled = true,
this.showCursor,
Expand Down Expand Up @@ -343,7 +347,7 @@ class MoonTextArea extends StatelessWidget {
enableSuggestions: enableSuggestions,
errorColor: effectiveErrorColor,
errorBuilder: errorBuilder,
expands: height != null,
expands: expands,
focusNode: focusNode,
height: height,
helper: helper,
Expand Down
81 changes: 37 additions & 44 deletions lib/src/widgets/text_input/text_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1298,21 +1298,21 @@ class _MoonTextInputState extends State<MoonTextInput>
backgroundColor: effectiveBackgroundColor,
border: resolvedBorder,
decoration: widget.decoration,
height: widget.keyboardType == TextInputType.multiline && widget.height == null ? null : effectiveHeight,
expands: widget.expands,
width: widget.width,
height: effectiveHeight,
duration: effectiveTransitionDuration,
curve: effectiveTransitionCurve,
child: Row(
crossAxisAlignment: widget.expands ? CrossAxisAlignment.center : CrossAxisAlignment.stretch,
children: [
if (widget.leading != null)
SizedBox(
height: double.infinity,
child: Padding(
padding: EdgeInsetsDirectional.only(
start: resolvedContentPadding.left,
end: effectiveGap,
),
child: widget.leading,
Padding(
padding: EdgeInsetsDirectional.only(
start: resolvedContentPadding.left,
end: effectiveGap,
),
child: widget.leading,
),
Expanded(
child: Padding(
Expand Down Expand Up @@ -1371,15 +1371,12 @@ class _MoonTextInputState extends State<MoonTextInput>
),
),
if (widget.trailing != null)
SizedBox(
height: double.infinity,
child: Padding(
padding: EdgeInsetsDirectional.only(
start: effectiveGap,
end: resolvedContentPadding.right,
),
child: widget.trailing,
Padding(
padding: EdgeInsetsDirectional.only(
start: effectiveGap,
end: resolvedContentPadding.right,
),
child: widget.trailing,
),
],
),
Expand All @@ -1392,38 +1389,34 @@ class _MoonTextInputState extends State<MoonTextInput>
opacity: widget.enabled ? 1.0 : effectiveDisabledOpacityValue,
curve: effectiveTransitionCurve,
duration: effectiveTransitionDuration,
child: SizedBox(
width: widget.width,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
child,
if (widget.helper != null || (widget.errorText != null))
RepaintBoundary(
child: IconTheme(
data: IconThemeData(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
child,
if (widget.helper != null || (widget.errorText != null))
RepaintBoundary(
child: IconTheme(
data: IconThemeData(
color: widget.errorText != null ? effectiveErrorColor : effectiveHintTextColor,
),
child: DefaultTextStyle(
style: effectiveHelperTextStyle.copyWith(
color: widget.errorText != null ? effectiveErrorColor : effectiveHintTextColor,
),
child: DefaultTextStyle(
style: effectiveHelperTextStyle.copyWith(
color: widget.errorText != null ? effectiveErrorColor : effectiveHintTextColor,
),
child: widget.errorText != null
? widget.errorBuilder?.call(context, widget.errorText) ??
Padding(
padding: effectiveHelperPadding,
child: MoonErrorMessage(errorText: widget.errorText!),
)
: Padding(
child: widget.errorText != null
? widget.errorBuilder?.call(context, widget.errorText) ??
Padding(
padding: effectiveHelperPadding,
child: widget.helper,
),
),
child: MoonErrorMessage(errorText: widget.errorText!),
)
: Padding(
padding: effectiveHelperPadding,
child: widget.helper,
),
),
),
],
),
),
],
),
);

Expand Down