Skip to content

Commit

Permalink
overflow, minFont, maxFont, Grnularity, softwrap and replacement adde…
Browse files Browse the repository at this point in the history
…d for text
  • Loading branch information
iampawan committed Oct 11, 2020
1 parent ae73600 commit 5dc8421
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- numCurrency and numCurrencyWithLocale() added.
- circularAssetImage, circularNetworImage, circularAssetShadowImage added to string extension methods.
- orientation prop added to context extensions.
- [BREAKING] Overflow has been removed and clip has been added with default as Clipbehavior.None. It can affect all the widgets which uses Stack or ZStack.


## [0.4.1] - July 15, 2020

Expand Down
9 changes: 8 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ class Demo extends StatelessWidget {
title: "Vx Demo".text.make(),
),
body: VStack([
"Welcome to VelocityX".text.semiBold.blue500.xl4.make(),
"Welcome to VelocityX"
.text
.maxLines(4)
.semiBold
.ellipsis
.blue500
.minFontSize(20)
.make(),
20.heightBox,
"${context.isMobile ? 'We are on mobile' : 'We are on Web'}"
.text
Expand Down
79 changes: 63 additions & 16 deletions lib/src/flutter/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ class VxTextBuilder extends VxWidgetBuilder<AutoSizeText>
setChildToColor(this);
}

String _text;
String _fontFamily;
String _text, _fontFamily;

double _scaleFactor,
_fontSize,
_minFontSize,
_letterSpacing,
_lineHeight,
_maxFontSize,
_stepGranularity;
int _maxLines;
FontWeight _fontWeight;
TextAlign _textAlign;
double _scaleFactor;
double _fontSize;
int _maxLines;
FontStyle _fontStyle;
double _letterSpacing;
double _lineHeight;
TextDecoration _decoration;
TextStyle _textStyle;
TextStyle _themedStyle;
TextStyle _textStyle, _themedStyle;
TextOverflow _overflow;
Widget _replacement;
bool _softWrap;

VxTextBuilder text(String text) {
_text = text;
Expand All @@ -67,6 +72,37 @@ class VxTextBuilder extends VxWidgetBuilder<AutoSizeText>
return this;
}

VxTextBuilder softWrap(bool softWrap) {
_softWrap = softWrap;
return this;
}

/// Can be used to set overflow of a text
VxTextBuilder overflow(TextOverflow overflow) {
_overflow = overflow;
return this;
}

VxTextBuilder minFontSize(double minFontSize) {
_minFontSize = minFontSize;
return this;
}

VxTextBuilder maxFontSize(double maxFontSize) {
_maxFontSize = maxFontSize;
return this;
}

VxTextBuilder stepGranularity(double stepGranularity) {
_stepGranularity = stepGranularity;
return this;
}

VxTextBuilder overflowReplacement(Widget overflowReplacement) {
_replacement = overflowReplacement;
return this;
}

/// Use textStyle to provide custom or any theme style.
VxTextBuilder textStyle(TextStyle _style) {
_themedStyle = _style;
Expand All @@ -78,6 +114,10 @@ class VxTextBuilder extends VxWidgetBuilder<AutoSizeText>
VxTextBuilder get end => this.._textAlign = TextAlign.end;
VxTextBuilder get justify => this.._textAlign = TextAlign.justify;

VxTextBuilder get fade => this.._overflow = TextOverflow.fade;
VxTextBuilder get ellipsis => this.._overflow = TextOverflow.ellipsis;
VxTextBuilder get visible => this.._overflow = TextOverflow.visible;

VxTextBuilder size(double size) => this.._fontSize = size;

VxTextBuilder get xs => _fontSizedText(child: this, scaleFactor: 0.75);
Expand Down Expand Up @@ -181,13 +221,20 @@ class VxTextBuilder extends VxWidgetBuilder<AutoSizeText>
decoration: _decoration,
height: _lineHeight,
);
return AutoSizeText(_text,
key: key,
textAlign: _textAlign,
maxLines: _maxLines,
textScaleFactor: _scaleFactor,
softWrap: true,
style: _themedStyle?.merge(ts) ?? _textStyle?.merge(ts) ?? ts);
return AutoSizeText(
_text,
key: key,
textAlign: _textAlign,
maxLines: _maxLines,
textScaleFactor: _scaleFactor,
style: _themedStyle?.merge(ts) ?? _textStyle?.merge(ts) ?? ts,
softWrap: _softWrap ?? true,
minFontSize: _minFontSize ?? 12,
maxFontSize: _maxFontSize ?? double.infinity,
stepGranularity: _stepGranularity ?? 1,
overflowReplacement: _replacement,
overflow: _overflow ?? TextOverflow.clip,
);
}
}

Expand Down

0 comments on commit 5dc8421

Please sign in to comment.