From 82448a6c36cf27332739e5a7d9e6d617737d7856 Mon Sep 17 00:00:00 2001 From: iampawan Date: Fri, 14 Jan 2022 18:52:31 +0530 Subject: [PATCH] formatted --- lib/src/flutter/popup_menu.dart | 20 +++--- lib/src/flutter/text.dart | 33 ++++++---- test/flutter/text_test.dart | 107 ++++++++++++++++++++++---------- 3 files changed, 107 insertions(+), 53 deletions(-) diff --git a/lib/src/flutter/popup_menu.dart b/lib/src/flutter/popup_menu.dart index 4dd3a28..75defd8 100644 --- a/lib/src/flutter/popup_menu.dart +++ b/lib/src/flutter/popup_menu.dart @@ -209,23 +209,23 @@ class _VxPopupMenuState extends State { 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; } } }, diff --git a/lib/src/flutter/text.dart b/lib/src/flutter/text.dart index ed3da09..1bd7301 100644 --- a/lib/src/flutter/text.dart +++ b/lib/src/flutter/text.dart @@ -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 with VxColorMixin { +class VxTextBuilder extends VxWidgetBuilder + with VxColorMixin { VxTextBuilder(String this._text) { setChildToColor(this); } @@ -76,7 +77,8 @@ class VxTextBuilder extends VxWidgetBuilder with VxColorMixin this..velocityColor = Vx.hexToColor(colorHex); + VxTextBuilder hexColor(String colorHex) => + this..velocityColor = Vx.hexToColor(colorHex); /// [LayoutBuilder] does not support using IntrinsicWidth or IntrinsicHeight. /// @@ -352,9 +354,11 @@ class VxTextBuilder extends VxWidgetBuilder with VxColorMixin _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; @@ -420,7 +424,8 @@ class VxTextBuilder extends VxWidgetBuilder with VxColorMixin 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; @@ -453,10 +458,12 @@ class VxTextBuilder extends VxWidgetBuilder with VxColorMixin 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; @@ -465,11 +472,15 @@ class VxTextBuilder extends VxWidgetBuilder with VxColorMixin 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, diff --git a/test/flutter/text_test.dart b/test/flutter/text_test.dart index 688ca71..3c3ff2f 100644 --- a/test/flutter/text_test.dart +++ b/test/flutter/text_test.dart @@ -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, ); @@ -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(), @@ -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(), @@ -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(), @@ -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(), @@ -100,13 +105,18 @@ void main() { // Font Weight for medium is 500 expect( - tester.widget(find.byType(AutoSizeText)).style!.fontWeight, + tester + .widget(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(find.byType(AutoSizeText)).style!.fontStyle, @@ -114,56 +124,89 @@ void main() { ); }); - 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(find.byType(AutoSizeText)).textAlign, TextAlign.start); + expect(tester.widget(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(find.byType(AutoSizeText)).style!.letterSpacing, -3.0); + expect( + tester + .widget(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(find.byType(AutoSizeText)).style!.letterSpacing, 4.0); + expect( + tester + .widget(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(find.byType(AutoSizeText)).style!.decoration, + expect( + tester + .widget(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(find.byType(AutoSizeText)).style!.height, 0.875); + expect( + tester.widget(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(find.byType(AutoSizeText)).data, 'VELOCITYX'); + expect(tester.widget(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(find.byType(AutoSizeText)).style!.color, Vx.red300); + expect( + tester.widget(find.byType(AutoSizeText)).style!.color, + Vx.red300); }); }); }