Skip to content

Commit

Permalink
formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
iampawan committed Jan 14, 2022
1 parent 5a39a00 commit 82448a6
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 53 deletions.
20 changes: 10 additions & 10 deletions lib/src/flutter/popup_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,23 @@ class _VxPopupMenuState extends State<VxPopupMenu> {
child: widget.child,
onTap: () {
if (widget.clickType == VxClickType.singleClick) {
if(!_controller!.menuIsShowing){
_showMenu();
_controller!.menuIsShowing = true;
}else{
if (!_controller!.menuIsShowing) {
_showMenu();
_controller!.menuIsShowing = true;
} else {
_hideMenu();
_controller!.menuIsShowing = false;
_controller!.menuIsShowing = false;
}
}
},
onLongPress: () {
if (widget.clickType == VxClickType.longClick) {
if(!_controller!.menuIsShowing){
_showMenu();
_controller!.menuIsShowing = true;
}else{
if (!_controller!.menuIsShowing) {
_showMenu();
_controller!.menuIsShowing = true;
} else {
_hideMenu();
_controller!.menuIsShowing = false;
_controller!.menuIsShowing = false;
}
}
},
Expand Down
33 changes: 22 additions & 11 deletions lib/src/flutter/text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import 'velocityx_mixins/color_mixin.dart';
/// overflows anyway, you should check if the parent widget actually constraints
/// the size of this widget.
@protected
class VxTextBuilder extends VxWidgetBuilder<Widget> with VxColorMixin<VxTextBuilder> {
class VxTextBuilder extends VxWidgetBuilder<Widget>
with VxColorMixin<VxTextBuilder> {
VxTextBuilder(String this._text) {
setChildToColor(this);
}
Expand Down Expand Up @@ -76,7 +77,8 @@ class VxTextBuilder extends VxWidgetBuilder<Widget> with VxColorMixin<VxTextBuil
}

/// Set [color] of the text using hexvalue
VxTextBuilder hexColor(String colorHex) => this..velocityColor = Vx.hexToColor(colorHex);
VxTextBuilder hexColor(String colorHex) =>
this..velocityColor = Vx.hexToColor(colorHex);

/// [LayoutBuilder] does not support using IntrinsicWidth or IntrinsicHeight.
///
Expand Down Expand Up @@ -352,9 +354,11 @@ class VxTextBuilder extends VxWidgetBuilder<Widget> with VxColorMixin<VxTextBuil
VxTextBuilder get xl6 => _fontSizedText(child: this, scaleFactor: 4);

/// Sets [textScaleFactor] to custom value
VxTextBuilder scale(double value) => _fontSizedText(child: this, scaleFactor: value);
VxTextBuilder scale(double value) =>
_fontSizedText(child: this, scaleFactor: value);

VxTextBuilder _fontSizedText({required double scaleFactor, required VxTextBuilder child}) {
VxTextBuilder _fontSizedText(
{required double scaleFactor, required VxTextBuilder child}) {
_fontSize = _fontSize ?? 14.0;
_scaleFactor = scaleFactor;
return this;
Expand Down Expand Up @@ -420,7 +424,8 @@ class VxTextBuilder extends VxWidgetBuilder<Widget> with VxColorMixin<VxTextBuil
VxTextBuilder get underline => this.._decoration = TextDecoration.underline;

/// Sets [TextDecoration] as [TextDecoration.lineThrough]
VxTextBuilder get lineThrough => this.._decoration = TextDecoration.lineThrough;
VxTextBuilder get lineThrough =>
this.._decoration = TextDecoration.lineThrough;

/// Sets [TextDecoration] as [TextDecoration.overline]
VxTextBuilder get overline => this.._decoration = TextDecoration.overline;
Expand Down Expand Up @@ -453,10 +458,12 @@ class VxTextBuilder extends VxWidgetBuilder<Widget> with VxColorMixin<VxTextBuil
VxTextBuilder lineHeight(double val) => this.._lineHeight = val;

/// Sets [Shadow] as specified in request *#127*
VxTextBuilder shadow(double offsetX, double offsetY, double blurRadius, Color color) => this
.._shadowBlur = blurRadius
.._shadowColor = color
.._shadowOffset = Offset(offsetX, offsetY);
VxTextBuilder shadow(
double offsetX, double offsetY, double blurRadius, Color color) =>
this
.._shadowBlur = blurRadius
.._shadowColor = color
.._shadowOffset = Offset(offsetX, offsetY);

/// Sets [Shadow] blur
VxTextBuilder shadowBlur(double blur) => this.._shadowBlur = blur;
Expand All @@ -465,11 +472,15 @@ class VxTextBuilder extends VxWidgetBuilder<Widget> with VxColorMixin<VxTextBuil
VxTextBuilder shadowColor(Color color) => this.._shadowColor = color;

/// Sets [Shadow] offset
VxTextBuilder shadowOffset(double dx, double dy) => this.._shadowOffset = Offset(dx, dy);
VxTextBuilder shadowOffset(double dx, double dy) =>
this.._shadowOffset = Offset(dx, dy);

@override
Widget make({Key? key}) {
final sdw = [Shadow(blurRadius: _shadowBlur, color: _shadowColor, offset: _shadowOffset)];
final sdw = [
Shadow(
blurRadius: _shadowBlur, color: _shadowColor, offset: _shadowOffset)
];

final ts = TextStyle(
color: velocityColor,
Expand Down
107 changes: 75 additions & 32 deletions test/flutter/text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import 'package:velocity_x/src/extensions/string_ext.dart';
import 'package:velocity_x/velocity_x.dart';

void main() {
Directionality getDirectionalityWidget({required Widget child}) => Directionality(
Directionality getDirectionalityWidget({required Widget child}) =>
Directionality(
textDirection: TextDirection.ltr,
child: child,
);
Expand Down Expand Up @@ -51,7 +52,8 @@ void main() {
});

group("Group all text tests", () {
testWidgets('text used on String creates a Text Widget', (WidgetTester tester) async {
testWidgets('text used on String creates a Text Widget',
(WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(
child: 'VelocityX'.text.make(),
Expand All @@ -64,7 +66,8 @@ void main() {
);
});

testWidgets('Text widget responds to Font Scale', (WidgetTester tester) async {
testWidgets('Text widget responds to Font Scale',
(WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(
child: 'VelocityX'.text.xs.make(),
Expand All @@ -78,7 +81,8 @@ void main() {
);
});

testWidgets('Text widget responds to fontSize', (WidgetTester tester) async {
testWidgets('Text widget responds to fontSize',
(WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(
child: "VelocityX".text.size(24).make(),
Expand All @@ -91,7 +95,8 @@ void main() {
);
});

testWidgets('Text widget responds to FontWeight', (WidgetTester tester) async {
testWidgets('Text widget responds to FontWeight',
(WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(
child: 'VelocityX'.text.medium.make(),
Expand All @@ -100,70 +105,108 @@ void main() {

// Font Weight for medium is 500
expect(
tester.widget<AutoSizeText>(find.byType(AutoSizeText)).style!.fontWeight,
tester
.widget<AutoSizeText>(find.byType(AutoSizeText))
.style!
.fontWeight,
FontWeight.w500,
);
});

testWidgets('Text widget responds to FontStyle', (WidgetTester tester) async {
await tester.pumpWidget(getDirectionalityWidget(child: 'VelocityX'.text.italic.make()));
testWidgets('Text widget responds to FontStyle',
(WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(child: 'VelocityX'.text.italic.make()));

expect(
tester.widget<AutoSizeText>(find.byType(AutoSizeText)).style!.fontStyle,
FontStyle.italic,
);
});

testWidgets('Text widget responds to alignment', (WidgetTester tester) async {
await tester.pumpWidget(getDirectionalityWidget(child: 'VelocityX'.text.start.make()));
testWidgets('Text widget responds to alignment',
(WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(child: 'VelocityX'.text.start.make()));

expect(tester.widget<AutoSizeText>(find.byType(AutoSizeText)).textAlign, TextAlign.start);
expect(tester.widget<AutoSizeText>(find.byType(AutoSizeText)).textAlign,
TextAlign.start);
});

testWidgets('Text widget responds to letter spacing', (WidgetTester tester) async {
await tester.pumpWidget(getDirectionalityWidget(child: 'VelocityX'.text.tightest.make()));
testWidgets('Text widget responds to letter spacing',
(WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(child: 'VelocityX'.text.tightest.make()));

expect(tester.widget<AutoSizeText>(find.byType(AutoSizeText)).style!.letterSpacing, -3.0);
expect(
tester
.widget<AutoSizeText>(find.byType(AutoSizeText))
.style!
.letterSpacing,
-3.0);
});

testWidgets('Text widget responds to custom letter spacing', (WidgetTester tester) async {
await tester
.pumpWidget(getDirectionalityWidget(child: 'VelocityX'.text.letterSpacing(4.0).make()));
testWidgets('Text widget responds to custom letter spacing',
(WidgetTester tester) async {
await tester.pumpWidget(getDirectionalityWidget(
child: 'VelocityX'.text.letterSpacing(4.0).make()));

expect(tester.widget<AutoSizeText>(find.byType(AutoSizeText)).style!.letterSpacing, 4.0);
expect(
tester
.widget<AutoSizeText>(find.byType(AutoSizeText))
.style!
.letterSpacing,
4.0);
});

testWidgets('Text widget responds to TextDecoration', (WidgetTester tester) async {
await tester.pumpWidget(getDirectionalityWidget(child: 'VelocityX'.text.underline.make()));
testWidgets('Text widget responds to TextDecoration',
(WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(child: 'VelocityX'.text.underline.make()));

expect(tester.widget<AutoSizeText>(find.byType(AutoSizeText)).style!.decoration,
expect(
tester
.widget<AutoSizeText>(find.byType(AutoSizeText))
.style!
.decoration,
TextDecoration.underline);
});

testWidgets('Text widget responds to line height', (WidgetTester tester) async {
await tester.pumpWidget(getDirectionalityWidget(child: 'VelocityX'.text.heightSnug.make()));
testWidgets('Text widget responds to line height',
(WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(child: 'VelocityX'.text.heightSnug.make()));

// Line Height or heightSnug is 0.875
expect(tester.widget<AutoSizeText>(find.byType(AutoSizeText)).style!.height, 0.875);
expect(
tester.widget<AutoSizeText>(find.byType(AutoSizeText)).style!.height,
0.875);
});

testWidgets('Text widget responds to text utilities', (WidgetTester tester) async {
await tester.pumpWidget(getDirectionalityWidget(child: 'VelocityX'.text.uppercase.make()));
testWidgets('Text widget responds to text utilities',
(WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(child: 'VelocityX'.text.uppercase.make()));

expect(tester.widget<AutoSizeText>(find.byType(AutoSizeText)).data, 'VELOCITYX');
expect(tester.widget<AutoSizeText>(find.byType(AutoSizeText)).data,
'VELOCITYX');
});

testWidgets('key is properly assigned', (WidgetTester tester) async {
await tester.pumpWidget(
getDirectionalityWidget(child: 'VelocityX'.text.uppercase.make(key: const Key("key"))));
await tester.pumpWidget(getDirectionalityWidget(
child: 'VelocityX'.text.uppercase.make(key: const Key("key"))));

expect(tester.widget(find.byKey(const Key('key'))).runtimeType, AutoSizeText);
expect(tester.widget(find.byKey(const Key('key'))).runtimeType,
AutoSizeText);
});

testWidgets('Text widget responds to color', (WidgetTester tester) async {
await tester.pumpWidget(getDirectionalityWidget(child: 'VelocityX'.text.red300.make()));
await tester.pumpWidget(
getDirectionalityWidget(child: 'VelocityX'.text.red300.make()));

expect(tester.widget<AutoSizeText>(find.byType(AutoSizeText)).style!.color, Vx.red300);
expect(
tester.widget<AutoSizeText>(find.byType(AutoSizeText)).style!.color,
Vx.red300);
});
});
}

0 comments on commit 82448a6

Please sign in to comment.