diff --git a/test/accordion_test.dart b/test/accordion_test.dart deleted file mode 100644 index ae354b77..00000000 --- a/test/accordion_test.dart +++ /dev/null @@ -1,212 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - testWidgets('GFAccordion can be created.', (tester) async { - const GFAccordion accordion = GFAccordion( - title: 'title bar', - content: 'content body', - ); - - const TestApp app = TestApp(accordion); - await tester.pumpWidget(app); - - expect(find.text('title bar'), findsOneWidget); - expect(find.text('content body'), findsNothing); - await tester.tap(find.text('title bar')); - await tester.pump(); - expect(find.text('title bar'), findsOneWidget); - expect(find.text('content body'), findsOneWidget); - }); - - testWidgets('GFAccordion can be constructed with child.', (tester) async { - const GFAccordion accordion = GFAccordion( - titleChild: Text('title bar'), - contentChild: Text('content body'), - ); - - const TestApp app = TestApp(accordion); - await tester.pumpWidget(app); - - expect(find.text('title bar'), findsOneWidget); - expect(find.text('content body'), findsNothing); - await tester.tap(find.text('title bar')); - await tester.pump(); - expect(find.text('title bar'), findsOneWidget); - expect(find.text('content body'), findsOneWidget); - }); - - testWidgets( - 'GFAccordion can be constructed with expanded and collapsed icons', - (tester) async { - const GFAccordion accordion = GFAccordion( - titleChild: Text('title bar'), - contentChild: Text('content body'), - collapsedIcon: Icon(Icons.add), - expandedIcon: Icon(Icons.remove), - ); - - const TestApp app = TestApp(accordion); - await tester.pumpWidget(app); - - expect(find.text('title bar'), findsOneWidget); - expect(find.text('content body'), findsNothing); - expect(find.byIcon(Icons.add), findsOneWidget); - await tester.tap(find.text('title bar')); - await tester.pump(); - expect(find.text('title bar'), findsOneWidget); - expect(find.text('content body'), findsOneWidget); - expect(find.byIcon(Icons.remove), findsOneWidget); - }); - - testWidgets('GFAccordion can be constructed with show accordion', - (tester) async { - const GFAccordion accordion = GFAccordion( - titleChild: Text('title bar'), - contentChild: Text('content body'), - showAccordion: true, - ); - - const TestApp app = TestApp(accordion); - await tester.pumpWidget(app); - - expect(find.text('title bar'), findsOneWidget); - expect(find.text('content body'), findsOneWidget); - }); - - testWidgets( - 'GFAccordion can be constructed with show button on toggle collapsed', - (tester) async { - bool showButton = false; - - final accordion = MaterialApp( - home: Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFAccordion( - titleChild: Row( - children: [ - const Text('title bar'), - showButton - ? const GFButton( - onPressed: null, - text: 'Select one', - ) - : Container(), - ], - ), - contentChild: const Text('content body'), - onToggleCollapsed: (value) { - print('collapsed $value'); - setState(() { - showButton = value; - }); - }, - ), - ), - ), - ), - ); - - await tester.pumpWidget(accordion); - - expect(find.text('title bar'), findsOneWidget); - expect(find.text('content body'), findsNothing); - expect(find.text('Select one'), findsNothing); - await tester.tap(find.text('title bar')); - await tester.pump(); - expect(find.text('title bar'), findsOneWidget); - expect(find.text('content body'), findsOneWidget); - expect(find.text('Select one'), findsOneWidget); - }); - - testWidgets('GFAccordion can be constructed with show accordion', - (tester) async { - const GFAccordion accordion = GFAccordion( - titleChild: Text('title bar'), - contentChild: Text('content body'), - showAccordion: true, - ); - - const TestApp app = TestApp(accordion); - await tester.pumpWidget(app); - - expect(find.text('title bar'), findsOneWidget); - expect(find.text('content body'), findsOneWidget); - }); - - testWidgets('GFAccordion with all properties.', (WidgetTester tester) async { - final GFAccordion accordion = GFAccordion( - title: 'title', - content: 'content', - titleChild: const Text('title bar'), - contentChild: const Text('content body'), - textStyle: const TextStyle(color: Colors.deepOrange, fontSize: 16), - collapsedIcon: const Icon(Icons.ac_unit), - expandedIcon: const Icon(Icons.baby_changing_station), - collapsedTitleBackgroundColor: Colors.amber, - expandedTitleBackgroundColor: Colors.greenAccent, - contentBackgroundColor: Colors.tealAccent, - titlePadding: const EdgeInsets.all(13), - contentPadding: const EdgeInsets.all(16), - margin: const EdgeInsets.all(5), - titleBorder: Border.all(color: Colors.blueAccent, width: 1), - contentBorder: Border.all(color: Colors.deepPurpleAccent, width: 1), - titleBorderRadius: const BorderRadius.all(Radius.circular(2)), - contentBorderRadius: const BorderRadius.all(Radius.circular(6)), - showAccordion: true, - onToggleCollapsed: (value) { - print('collapsed $value'); - }, - ); - - final TestApp app = TestApp(accordion); - await tester.pumpWidget(app); - - expect(app.accordion.title, 'title'); - expect(app.accordion.content, 'content'); - expect(app.accordion.textStyle, - const TextStyle(color: Colors.deepOrange, fontSize: 16)); - expect(app.accordion.collapsedTitleBackgroundColor, Colors.amber); - expect(app.accordion.expandedTitleBackgroundColor, Colors.greenAccent); - expect(app.accordion.contentBackgroundColor, Colors.tealAccent); - expect(app.accordion.titlePadding, const EdgeInsets.all(13)); - expect(app.accordion.contentPadding, const EdgeInsets.all(16)); - expect(app.accordion.margin, const EdgeInsets.all(5)); - expect( - app.accordion.titleBorder, - Border.all(color: Colors.blueAccent, width: 1), - ); - expect(app.accordion.contentBorder, - Border.all(color: Colors.deepPurpleAccent, width: 1)); - expect(app.accordion.contentBorder, - Border.all(color: Colors.deepPurpleAccent, width: 1)); - expect(app.accordion.titleBorderRadius, - const BorderRadius.all(Radius.circular(2))); - expect(app.accordion.contentBorderRadius, - const BorderRadius.all(Radius.circular(6))); - expect(app.accordion.showAccordion, isTrue); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.accordion); - final GFAccordion accordion; - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.accordion, - ], - ), - ), - ); -} diff --git a/test/alert_test.dart b/test/alert_test.dart deleted file mode 100644 index 6d5e8bef..00000000 --- a/test/alert_test.dart +++ /dev/null @@ -1,157 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final childWidget = Container( - width: 100, - height: 100, - ); - const bgColor = Colors.teal; - const topBar = Icon(Icons.umbrella); - const bottomBar = Text('Get Widget'); - - testWidgets('GFAlert can be created.', (tester) async { - const GFAlert alert = GFAlert( - backgroundColor: bgColor, content: topBar, bottomBar: bottomBar); - - const TestApp app = TestApp(alert); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.alert.backgroundColor, bgColor); - expect(app.alert.content, topBar); - expect(app.alert.bottomBar, bottomBar); - }); - - testWidgets('Basic GFAlert.', (tester) async { - const basicType = GFAlertType.basic; - - const GFAlert alert = GFAlert( - backgroundColor: bgColor, - content: topBar, - type: basicType, - bottomBar: bottomBar); - - const TestApp app = TestApp(alert); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.alert.backgroundColor, bgColor); - expect(app.alert.content, topBar); - expect(app.alert.type, basicType); - expect(app.alert.bottomBar, bottomBar); - }); - - testWidgets('Rounded GFAlert.', (tester) async { - const roundedType = GFAlertType.rounded; - - const GFAlert alert = - GFAlert(content: topBar, type: roundedType, bottomBar: bottomBar); - - const TestApp app = TestApp(alert); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.alert.content, topBar); - expect(app.alert.type, roundedType); - expect(app.alert.bottomBar, bottomBar); - }); - - testWidgets('FullWidth GFAlert.', (tester) async { - const basicType = GFAlertType.basic; - const fullWidth = 400.0; - - const GFAlert alert = GFAlert( - width: fullWidth, - content: topBar, - type: basicType, - bottomBar: bottomBar); - - const TestApp app = TestApp(alert); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.alert.width, fullWidth); - expect(app.alert.content, topBar); - expect(app.alert.type, basicType); - expect(app.alert.bottomBar, bottomBar); - }); - - testWidgets('Customized GFAlert.', (tester) async { - const basicType = GFAlertType.basic; - final bottomBar = Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - GFButton( - shape: GFButtonShape.square, - color: GFColors.LIGHT, - onPressed: () {}, - child: const Text( - 'Skip', - style: TextStyle(color: Colors.black), - ), - ), - const SizedBox( - width: 5, - ), - GFButton( - shape: GFButtonShape.square, - type: GFButtonType.outline2x, - icon: const Icon( - Icons.keyboard_arrow_right, - color: GFColors.PRIMARY, - ), - position: GFPosition.end, - text: 'Learn More', - onPressed: () {}, - ) - ], - ); - final GFAlert alert = - GFAlert(content: topBar, type: basicType, bottomBar: bottomBar); - - final TestApp app = TestApp(alert); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.alert.content, topBar); - expect(app.alert.type, basicType); - expect(app.alert.bottomBar, bottomBar); - }); - - testWidgets('GFAlert with alignment.', (tester) async { - const alignment = Alignment.bottomRight; - - const GFAlert alert = - GFAlert(content: topBar, alignment: alignment, bottomBar: bottomBar); - - const TestApp app = TestApp(alert); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.alert.content, topBar); - expect(app.alert.alignment, alignment); - expect(app.alert.bottomBar, bottomBar); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.alert); - final GFAlert alert; - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.alert, - ], - ), - ), - ); -} diff --git a/test/animation_test.dart b/test/animation_test.dart deleted file mode 100644 index 18fbb4d8..00000000 --- a/test/animation_test.dart +++ /dev/null @@ -1,514 +0,0 @@ -import 'dart:math' as math; - -import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -class TestPaintingContext implements PaintingContext { - final List invocations = []; - @override - void noSuchMethod(Invocation invocation) { - invocations.add(invocation); - } -} - -void main() { - testWidgets('AnimatedAlign.debugFillProperties', (WidgetTester tester) async { - final GFAnimation box = GFAnimation( - duration: const Duration(seconds: 2), - alignment: Alignment.bottomLeft, - type: GFAnimationType.align, - child: Container( - width: 80, - height: 80, - ), - ); - expect(box, hasOneLineDescription); - }); - - testWidgets('AnimatedAlign alignment visual-to-directional animation', - (WidgetTester tester) async { - final Key alignKey = UniqueKey(); - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.rtl, - child: GFAnimation( - duration: const Duration(milliseconds: 200), - alignment: Alignment.topRight, - type: GFAnimationType.align, - child: SizedBox(key: alignKey, width: 100, height: 200), - ), - ), - ); - - expect(tester.getSize(find.byKey(alignKey)), const Size(100, 200)); - expect(tester.getTopRight(find.byKey(alignKey)), const Offset(800, 0)); - - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.rtl, - child: GFAnimation( - duration: const Duration(milliseconds: 200), - alignment: Alignment.bottomRight, - type: GFAnimationType.align, - child: SizedBox(key: alignKey, width: 100, height: 200), - ), - ), - ); - expect(tester.getSize(find.byKey(alignKey)), const Size(100, 200)); - expect(tester.getTopRight(find.byKey(alignKey)), const Offset(800, 0)); - await tester.pump(const Duration(milliseconds: 100)); - expect(tester.getSize(find.byKey(alignKey)), const Size(100, 200)); - expect(tester.getTopRight(find.byKey(alignKey)), const Offset(800, 200)); - await tester.pump(const Duration(milliseconds: 500)); - expect(tester.getSize(find.byKey(alignKey)), const Size(100, 200)); - expect(tester.getTopRight(find.byKey(alignKey)), const Offset(800, 400)); - }); - - testWidgets('AnimatedContainer.debugFillProperties', - (WidgetTester tester) async { - final GFAnimation container = GFAnimation( - width: 50, - changedWidth: 100, - height: 50, - changedHeight: 100, - activeColor: Colors.transparent, - color: Colors.transparent, - fontSize: 35, - type: GFAnimationType.container, - child: Container( - width: 80, - height: 80, - ), - ); - expect(container, hasOneLineDescription); - }); - - testWidgets('AnimatedContainer test animation control ', - (WidgetTester tester) async { - final GlobalKey key = GlobalKey(); - - final GFAnimation animate = GFAnimation( - key: key, - duration: const Duration(milliseconds: 300), - color: Colors.amberAccent, - width: 50, - changedWidth: 100, - height: 50, - changedHeight: 100, - activeColor: Colors.transparent, - fontSize: 35, - type: GFAnimationType.container, - child: Container( - width: 80, - height: 80, - ), - ); - - final TestApp app = TestApp(animate); - - await tester.pumpWidget(app); - expect(app.animate.color, equals(Colors.amberAccent)); - await tester.pump(const Duration(seconds: 1)); - }); - - testWidgets('AnimatedContainer testing over animate ', - (WidgetTester tester) async { - await tester.pumpWidget(const GFAnimation( - duration: Duration(milliseconds: 300), - type: GFAnimationType.container, - color: Colors.teal, - child: SizedBox( - width: 45, - height: 45, - ), - )); - expect(tester.binding.transientCallbackCount, 0); - await tester.pump(const Duration(seconds: 1)); - expect(tester.binding.transientCallbackCount, 0); - await tester.pumpWidget(const GFAnimation( - duration: Duration(milliseconds: 300), - type: GFAnimationType.container, - color: Colors.teal, - child: SizedBox( - width: 45, - height: 45, - ), - )); - expect(tester.binding.transientCallbackCount, 0); - await tester.pump(const Duration(seconds: 1)); - expect(tester.binding.transientCallbackCount, 0); - await tester.pumpWidget(const GFAnimation( - duration: Duration(milliseconds: 300), - type: GFAnimationType.container, - color: Colors.teal, - child: SizedBox( - width: 45, - height: 45, - ), - )); - expect(tester.binding.transientCallbackCount, - 0); // this is the only time an animation should have started! - await tester.pump(const Duration(seconds: 1)); - expect(tester.binding.transientCallbackCount, 0); - await tester.pumpWidget(const GFAnimation( - duration: Duration(milliseconds: 300), - type: GFAnimationType.container, - color: Colors.teal, - child: SizedBox( - width: 45, - height: 45, - ), - )); - expect(tester.binding.transientCallbackCount, 0); - }); - - testWidgets('AnimatedContainer alignment visual-to-directional animation', - (WidgetTester tester) async { - final Key target = UniqueKey(); - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.rtl, - child: GFAnimation( - duration: const Duration(milliseconds: 200), - alignment: Alignment.topRight, - type: GFAnimationType.container, - child: SizedBox(key: target, width: 100, height: 200), - ), - ), - ); - expect(tester.getSize(find.byKey(target)), const Size(100, 200)); - expect(tester.getTopRight(find.byKey(target)), const Offset(792, 8)); - await tester.pumpWidget( - Directionality( - textDirection: TextDirection.rtl, - child: GFAnimation( - duration: const Duration(milliseconds: 200), - alignment: Alignment.bottomRight, - type: GFAnimationType.container, - child: SizedBox(key: target, width: 100, height: 200), - ), - ), - ); - expect(tester.getSize(find.byKey(target)), const Size(100, 200)); - expect(tester.getTopRight(find.byKey(target)), const Offset(792, 8)); - await tester.pump(const Duration(milliseconds: 100)); - expect(tester.getSize(find.byKey(target)), const Size(100, 200)); - expect(tester.getTopRight(find.byKey(target)), const Offset(792, 200)); - await tester.pump(const Duration(milliseconds: 500)); - expect(tester.getSize(find.byKey(target)), const Size(100, 200)); - expect(tester.getTopRight(find.byKey(target)), const Offset(792, 392)); - }); - - testWidgets('Animation rerun', (WidgetTester tester) async { - await tester.pumpWidget(Center( - child: GFAnimation( - duration: const Duration(milliseconds: 200), - type: GFAnimationType.container, - child: Container( - child: const Text('X', textDirection: TextDirection.ltr), - width: 100, - height: 100, - )))); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 100)); - RenderBox text = tester.renderObject(find.text('X')); - expect(text.size.width, equals(84)); - expect(text.size.height, equals(84)); - await tester.pump(const Duration(milliseconds: 1000)); - await tester.pumpWidget(Center( - child: GFAnimation( - duration: const Duration(milliseconds: 200), - type: GFAnimationType.container, - child: Container( - child: const Text('X', textDirection: TextDirection.ltr), - width: 200, - height: 200, - )))); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 100)); - text = tester.renderObject(find.text('X')); - expect(text.size.width, greaterThan(60)); - expect(text.size.width, lessThan(220)); - expect(text.size.height, greaterThan(60)); - expect(text.size.height, lessThan(220)); - await tester.pump(const Duration(milliseconds: 1000)); - expect(text.size.width, equals(84)); - expect(text.size.height, equals(84)); - await tester.pumpWidget(Center( - child: GFAnimation( - duration: const Duration(milliseconds: 200), - child: Container( - child: const Text('X', textDirection: TextDirection.ltr), - width: 200, - height: 200, - )))); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 100)); - expect(text.size.width, equals(84)); - expect(text.size.height, greaterThan(60)); - expect(text.size.height, lessThan(190)); - await tester.pump(const Duration(milliseconds: 1000)); - expect(text.size.width, equals(84)); - expect(text.size.height, equals(84)); - }); - - // --------------------------- size - - testWidgets('animates forwards then backwards with stable-sized children', - (WidgetTester tester) async { - await tester.pumpWidget( - const Center( - child: GFAnimation( - type: GFAnimationType.size, - duration: Duration(milliseconds: 200), - child: SizedBox( - width: 100, - height: 100, - ), - ), - ), - ); - RenderBox box = tester.renderObject(find.byType(AnimatedSize)); - expect(box.size.width, equals(100)); - expect(box.size.height, equals(100)); - await tester.pumpWidget( - const Center( - child: GFAnimation( - width: 200, - height: 200, - duration: Duration(milliseconds: 200), - type: GFAnimationType.size, - child: SizedBox( - width: 200, - height: 200, - ), - ), - ), - ); - await tester.pump(const Duration(milliseconds: 100)); - box = tester.renderObject(find.byType(AnimatedSize)); - expect(box.size.width, equals(150)); - expect(box.size.height, equals(150)); - TestPaintingContext context = TestPaintingContext(); - box.paint(context, Offset.zero); - expect(context.invocations.first.memberName, equals(#pushClipRect)); - await tester.pump(const Duration(milliseconds: 100)); - box = tester.renderObject(find.byType(AnimatedSize)); - expect(box.size.width, equals(200)); - expect(box.size.height, equals(200)); - await tester.pumpWidget( - const Center( - child: GFAnimation( - duration: Duration(milliseconds: 200), - type: GFAnimationType.size, - width: 200, - height: 200, - child: SizedBox( - width: 100, - height: 100, - ), - ), - ), - ); - await tester.pump(const Duration(milliseconds: 100)); - box = tester.renderObject(find.byType(AnimatedSize)); - expect(box.size.width, equals(200)); - expect(box.size.height, equals(200)); - context = TestPaintingContext(); - box.paint(context, Offset.zero); - expect(context.invocations.first.memberName, equals(#paintChild)); - await tester.pump(const Duration(milliseconds: 100)); - box = tester.renderObject(find.byType(AnimatedSize)); - expect(box.size.width, equals(200)); - expect(box.size.height, equals(200)); - }); - - testWidgets('clamps animated size to constraints', - (WidgetTester tester) async { - await tester.pumpWidget( - const Center( - child: SizedBox( - width: 100, - height: 100, - child: GFAnimation( - duration: Duration(milliseconds: 200), - type: GFAnimationType.size, - child: SizedBox( - width: 100, - height: 100, - ), - ), - ), - ), - ); - RenderBox box = tester.renderObject(find.byType(AnimatedSize)); - expect(box.size.width, equals(100)); - expect(box.size.height, equals(100)); - // Attempt to animate beyond the outer SizedBox. - await tester.pumpWidget( - const Center( - child: SizedBox( - width: 100, - height: 100, - child: GFAnimation( - duration: Duration(milliseconds: 200), - type: GFAnimationType.size, - child: SizedBox( - width: 200, - height: 200, - ), - ), - ), - ), - ); - // Verify that animated size is the same as the outer SizedBox. - await tester.pump(const Duration(milliseconds: 100)); - box = tester.renderObject(find.byType(AnimatedSize)); - expect(box.size.width, equals(100)); - expect(box.size.height, equals(100)); - }); - - testWidgets('resyncs its animation controller', (WidgetTester tester) async { - await tester.pumpWidget( - const Center( - child: AnimatedSize( - duration: Duration(milliseconds: 200), - child: SizedBox( - width: 100, - height: 100, - ), - ), - ), - ); - await tester.pumpWidget( - const Center( - child: GFAnimation( - duration: Duration(milliseconds: 200), - type: GFAnimationType.size, - child: SizedBox( - width: 200, - height: 100, - ), - ), - ), - ); - await tester.pump(const Duration(milliseconds: 100)); - final RenderBox box = tester.renderObject(find.byType(AnimatedSize)); - expect(box.size.width, equals(100)); - }); - testWidgets('does not run animation unnecessarily', - (WidgetTester tester) async { - await tester.pumpWidget( - const Center( - child: GFAnimation( - duration: Duration(milliseconds: 200), - type: GFAnimationType.size, - child: SizedBox( - width: 100, - height: 100, - ), - ), - ), - ); - for (int i = 0; i < 20; i++) { - final RenderAnimatedSize box = - tester.renderObject(find.byType(AnimatedSize)); - expect(box.size.width, 100); - expect(box.size.height, 100); - expect(box.state, RenderAnimatedSizeState.stable); - expect(box.isAnimating, false); - await tester.pump(const Duration(milliseconds: 10)); - } - }); - - testWidgets('RotationTransition maintains chosen alignment during animation', - (WidgetTester tester) async { - AnimationController controller; - Animation animation; - - controller = AnimationController( - duration: const Duration(seconds: 5), vsync: const TestVSync()); - animation = CurvedAnimation(parent: controller, curve: Curves.linear); - - final Widget widget = GFAnimation( - turnsAnimation: animation, - controller: controller, - type: GFAnimationType.rotateTransition, - alignment: Alignment.topRight, - child: const Text('Rotation', textDirection: TextDirection.ltr), - ); - - await tester.pumpWidget(widget); - RotationTransition actualRotatedBox = - tester.widget(find.byType(RotationTransition)); - Alignment actualAlignment = actualRotatedBox.alignment; - expect(actualAlignment, Alignment.topRight); - - controller.value = 0.5; - await tester.pump(); - actualRotatedBox = tester.widget(find.byType(RotationTransition)); - actualAlignment = actualRotatedBox.alignment; - expect(actualAlignment, Alignment.topRight); - }); - - testWidgets('RotationTransition animates', (WidgetTester tester) async { - AnimationController controller; - Animation animation; - - controller = AnimationController( - duration: const Duration(seconds: 5), vsync: const TestVSync()); - animation = CurvedAnimation(parent: controller, curve: Curves.linear); - - final Widget widget = GFAnimation( - turnsAnimation: animation, - controller: controller, - type: GFAnimationType.rotateTransition, - alignment: Alignment.topRight, - child: const Text('Rotation', textDirection: TextDirection.ltr), - ); - - await tester.pumpWidget(widget); - Transform actualRotatedBox = tester.widget(find.byType(Transform)); - Matrix4 actualTurns = actualRotatedBox.transform; - expect(actualTurns, equals(Matrix4.rotationZ(0))); - - controller.value = 0.5; - await tester.pump(); - actualRotatedBox = tester.widget(find.byType(Transform)); - actualTurns = actualRotatedBox.transform; - expect(actualTurns, Matrix4.rotationZ(math.pi)); - - controller.value = 0.75; - await tester.pump(); - actualRotatedBox = tester.widget(find.byType(Transform)); - actualTurns = actualRotatedBox.transform; - expect(actualTurns, Matrix4.rotationZ(math.pi * 1.5)); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.animate); - - final GFAnimation animate; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - bool fav = false; - - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.animate, - ], - ), - ), - ); -} diff --git a/test/appbar_test.dart b/test/appbar_test.dart deleted file mode 100644 index d80a978f..00000000 --- a/test/appbar_test.dart +++ /dev/null @@ -1,365 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - const title = Text('Appbar'); - final leading = GFIconButton( - icon: const Icon( - Icons.wb_sunny, - color: GFColors.WHITE, - ), - onPressed: () {}, - type: GFButtonType.transparent, - ); - final actionButton = GFIconButton( - icon: const Icon( - Icons.favorite, - color: GFColors.WHITE, - ), - onPressed: () {}, - type: GFButtonType.transparent, - ); - final flexibleSpace = Container(color: Colors.amber); - final shape = RoundedRectangleBorder( - side: const BorderSide( - color: Colors.tealAccent, width: 1, style: BorderStyle.solid), - borderRadius: BorderRadius.circular(25)); - - final bottom = PreferredSize( - child: Container( - color: Colors.orange, - height: 4, - ), - preferredSize: const Size.fromHeight(4)); - - const textTheme = - TextTheme(headlineSmall: TextStyle(color: Colors.tealAccent)); - const iconTheme = IconThemeData(color: Colors.red); - const actionsIconTheme = IconThemeData(color: Colors.amber); - - testWidgets('GF AppBar can be constructed', (tester) async { - final GFAppBar appbar = GFAppBar(); - - final TestApp app = TestApp(appbar); - - await tester.pumpWidget(app); - }); - - testWidgets('GF AppBar can be constructed with title, leading and actions', - (tester) async { - final GFAppBar appbar = GFAppBar( - leading: leading, - title: title, - actions: [actionButton], - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - expect(find.text('Appbar'), findsOneWidget); - expect(find.byIcon(Icons.wb_sunny), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - - expect(app.appbar.leading, leading); - expect(app.appbar.title, title); - expect(app.appbar.actions!.length, 1); - }); - - testWidgets('GF AppBar with title with no titleSpace', (tester) async { - // when GFAppBar.titleSpacing is 0, title takes all the space available - // with or without leading and actions - final GFAppBar appbar = GFAppBar( - leading: leading, - title: title, - titleSpacing: 0, - actions: [actionButton], - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - expect(find.text('Appbar'), findsOneWidget); - expect(find.byIcon(Icons.wb_sunny), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - - expect(app.appbar.leading, leading); - expect(app.appbar.title, title); - expect(app.appbar.actions!.length, 1); - expect(app.appbar.titleSpacing, 0); - }); - - testWidgets('GF AppBar with centerTitle', (tester) async { - // when GFAppBar.centerTitle is true, title will align at center. - final GFAppBar appbar = GFAppBar( - leading: leading, - title: title, - actions: [actionButton], - centerTitle: true, - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - expect(find.text('Appbar'), findsOneWidget); - expect(find.byIcon(Icons.wb_sunny), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - - expect(app.appbar.leading, leading); - expect(app.appbar.title, title); - expect(app.appbar.actions!.length, 1); - expect(app.appbar.centerTitle, true); - }); - - testWidgets('GF AppBar with automaticallyImplyLeading', (tester) async { - // when GFAppBar.automaticallyImplyLeading is true and [leading] is null, automatically try to deduce what the leading - // widget should be. If false and [leading] is null, leading space is given to [title]. - // If leading widget is not null, this parameter has no effect. - final GFAppBar appbar = GFAppBar( - title: title, - actions: [actionButton], - automaticallyImplyLeading: true, - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - expect(find.text('Appbar'), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - - expect(app.appbar.title, title); - expect(app.appbar.actions!.length, 1); - expect(app.appbar.automaticallyImplyLeading, true); - }); - - testWidgets('GF AppBar with flexibleSpace', (tester) async { - // GFAppbar.flexibleSpace stacked behind the toolbar and the tab bar. It's height will - // be the same as the app bar's overall height. A flexible space isn't actually - // flexible unless the [GFAppBar]'s container changes the [GFAppBar]'s size. - final GFAppBar appbar = GFAppBar( - title: title, - actions: [actionButton], - flexibleSpace: flexibleSpace, - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - expect(find.text('Appbar'), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - expect(find.byWidget(flexibleSpace), findsOneWidget); - - expect(app.appbar.title, title); - expect(app.appbar.actions!.length, 1); - expect(app.appbar.flexibleSpace, flexibleSpace); - }); - - testWidgets('GF AppBar with primary and brightness', (tester) async { - // GFAppbar.primary on false displays title at the top of the screen. - // If true, the app bar's toolbar elements and [bottom] widget will be - // padded on top by the height of the system status bar. - - final GFAppBar appbar = GFAppBar( - title: title, - primary: false, - brightness: Brightness.dark, - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - expect(find.text('Appbar'), findsOneWidget); - - expect(app.appbar.title, title); - expect(app.appbar.primary, false); - expect(app.appbar.brightness, Brightness.dark); - }); - - testWidgets('GF AppBar with backgroundColor and shape', (tester) async { - // GFAppbar.shape to customize shape of the appbar - final GFAppBar appbar = GFAppBar( - title: title, - actions: [actionButton], - backgroundColor: Colors.teal, - shape: shape, - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - expect(find.text('Appbar'), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - - expect(app.appbar.title, title); - expect(app.appbar.actions!.length, 1); - expect(app.appbar.backgroundColor, Colors.teal); - expect(app.appbar.shape, shape); - }); - - testWidgets('GF AppBar with bottom and elevation', (tester) async { - final GFAppBar appbar = GFAppBar( - title: title, - actions: [actionButton], - bottom: bottom, - elevation: 1, - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - expect(find.text('Appbar'), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - expect(find.byWidget(bottom), findsOneWidget); - - expect(app.appbar.title, title); - expect(app.appbar.actions!.length, 1); - expect(app.appbar.bottom, bottom); - expect(app.appbar.elevation, 1); - }); - - testWidgets('GF AppBar with textTheme, iconTheme, actionsIconTheme', - (tester) async { - const leadingIcon = Icon(Icons.wb_sunny); - - final GFAppBar appbar = GFAppBar( - leading: leadingIcon, - title: title, - actions: const [Icon(Icons.favorite)], - textTheme: textTheme, - actionsIconTheme: actionsIconTheme, - iconTheme: iconTheme, - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - expect(find.text('Appbar'), findsOneWidget); - expect(find.byIcon(Icons.wb_sunny), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - - expect(app.appbar.leading, leadingIcon); - expect(app.appbar.title, title); - expect(app.appbar.actions!.length, 1); - expect(app.appbar.textTheme, textTheme); - expect(app.appbar.actionsIconTheme, actionsIconTheme); - expect(app.appbar.iconTheme, iconTheme); - }); - testWidgets( - 'GF AppBar with bottomOpacity, toolbarOpacity and test searchBar with default searchBar value', - (tester) async { - final GFAppBar appbar = GFAppBar( - title: title, - actions: [actionButton], - bottomOpacity: 0.5, - toolbarOpacity: 0.6, - bottom: bottom, - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - expect(find.text('Appbar'), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - expect(find.byWidget(bottom), findsOneWidget); - - expect(app.appbar.title, title); - expect(app.appbar.actions!.length, 1); - expect(app.appbar.bottom, bottom); - expect(app.appbar.bottomOpacity, 0.5); - expect(app.appbar.toolbarOpacity, 0.6); - // set appbar.searchBar = false state to disable search bar - expect(app.appbar.searchBar, isFalse); - // try to find search icon when appbar.searchBar = false - expect(find.byIcon(Icons.search), findsNothing); - }); - - testWidgets('GF AppBar with searchBar', (tester) async { - final Key appbarKey = UniqueKey(); - final TextEditingController _searchController = TextEditingController(); - - final GFAppBar appbar = GFAppBar( - key: appbarKey, - title: title, - actions: [actionButton], - searchBar: true, - searchController: _searchController, - searchHintText: 'Search', - searchHintStyle: const TextStyle(fontSize: 14, color: Colors.white70), - searchTextStyle: const TextStyle(fontSize: 16, color: Colors.white), - searchBarColorTheme: Colors.white, - onChanged: (value) { - print('on change $value'); - }, - onSubmitted: (value) { - print('submitted $value'); - }, - onTap: () { - print('tapped'); - }, - ); - - final TestApp app = TestApp(appbar); - await tester.pumpWidget(app); - - // find appbar by key - expect(find.byKey(appbarKey), findsOneWidget); - // find appbar title text - expect(find.text('Appbar'), findsOneWidget); - // find appbar action button icon - expect(find.byIcon(Icons.favorite), findsOneWidget); - // set appbar.searchBar = true state to enable search bar - expect(app.appbar.searchBar, isTrue); - // find appbar search icon - expect(find.byIcon(Icons.search), findsOneWidget); - // tap the search icon - await tester.tap(find.byIcon(Icons.search)); - // rebuild the widget - await tester.pump(); - // enter 'flutter' to the textField - await tester.enterText(find.byWidget(appbar), 'flutter'); - // find the text 'flutter' to test onChanged - expect(find.text('flutter'), findsOneWidget); - // to test onSubmitted when TextInputAction.done - await tester.testTextInput.receiveAction(TextInputAction.done); - // rebuild the widget - await tester.pump(); - // find the text 'flutter' in textField - expect(find.text('flutter'), findsOneWidget); - // tap the close icon to close the searchBar - await tester.tap(find.byIcon(Icons.close)); - // rebuild the widget - await tester.pump(); - // try to find textField - expect(find.byType(TextField), findsNothing); - // tap the search icon to reopen the searchBar - await tester.tap(find.byIcon(Icons.search)); - // rebuild the widget - await tester.pump(); - // find the text 'flutter' in textField - expect(find.text('flutter'), findsNothing); - // tap the textField to test onTap - await tester.tap(find.byType(TextField)); - // rebuild the widget - await tester.pump(); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.appbar); - - final GFAppBar appbar; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - appBar: widget.appbar, - body: Container( - child: const Text('body'), - )), - ); -} diff --git a/test/avatar_test.dart b/test/avatar_test.dart deleted file mode 100644 index 10beb886..00000000 --- a/test/avatar_test.dart +++ /dev/null @@ -1,118 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final childWidget = Container( - width: 60, - height: 60, - ); - const bgColor = Colors.teal; - const fgColor = Colors.transparent; - - testWidgets('GFAvatar can be created', (tester) async { - final GFAvatar avatar = GFAvatar( - backgroundColor: bgColor, - foregroundColor: fgColor, - size: GFSize.MEDIUM, - child: childWidget); - final TestApp app = TestApp(avatar); - await tester.pumpWidget(app); - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.avatar.backgroundColor, bgColor); - expect(app.avatar.foregroundColor, fgColor); - expect(app.avatar.size, GFSize.MEDIUM); - expect(app.avatar.child, childWidget); - }); - - testWidgets('GFAvatar with minRadius & maxRadius', (tester) async { - const minRadius = 10.0; - const maxRadius = 20.0; - final GFAvatar avatar = GFAvatar( - backgroundColor: bgColor, - foregroundColor: fgColor, - minRadius: minRadius, - maxRadius: maxRadius, - size: GFSize.MEDIUM, - child: childWidget); - final TestApp app = TestApp(avatar); - await tester.pumpWidget(app); - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.avatar.backgroundColor, bgColor); - expect(app.avatar.foregroundColor, fgColor); - expect(app.avatar.minRadius, minRadius); - expect(app.avatar.maxRadius, maxRadius); - expect(app.avatar.size, GFSize.MEDIUM); - expect(app.avatar.child, childWidget); - }); - - testWidgets('Circular GFAvatar with bgImage', (tester) async { - const bgImage = NetworkImage( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - - const GFAvatar avatar = GFAvatar( - backgroundImage: bgImage, - shape: GFAvatarShape.circle, - ); - - const TestApp app = TestApp(avatar); - - expect(app.avatar.backgroundImage, bgImage); - expect(app.avatar.shape, GFAvatarShape.circle); - }); - - testWidgets('Square GFAvatar with bgImage', (tester) async { - const bgImage = NetworkImage( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - - const GFAvatar avatar = GFAvatar( - backgroundImage: bgImage, - shape: GFAvatarShape.square, - ); - - const TestApp app = TestApp(avatar); - - expect(app.avatar.backgroundImage, bgImage); - expect(app.avatar.shape, GFAvatarShape.square); - }); - - testWidgets('Standard shape GFAvatar with bgImage', (tester) async { - const bgImage = NetworkImage( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - - const GFAvatar avatar = GFAvatar( - backgroundImage: bgImage, - shape: GFAvatarShape.standard, - ); - - const TestApp app = TestApp(avatar); - - expect(app.avatar.backgroundImage, bgImage); - expect(app.avatar.shape, GFAvatarShape.standard); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.avatar); - final GFAvatar avatar; - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.avatar, - ], - ), - ), - ); -} diff --git a/test/badge_test.dart b/test/badge_test.dart deleted file mode 100644 index 4dbfb70a..00000000 --- a/test/badge_test.dart +++ /dev/null @@ -1,150 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - const text = '1'; - const textStyle = TextStyle(fontSize: 14, color: Colors.black); - const size = GFSize.SMALL; - const textColor = GFColors.INFO; - const color = Colors.amber; - const border = - BorderSide(color: Colors.tealAccent, width: 1, style: BorderStyle.solid); - const shape = RoundedRectangleBorder( - side: BorderSide(color: Colors.pink, width: 2, style: BorderStyle.solid), - borderRadius: BorderRadius.zero); - const childWidget = Text('hey'); - - testWidgets('GF Badge can be constructed', (tester) async { - const GFBadge badge = GFBadge( - text: text, - textStyle: textStyle, - size: size, - ); - - const TestApp app = TestApp(badge); - - await tester.pumpWidget(app); - - expect(find.text('1'), findsOneWidget); - - expect(app.badge.text, text); - expect(app.badge.textStyle, textStyle); - expect(app.badge.size, size); - - await tester.pumpWidget(app); - }); - - testWidgets('GF Badge with color and textColor', (tester) async { - const GFBadge badge = GFBadge( - text: text, - size: size, - textColor: textColor, - color: color, - ); - - const TestApp app = TestApp(badge); - - await tester.pumpWidget(app); - - expect(find.text('1'), findsOneWidget); - - expect(app.badge.text, text); - expect(app.badge.size, size); - expect(app.badge.textColor, textColor); - expect(app.badge.color, color); - - await tester.pumpWidget(app); - }); - - testWidgets( - 'GF Badge with GFBadgeShape like circle, standard, square and pills', - (tester) async { - const GFBadge badge = GFBadge( - text: text, - size: size, - textColor: textColor, - color: color, - shape: GFBadgeShape.circle, - ); - - const TestApp app = TestApp(badge); - - await tester.pumpWidget(app); - - expect(find.text('1'), findsOneWidget); - - expect(app.badge.text, text); - expect(app.badge.size, size); - expect(app.badge.textColor, textColor); - expect(app.badge.color, color); - expect(app.badge.shape, GFBadgeShape.circle); - - await tester.pumpWidget(app); - }); - - testWidgets('GF Badge with custom border and shape', (tester) async { - const GFBadge badge = GFBadge( - text: text, - size: size, - textColor: textColor, - color: color, - borderShape: shape, - border: border, - ); - - const TestApp app = TestApp(badge); - - await tester.pumpWidget(app); - - expect(find.text('1'), findsOneWidget); - - expect(app.badge.text, text); - expect(app.badge.size, size); - expect(app.badge.textColor, textColor); - expect(app.badge.color, color); - expect(app.badge.borderShape, shape); - expect(app.badge.border, border); - - await tester.pumpWidget(app); - }); - - testWidgets('GF Badge with custom child', (tester) async { - const GFBadge badge = GFBadge( - child: childWidget, - size: size, - ); - - const TestApp app = TestApp(badge); - - await tester.pumpWidget(app); - - expect(find.text('hey'), findsOneWidget); - - expect(app.badge.child, childWidget); - - await tester.pumpWidget(app); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.badge); - - final GFBadge badge; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.badge, - ], - ), - ), - ); -} diff --git a/test/border_test.dart b/test/border_test.dart deleted file mode 100644 index 2baa2460..00000000 --- a/test/border_test.dart +++ /dev/null @@ -1,275 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final childWidget = Container( - width: 222, - height: 333, - ); - const color = Colors.teal; - const padding = EdgeInsets.all(5); - const type = GFBorderType.rect; - const text = Text('Hello'); - - testWidgets('GFBorder can be created around different components.', - (tester) async { - final GFBorder border = GFBorder( - color: color, - padding: padding, - type: type, - dashedLine: const [2, 0], - child: childWidget); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.padding, padding); - expect(app.border.type, type); - expect(app.border.dashedLine, [2, 0]); - expect(app.border.child, childWidget); - }); - - testWidgets('Solid GFBorder around image.', (tester) async { - final bgImage = Image.network( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - final GFBorder border = GFBorder( - color: color, type: type, dashedLine: const [2, 0], child: bgImage); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, type); - expect(app.border.dashedLine, [2, 0]); - expect(app.border.child, bgImage); - }); - - testWidgets('Solid GFBorder with radius.', (tester) async { - const radius = Radius.circular(20); - - final GFBorder border = GFBorder( - color: color, - type: GFBorderType.rRect, - dashedLine: const [2, 0], - radius: radius, - child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.rRect); - expect(app.border.dashedLine, [2, 0]); - expect(app.border.child, text); - }); - - testWidgets('Oval GFBorder.', (tester) async { - const stroke = 2.0; - - final GFBorder border = GFBorder( - color: color, - type: GFBorderType.oval, - dashedLine: const [6, 0], - strokeWidth: stroke, - child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.oval); - expect(app.border.dashedLine, [6, 0]); - expect(app.border.strokeWidth, stroke); - expect(app.border.child, text); - }); - - testWidgets('Circular GFBorder.', (tester) async { - const stroke = 2.0; - final GFBorder border = GFBorder( - color: color, - type: GFBorderType.circle, - dashedLine: const [2, 0], - strokeWidth: stroke, - child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.circle); - expect(app.border.dashedLine, [2, 0]); - expect(app.border.strokeWidth, stroke); - expect(app.border.child, text); - }); - - testWidgets('Dashed GFBorder.', (tester) async { - final GFBorder border = - GFBorder(color: color, type: GFBorderType.rRect, child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.rRect); - expect(app.border.child, text); - }); - - testWidgets('Dashed GFBorder with radius.', (tester) async { - const radius = Radius.circular(20); - - final GFBorder border = GFBorder( - color: color, type: GFBorderType.rRect, radius: radius, child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.rRect); - expect(app.border.radius, radius); - expect(app.border.child, text); - }); - - testWidgets('Oval dashed GFBorder.', (tester) async { - const stroke = 2.0; - - final GFBorder border = GFBorder( - color: color, - type: GFBorderType.oval, - strokeWidth: stroke, - dashedLine: const [3, 1], - child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.oval); - expect(app.border.strokeWidth, stroke); - expect(app.border.dashedLine, [3, 1]); - expect(app.border.child, text); - }); - - testWidgets('Circular dashed GFBorder.', (tester) async { - const stroke = 2.0; - - final GFBorder border = GFBorder( - color: color, - type: GFBorderType.circle, - dashedLine: const [3, 1], - strokeWidth: stroke, - child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.circle); - expect(app.border.dashedLine, [3, 1]); - expect(app.border.strokeWidth, stroke); - expect(app.border.child, text); - }); - - testWidgets('Dotted GFBorder.', (tester) async { - final GFBorder border = GFBorder( - color: color, - type: GFBorderType.rect, - dashedLine: const [2, 1], - child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.rect); - expect(app.border.dashedLine, [2, 1]); - expect(app.border.child, text); - }); - - testWidgets('Dotted GFBorder with radius.', (tester) async { - const radius = Radius.circular(20); - - final GFBorder border = GFBorder( - color: color, - type: GFBorderType.rRect, - dashedLine: const [2, 1], - radius: radius, - child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.rRect); - expect(app.border.dashedLine, [2, 1]); - expect(app.border.radius, radius); - expect(app.border.child, text); - }); - - testWidgets('Oval dotted GFBorder.', (tester) async { - final GFBorder border = GFBorder( - color: color, - type: GFBorderType.oval, - dashedLine: const [2, 1], - child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.oval); - expect(app.border.dashedLine, [2, 1]); - expect(app.border.child, text); - }); - - testWidgets('Circular dotted GFBorder.', (tester) async { - final GFBorder border = GFBorder( - color: color, - type: GFBorderType.circle, - dashedLine: const [2, 1], - child: text); - - final TestApp app = TestApp(border); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.border.color, color); - expect(app.border.type, GFBorderType.circle); - expect(app.border.dashedLine, [2, 1]); - expect(app.border.child, text); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.border); - final GFBorder border; - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.border, - ], - ), - ), - ); -} diff --git a/test/bottom_sheet_test.dart b/test/bottom_sheet_test.dart deleted file mode 100644 index f2d423b1..00000000 --- a/test/bottom_sheet_test.dart +++ /dev/null @@ -1,307 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final Key bottomSheetKey = UniqueKey(); - final Key contentKey = UniqueKey(); - final GFBottomSheetController _controller = GFBottomSheetController(); - - testWidgets('GFBottomSheet can be constructed', (tester) async { - final GFBottomSheet bottomSheet = GFBottomSheet( - key: bottomSheetKey, - controller: _controller, - stickyHeaderHeight: 70, - stickyHeader: const GFListTile( - avatar: GFAvatar( - backgroundColor: Colors.amber, - ), - titleText: 'Header Title', - subTitleText: '11 minutes ago', - ), - contentBody: ListView( - shrinkWrap: true, - physics: const ScrollPhysics(), - children: [ - ListView.builder( - shrinkWrap: true, - physics: const ScrollPhysics(), - scrollDirection: Axis.vertical, - itemCount: 3, - itemBuilder: (BuildContext context, int index) => GFListTile( - color: Colors.black12, - avatar: const GFAvatar( - backgroundColor: Colors.tealAccent, - size: 20, - ), - subTitleText: 'Content Title', - icon: GFButton( - onPressed: () {}, - color: Colors.teal, - child: const Text( - 'Send', - style: TextStyle(color: Colors.white), - ), - ), - ), - ), - const Text('Content'), - ], - ), - ); - - final TestApp app = TestApp(bottomSheet); - await tester.pumpWidget(app); - - // find bottom sheet by key - expect(find.byKey(bottomSheetKey), findsOneWidget); - // find header tile text - expect(find.text('Header Title'), findsOneWidget); - // tap on header tile to open bottomSheet - await tester.tap(find.text('Header Title')); - await tester.pump(); - await tester.pump(const Duration(seconds: 2)); - // find the content tile - expect(find.text('Content Title'), findsNWidgets(3)); - // tap on header tile to close bottomSheet - await tester.tap(find.text('Header Title')); - await tester.pump(); - await tester.pump(const Duration(seconds: 2)); - // try to find content finds nothing - expect(find.text('Content Title'), findsNothing); - // Swipe the header tile to open bottomSheet - await tester.drag(find.text('Header Title'), const Offset(0, -4.6)); - await tester.pumpAndSettle(); - // find the content tile - expect(find.text('Content Title'), findsNWidgets(3)); - // Swipe the header tile to close bottomSheet - await tester.drag(find.text('Header Title'), const Offset(0, 6.5)); - await tester.pumpAndSettle(); - await tester.pump(const Duration(seconds: 2)); - // try to find content finds nothing - expect(find.text('Content Title'), findsNothing); - - // Swipe the header tile to open bottomSheet - await tester.drag(find.text('Header Title'), const Offset(0, -4.6)); - await tester.pumpAndSettle(); - await tester.pump(const Duration(seconds: 2)); - // find the content tile - expect(find.text('Content Title'), findsNWidgets(3)); - // Swipe the content tile to close bottomSheet - await tester.drag(find.text('Content'), const Offset(0, 6.5)); - await tester.pumpAndSettle(); - await tester.pump(const Duration(seconds: 2)); - // try to find content finds nothing - expect(find.text('Content Title'), findsNothing); - }); - - testWidgets('GFBottomSheet can be constructed with footer', (tester) async { - final GFBottomSheet bottomSheet = GFBottomSheet( - key: bottomSheetKey, - controller: _controller, - stickyHeaderHeight: 70, - stickyHeader: const GFListTile( - avatar: GFAvatar( - backgroundColor: Colors.amber, - ), - titleText: 'Header Title', - subTitleText: '11 minutes ago', - ), - contentBody: ListView( - shrinkWrap: true, - physics: const ScrollPhysics(), - children: [ - const Text('Content GetWidget'), - Container( - padding: const EdgeInsets.all(16), - child: const Text( - 'Get Widget is one of the largest Flutter open-source ' - 'UI library for mobile or web apps. It has more than 1000+ pre-built reusable widgets.'), - ), - ], - ), - stickyFooterHeight: 60, - stickyFooter: Container( - alignment: AlignmentDirectional.center, - width: 444, - color: Colors.amber, - child: const Text('Footer Title'), - ), - ); - - final TestApp app = TestApp(bottomSheet); - await tester.pumpWidget(app); - - // find bottom sheet by key - expect(find.byKey(bottomSheetKey), findsOneWidget); - // find header tile text - expect(find.text('Header Title'), findsOneWidget); - - // Swipe the header tile to open bottomSheet - await tester.drag(find.text('Header Title'), const Offset(0, -4.6)); - await tester.pumpAndSettle(); - await tester.pump(const Duration(seconds: 2)); - // find the content tile - expect(find.text('Content GetWidget'), findsOneWidget); - // find the footer title - expect(find.text('Footer Title'), findsOneWidget); - // Swipe the content tile to close bottomSheet - await tester.drag(find.text('Footer Title'), const Offset(0, 5.3)); - await tester.pumpAndSettle(); - await tester.pump(const Duration(seconds: 2)); - // try to find content finds nothing - expect(find.text('Content GetWidget'), findsNothing); - }); - - testWidgets('GFBottomSheet can be constructed with expandable content', - (tester) async { - final GFBottomSheet bottomSheet = GFBottomSheet( - key: bottomSheetKey, - controller: _controller, - enableExpandableContent: true, - stickyHeaderHeight: 70, - stickyHeader: const GFListTile( - avatar: GFAvatar( - backgroundColor: Colors.amber, - ), - titleText: 'Header Title', - subTitleText: '11 minutes ago', - ), - contentBody: ListView( - key: contentKey, - shrinkWrap: true, - physics: const ScrollPhysics(), - children: [ - const Text('Content GetWidget'), - Container( - padding: const EdgeInsets.all(16), - child: const Text( - 'Get Widget is one of the largest Flutter open-source ' - 'UI library for mobile or web apps. It has more than 1000+ pre-built reusable widgets.'), - ), - ], - ), - stickyFooterHeight: 60, - stickyFooter: Container( - alignment: AlignmentDirectional.center, - width: 444, - color: Colors.amber, - child: const Text('Footer Title'), - ), - ); - - final TestApp app = TestApp(bottomSheet); - await tester.pumpWidget(app); - - // find bottom sheet by key - expect(find.byKey(bottomSheetKey), findsOneWidget); - // find header tile text - expect(find.text('Header Title'), findsOneWidget); - // set enableExpandableContent = true - expect(bottomSheet.enableExpandableContent, isTrue); - // Swipe the header tile to open bottomSheet - await tester.drag(find.text('Header Title'), const Offset(0, -4.6)); - await tester.pumpAndSettle(); - await tester.pump(const Duration(seconds: 2)); - // find the content tile - expect(find.text('Content GetWidget'), findsOneWidget); - // find the footer title - expect(find.text('Footer Title'), findsOneWidget); - // Swipe the content tile to close bottomSheet - await tester.drag(find.text('Content GetWidget'), const Offset(0, 6.5)); - await tester.pumpAndSettle(); - await tester.pump(const Duration(seconds: 2)); - // try to find content finds nothing - expect(find.text('Content GetWidget'), findsNothing); - - // Swipe the header tile to open bottomSheet - await tester.drag(find.text('Header Title'), const Offset(0, -4.6)); - await tester.pumpAndSettle(); - await tester.pump(const Duration(seconds: 2)); - // find the content tile - expect(find.text('Content GetWidget'), findsOneWidget); - // find the footer title - expect(find.text('Footer Title'), findsOneWidget); - // drag up content body to expand - await tester.drag(find.byKey(contentKey), const Offset(0, -22.9)); - await tester.pumpAndSettle(); - await tester.pump(const Duration(seconds: 5)); - // find content body - expect(find.text('Content GetWidget'), findsOneWidget); - - // drag down content body to close the bottom sheet - await tester.drag(find.byKey(contentKey), const Offset(0, 5.6)); - await tester.pumpAndSettle(); - await tester.pump(const Duration(seconds: 5)); - // try to find content body, finds nothing - expect(find.text('Content GetWidget'), findsNothing); - }); - - testWidgets('GFBottomSheet with properties', (tester) async { - final GFBottomSheet bottomSheet = GFBottomSheet( - controller: _controller, - enableExpandableContent: true, - stickyHeaderHeight: 70, - stickyHeader: const GFListTile( - avatar: GFAvatar( - backgroundColor: Colors.amber, - ), - titleText: 'Header Title', - subTitleText: '11 minutes ago', - ), - contentBody: ListView( - key: contentKey, - shrinkWrap: true, - physics: const ScrollPhysics(), - children: [ - const Text('Content GetWidget'), - Container( - padding: const EdgeInsets.all(16), - child: const Text( - 'Get Widget is one of the largest Flutter open-source ' - 'UI library for mobile or web apps. It has more than 1000+ pre-built reusable widgets.'), - ), - ], - ), - stickyFooterHeight: 60, - stickyFooter: Container( - alignment: AlignmentDirectional.center, - width: 444, - color: Colors.amber, - child: const Text('Footer Title'), - ), - elevation: 5, - minContentHeight: 150, - maxContentHeight: 450, - animationDuration: 1500, - ); - - final TestApp app = TestApp(bottomSheet); - - await tester.pumpWidget(app); - expect(app.bottomSheet.controller, _controller); - expect(app.bottomSheet.stickyHeaderHeight, 70); - expect(app.bottomSheet.stickyFooterHeight, 60); - expect(app.bottomSheet.enableExpandableContent, isTrue); - expect(app.bottomSheet.elevation, 5); - expect(app.bottomSheet.minContentHeight, 150); - expect(app.bottomSheet.maxContentHeight, 450); - expect(app.bottomSheet.animationDuration, 1500); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.bottomSheet); - final GFBottomSheet bottomSheet; - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - bottomSheet: widget.bottomSheet, - ), - ); -} diff --git a/test/button_badge_test.dart b/test/button_badge_test.dart deleted file mode 100644 index 1bb00c67..00000000 --- a/test/button_badge_test.dart +++ /dev/null @@ -1,364 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - const badge = GFBadge( - child: Text('12'), - ); - const text = 'click me'; - const textStyle = TextStyle(fontSize: 14, color: Colors.black); - const size = GFSize.SMALL; - - testWidgets('Disabled GF ButtonBadge can be constructed', (tester) async { - const buttonBadgeKey = Key('header'); - - const GFButtonBadge buttonBadge = GFButtonBadge( - key: buttonBadgeKey, - onPressed: null, - text: text, - size: size, - icon: badge, - disabledColor: Colors.teal, - disabledElevation: 3, - disabledTextColor: GFColors.LIGHT, - ); - - const TestApp app = TestApp(buttonBadge); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.text('12'), findsOneWidget); - - expect(app.buttonBadge.icon, badge); - expect(app.buttonBadge.text, text); - expect(app.buttonBadge.size, size); - expect(app.buttonBadge.onPressed, null); - expect(app.buttonBadge.disabledColor, Colors.teal); - expect(app.buttonBadge.disabledElevation, 3); - expect(app.buttonBadge.disabledTextColor, GFColors.LIGHT); - - await tester.tap(find.byKey(buttonBadgeKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); - - testWidgets('GF ButtonBadge can be constructed', (tester) async { - const buttonBadgeKey = Key('header'); - - final GFButtonBadge buttonBadge = GFButtonBadge( - key: buttonBadgeKey, - onPressed: () {}, - text: text, - icon: badge, - size: size, - color: GFColors.ALT, - textStyle: textStyle, - ); - - final TestApp app = TestApp(buttonBadge); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.text('12'), findsOneWidget); - - expect(app.buttonBadge.icon, badge); - expect(app.buttonBadge.text, text); - expect(app.buttonBadge.textStyle, textStyle); - expect(app.buttonBadge.size, size); - expect(app.buttonBadge.color, GFColors.ALT); - - await tester.tap(find.byKey(buttonBadgeKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); - - testWidgets( - 'GF ButtonBadge can be constructed with standard type and shape i.e default', - (tester) async { - const buttonBadgeKey = Key('header'); - - final GFButtonBadge buttonBadge = GFButtonBadge( - key: buttonBadgeKey, - onPressed: () {}, - text: text, - icon: badge, - size: size, - textColor: GFColors.DARK, - ); - - final TestApp app = TestApp(buttonBadge); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.text('12'), findsOneWidget); - - expect(app.buttonBadge.icon, badge); - expect(app.buttonBadge.text, text); - expect(app.buttonBadge.textColor, GFColors.DARK); - expect(app.buttonBadge.size, size); - - await tester.tap(find.byKey(buttonBadgeKey)); - await tester.pump(); - await tester.press(find.byKey(buttonBadgeKey)); - await tester.pump(); - await tester.longPress(find.byKey(buttonBadgeKey)); - await tester.pump(); - - // await expectLater(() => tester.tap(find.byKey(buttonBadgeKey)), prints('onHighlight changed')); - - await tester.pumpWidget(app); - }); - - testWidgets('GF ButtonBadge with Block Button and badge position', - (tester) async { - const buttonBadgeKey = Key('header'); - - final GFButtonBadge buttonBadge = GFButtonBadge( - key: buttonBadgeKey, - onPressed: () {}, - text: text, - size: size, - icon: badge, - position: GFPosition.start, - blockButton: true, - ); - - final TestApp app = TestApp(buttonBadge); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.text('12'), findsOneWidget); - - expect(app.buttonBadge.icon, badge); - expect(app.buttonBadge.text, text); - expect(app.buttonBadge.size, size); - expect(app.buttonBadge.position, GFPosition.start); - expect(app.buttonBadge.blockButton, isTrue); - }); - - testWidgets( - 'GF ButtonBadge with solid type and pills shape ' - 'and Full Width Button', (tester) async { - const buttonBadgeKey = Key('header'); - - final GFButtonBadge buttonBadge = GFButtonBadge( - key: buttonBadgeKey, - onPressed: () {}, - text: text, - size: size, - icon: badge, - position: GFPosition.start, - type: GFButtonType.solid, - shape: GFButtonShape.pills, - fullWidthButton: true, - ); - - final TestApp app = TestApp(buttonBadge); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.text('12'), findsOneWidget); - - expect(app.buttonBadge.icon, badge); - expect(app.buttonBadge.text, text); - expect(app.buttonBadge.size, size); - expect(app.buttonBadge.position, GFPosition.start); - expect(app.buttonBadge.type, GFButtonType.solid); - expect(app.buttonBadge.shape, GFButtonShape.pills); - expect(app.buttonBadge.fullWidthButton, isTrue); - }); - - testWidgets('GF ButtonBadge with type outline and square shape ', - (tester) async { - const buttonBadgeKey = Key('header'); - - final GFButtonBadge buttonBadge = GFButtonBadge( - key: buttonBadgeKey, - onPressed: () {}, - text: text, - size: size, - icon: badge, - position: GFPosition.start, - type: GFButtonType.outline, - shape: GFButtonShape.square, - ); - - final TestApp app = TestApp(buttonBadge); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.text('12'), findsOneWidget); - - expect(app.buttonBadge.icon, badge); - expect(app.buttonBadge.text, text); - expect(app.buttonBadge.size, size); - expect(app.buttonBadge.position, GFPosition.start); - expect(app.buttonBadge.type, GFButtonType.outline); - expect(app.buttonBadge.shape, GFButtonShape.square); - }); - - testWidgets('GF ButtonBadge with custom border and shape ', (tester) async { - const buttonBadgeKey = Key('header'); - - const border = BorderSide( - color: Colors.tealAccent, width: 1, style: BorderStyle.solid); - const shape = RoundedRectangleBorder( - side: - BorderSide(color: Colors.pink, width: 2, style: BorderStyle.solid), - borderRadius: BorderRadius.zero); - - final GFButtonBadge buttonBadge = GFButtonBadge( - key: buttonBadgeKey, - onPressed: () {}, - text: text, - icon: badge, - size: size, - borderShape: shape, - borderSide: border, - ); - - final TestApp app = TestApp(buttonBadge); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.text('12'), findsOneWidget); - - expect(app.buttonBadge.icon, badge); - expect(app.buttonBadge.text, text); - expect(app.buttonBadge.size, size); - expect(app.buttonBadge.borderShape, shape); - expect(app.buttonBadge.borderSide, border); - }); - - testWidgets('GF ButtonBadge with boxshadow ', (tester) async { - const buttonBadgeKey = Key('header'); - - const boxshadow = BoxShadow( - color: Colors.pink, - blurRadius: 2, - spreadRadius: 1, - offset: Offset.zero, - ); - - final GFButtonBadge buttonBadge = GFButtonBadge( - key: buttonBadgeKey, - onPressed: () {}, - text: text, - icon: badge, - size: size, - badgeBoxShadow: true, - boxShadow: boxshadow, - ); - - final TestApp app = TestApp(buttonBadge); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.text('12'), findsOneWidget); - - expect(app.buttonBadge.icon, badge); - expect(app.buttonBadge.text, text); - expect(app.buttonBadge.size, size); - expect(app.buttonBadge.badgeBoxShadow, isTrue); - expect(app.buttonBadge.boxShadow, boxshadow); - }); - - testWidgets( - 'GF ButtonBadge with hover, focus, highlight and splash color. Works only in web', - (tester) async { - const buttonBadgeKey = Key('header'); - - final GFButtonBadge buttonBadge = GFButtonBadge( - key: buttonBadgeKey, - onPressed: () {}, - text: text, - icon: badge, - size: size, - hoverColor: Colors.tealAccent, - focusColor: Colors.teal, - highlightColor: Colors.amber, - splashColor: Colors.red, - ); - - final TestApp app = TestApp(buttonBadge); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.text('12'), findsOneWidget); - - expect(app.buttonBadge.icon, badge); - expect(app.buttonBadge.text, text); - expect(app.buttonBadge.size, size); - expect(app.buttonBadge.hoverColor, Colors.tealAccent); - expect(app.buttonBadge.focusColor, Colors.teal); - expect(app.buttonBadge.highlightColor, Colors.amber); - expect(app.buttonBadge.splashColor, Colors.red); - }); - - testWidgets( - 'GF ButtonBadge with hover, focus, highlight and splash color. Works only in web', - (tester) async { - const buttonBadgeKey = Key('header'); - - final GFButtonBadge buttonBadge = GFButtonBadge( - key: buttonBadgeKey, - onPressed: () {}, - text: text, - icon: badge, - size: size, - elevation: 3, - focusElevation: 2, - hoverElevation: 2, - highlightElevation: 4, - ); - - final TestApp app = TestApp(buttonBadge); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.text('12'), findsOneWidget); - - expect(app.buttonBadge.icon, badge); - expect(app.buttonBadge.text, text); - expect(app.buttonBadge.size, size); - expect(app.buttonBadge.elevation, 3); - expect(app.buttonBadge.focusElevation, 2); - expect(app.buttonBadge.hoverElevation, 2); - expect(app.buttonBadge.highlightElevation, 4); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.buttonBadge); - - final GFButtonBadge buttonBadge; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.buttonBadge, - ], - ), - ), - ); -} diff --git a/test/button_test.dart b/test/button_test.dart deleted file mode 100644 index 68b5114f..00000000 --- a/test/button_test.dart +++ /dev/null @@ -1,377 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - const text = 'click me'; - const textStyle = TextStyle(fontSize: 14, color: Colors.black); - const size = GFSize.SMALL; - const childWidget = Text('tap me'); - - testWidgets('Disabled GF Button can be constructed', (tester) async { - const buttonKey = Key('header'); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: null, - text: text, - size: size, - disabledColor: Colors.teal.shade300, - disabledElevation: 3, - disabledTextColor: GFColors.LIGHT, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - - expect(app.button.text, text); - expect(app.button.size, size); - expect(app.button.onPressed, null); - expect(app.button.disabledColor, Colors.teal.shade300); - expect(app.button.disabledElevation, 3); - expect(app.button.disabledTextColor, GFColors.LIGHT); - - await tester.tap(find.byKey(buttonKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); - - testWidgets('GF Button can be constructed', (tester) async { - const buttonKey = Key('header'); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: () {}, - text: text, - size: size, - color: GFColors.ALT, - textStyle: textStyle, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - - expect(app.button.text, text); - expect(app.button.textStyle, textStyle); - expect(app.button.size, size); - expect(app.button.color, GFColors.ALT); - - await tester.tap(find.byKey(buttonKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); - - testWidgets('GF Button can be constructed with child for custom text', - (tester) async { - const buttonKey = Key('header'); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: () {}, - text: text, - size: size, - child: childWidget, - color: Colors.amber, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(app.button.child, childWidget); - - expect(app.button.text, text); - expect(app.button.size, size); - expect(app.button.color, Colors.amber); - - await tester.tap(find.byKey(buttonKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); - - testWidgets( - 'GF Button can be constructed with standard type and shape i.e default', - (tester) async { - const buttonKey = Key('header'); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: () {}, - text: text, - size: size, - textColor: GFColors.DARK, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - - expect(app.button.text, text); - expect(app.button.textColor, GFColors.DARK); - expect(app.button.size, size); - - await tester.tap(find.byKey(buttonKey)); - await tester.pump(); - await tester.press(find.byKey(buttonKey)); - await tester.pump(); - await tester.longPress(find.byKey(buttonKey)); - await tester.pump(); - - // await expectLater(() => tester.tap(find.byKey(buttonKey)), prints('onHighlight changed')); - - await tester.pumpWidget(app); - }); - - testWidgets( - 'GF Button with icon and icon position' - 'and with Block Button', (tester) async { - const buttonKey = Key('header'); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: () {}, - text: text, - size: size, - child: childWidget, - icon: const Icon( - Icons.directions_bike_sharp, - ), - position: GFPosition.start, - blockButton: true, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - - expect(app.button.text, text); - expect(app.button.size, size); - expect(app.button.position, GFPosition.start); - expect(app.button.blockButton, isTrue); - }); - - testWidgets( - 'GF Button with solid type and pills shape ' - 'and Full Width Button', (tester) async { - const buttonKey = Key('header'); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: () {}, - text: text, - size: size, - child: childWidget, - icon: const Icon( - Icons.directions_bike_sharp, - ), - position: GFPosition.start, - type: GFButtonType.solid, - shape: GFButtonShape.pills, - fullWidthButton: true, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - - expect(app.button.text, text); - expect(app.button.size, size); - expect(app.button.position, GFPosition.start); - expect(app.button.type, GFButtonType.solid); - expect(app.button.shape, GFButtonShape.pills); - expect(app.button.fullWidthButton, isTrue); - }); - - testWidgets('GF Button with type outline and square shape ', (tester) async { - const buttonKey = Key('header'); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: () {}, - text: text, - size: size, - child: childWidget, - icon: const Icon( - Icons.directions_bike_sharp, - ), - position: GFPosition.start, - type: GFButtonType.outline, - shape: GFButtonShape.square, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - - expect(app.button.text, text); - expect(app.button.size, size); - expect(app.button.position, GFPosition.start); - expect(app.button.type, GFButtonType.outline); - expect(app.button.shape, GFButtonShape.square); - }); - - testWidgets('GF Button with custom border and shape ', (tester) async { - const buttonKey = Key('header'); - - const border = BorderSide( - color: Colors.tealAccent, width: 1, style: BorderStyle.solid); - const shape = RoundedRectangleBorder( - side: - BorderSide(color: Colors.pink, width: 2, style: BorderStyle.solid), - borderRadius: BorderRadius.zero); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: () {}, - text: text, - size: size, - borderShape: shape, - borderSide: border, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - - expect(app.button.text, text); - expect(app.button.size, size); - expect(app.button.borderShape, shape); - expect(app.button.borderSide, border); - }); - - testWidgets('GF Button with boxshadow ', (tester) async { - const buttonKey = Key('header'); - - const boxshadow = BoxShadow( - color: Colors.pink, - blurRadius: 2, - spreadRadius: 1, - offset: Offset.zero, - ); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: () {}, - text: text, - size: size, - buttonBoxShadow: true, - boxShadow: boxshadow, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - - expect(app.button.text, text); - expect(app.button.size, size); - expect(app.button.buttonBoxShadow, isTrue); - expect(app.button.boxShadow, boxshadow); - }); - - testWidgets( - 'GF Button with hover, focus, highlight and splash color. Works only in web', - (tester) async { - const buttonKey = Key('header'); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: () {}, - text: text, - size: size, - hoverColor: Colors.tealAccent, - focusColor: Colors.teal, - highlightColor: Colors.amber, - splashColor: Colors.red, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - - expect(app.button.text, text); - expect(app.button.size, size); - expect(app.button.hoverColor, Colors.tealAccent); - expect(app.button.focusColor, Colors.teal); - expect(app.button.highlightColor, Colors.amber); - expect(app.button.splashColor, Colors.red); - }); - - testWidgets( - 'GF Button with hover, focus, highlight and splash color. Works only in web', - (tester) async { - const buttonKey = Key('header'); - - final GFButton button = GFButton( - key: buttonKey, - onPressed: () {}, - text: text, - size: size, - elevation: 3, - focusElevation: 2, - hoverElevation: 2, - highlightElevation: 4, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.text('click me'), findsOneWidget); - - expect(app.button.text, text); - expect(app.button.size, size); - expect(app.button.elevation, 3); - expect(app.button.focusElevation, 2); - expect(app.button.hoverElevation, 2); - expect(app.button.highlightElevation, 4); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.button); - - final GFButton button; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.button, - ], - ), - ), - ); -} diff --git a/test/card_test.dart b/test/card_test.dart deleted file mode 100644 index 9c748ef4..00000000 --- a/test/card_test.dart +++ /dev/null @@ -1,404 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -Future main() async { - final childWidget = Container( - width: 100, - height: 100, - ); - - const color = Colors.white; - const elevation = 2.0; - const borderOnForeground = false; - const padding = EdgeInsets.symmetric(horizontal: 12, vertical: 8); - const margin = EdgeInsets.all(1); - const title = GFListTile( - titleText: 'Card Title', - icon: Icon(Icons.favorite_border), - ); - const content = Text('Hello'); - final borderRadius = BorderRadius.circular(10); - const border = Border(top: BorderSide(color: Colors.black)); - - testWidgets('GF Card can be created.', (tester) async { - final GFCard card = GFCard( - color: color, - elevation: elevation, - borderOnForeground: borderOnForeground, - padding: padding, - margin: margin, - title: title, - content: childWidget, - image: Image.network( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - imageOverlay: const NetworkImage( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - await tester.pumpWidget(app); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.card.color, color); - expect(app.card.elevation, elevation); - expect(app.card.borderOnForeground, borderOnForeground); - expect(app.card.padding, padding); - expect(app.card.margin, margin); - expect(app.card.title, title); - expect(app.card.content, childWidget); - }); - - testWidgets('GF Card with color gradient.', (tester) async { - const gradient = LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [Colors.red, Colors.pink]); - final GFCard card = GFCard( - gradient: gradient, - elevation: elevation, - borderOnForeground: borderOnForeground, - padding: padding, - margin: margin, - title: title, - image: Image.network( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - imageOverlay: const NetworkImage( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - await tester.pumpWidget(app); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.card.gradient, gradient); - expect(app.card.elevation, elevation); - expect(app.card.borderOnForeground, borderOnForeground); - expect(app.card.padding, padding); - expect(app.card.margin, margin); - expect(app.card.title, title); - }); - - testWidgets('GF Card with clip behaviour.', (tester) async { - final bgImage = Image.network( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - const clip = Clip.none; - - final GFCard card = GFCard( - image: bgImage, - title: title, - clipBehavior: clip, - imageOverlay: const NetworkImage( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - expect(app.card.image, bgImage); - expect(app.card.title, title); - expect(app.card.clipBehavior, clip); - }); - - testWidgets('GF Card with background image.', (tester) async { - final bgImage = Image.network( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - const boxFit = BoxFit.cover; - - final GFCard card = GFCard( - image: bgImage, - title: title, - boxFit: boxFit, - imageOverlay: const NetworkImage( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - expect(app.card.image, bgImage); - expect(app.card.title, title); - expect(app.card.boxFit, boxFit); - }); - - testWidgets('GF Card with background image & image overlay.', (tester) async { - final bgImage = Image.network( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - const boxFit = BoxFit.cover; - const imageOverlay = NetworkImage( - 'https://cdn.pixabay.com/photo/2016/11/22/07/09/spruce-1848543__340.jpg'); - - final GFCard card = GFCard( - image: bgImage, - title: title, - boxFit: boxFit, - imageOverlay: imageOverlay, - ); - - final TestApp app = TestApp(card); - - expect(app.card.image, bgImage); - expect(app.card.title, title); - expect(app.card.boxFit, boxFit); - expect(app.card.imageOverlay, imageOverlay); - }); - - testWidgets('GF Card with semantic container.', (tester) async { - const isSemanticContainer = false; - - final GFCard card = GFCard( - semanticContainer: isSemanticContainer, - elevation: elevation, - borderOnForeground: borderOnForeground, - title: title, - image: Image.network( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - imageOverlay: const NetworkImage( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - await tester.pumpWidget(app); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.card.semanticContainer, isSemanticContainer); - expect(app.card.elevation, elevation); - expect(app.card.borderOnForeground, borderOnForeground); - expect(app.card.title, title); - }); - - testWidgets('GF Card with title position.', (tester) async { - final bgImage = Image.network( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - const titlePosition = GFPosition.end; - - final GFCard card = GFCard( - image: bgImage, - title: title, - titlePosition: titlePosition, - imageOverlay: const NetworkImage( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - expect(app.card.image, bgImage); - expect(app.card.title, title); - expect(app.card.titlePosition, titlePosition); - }); - - testWidgets('GF Card with border & border radius.', (tester) async { - final bgImage = Image.network( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - final GFCard card = GFCard( - title: title, - border: border, - borderRadius: borderRadius, - image: bgImage, - content: content, - imageOverlay: const NetworkImage( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.card.title, title); - expect(app.card.border, border); - expect(app.card.borderRadius, borderRadius); - expect(app.card.content, content); - expect(app.card.image, bgImage); - }); - - testWidgets('GF Card with custom button bar.', (tester) async { - final bgImage = Image.network( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - const customButtonBar = GFButtonBar( - children: [ - GFButton( - onPressed: null, - child: Text('Read More'), - icon: Icon(Icons.keyboard_arrow_right), - type: GFButtonType.transparent, - ), - ], - ); - final GFCard card = GFCard( - color: color, - elevation: elevation, - buttonBar: customButtonBar, - title: title, - image: bgImage, - imageOverlay: const NetworkImage( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.card.color, color); - expect(app.card.elevation, elevation); - expect(app.card.buttonBar, customButtonBar); - expect(app.card.image, bgImage); - }); - - testWidgets('GF Card with custom title.', (tester) async { - const customTitle = GFListTile( - titleText: 'Card Title', - icon: Icon(Icons.favorite_border), - ); - final GFCard card = GFCard( - color: color, - title: customTitle, - image: Image.network( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - imageOverlay: const NetworkImage( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - await tester.pumpWidget(app); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.card.color, color); - expect(app.card.title, customTitle); - }); - - testWidgets('GF Card with GFAvatar & subTitle in title section.', - (tester) async { - const customTitle = GFListTile( - avatar: GFAvatar(), - titleText: 'Card Title', - subTitleText: 'Sub title', - icon: Icon(Icons.favorite_border), - ); - final GFCard card = GFCard( - color: color, - title: customTitle, - image: Image.network( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - imageOverlay: const NetworkImage( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - await tester.pumpWidget(app); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.card.color, color); - expect(app.card.title, customTitle); - }); - - testWidgets('GF Card with full background image & button bar.', - (tester) async { - const imageOverlay = NetworkImage( - 'https://cdn.pixabay.com/photo/2016/11/22/07/09/spruce-1848543__340.jpg'); - final colorFilter = - ColorFilter.mode(Colors.black.withOpacity(0.67), BlendMode.darken); - const customTitle = GFListTile( - titleText: 'Card Title', - subTitleText: 'Sub title', - ); - final GFCard card = GFCard( - color: color, - title: customTitle, - imageOverlay: imageOverlay, - colorFilter: colorFilter, - image: Image.network( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.card.color, color); - expect(app.card.title, customTitle); - expect(app.card.imageOverlay, imageOverlay); - expect(app.card.colorFilter, colorFilter); - }); - - testWidgets( - 'GF Card with full background image, customized title & button bar.', - (tester) async { - const imageOverlay = NetworkImage( - 'https://cdn.pixabay.com/photo/2016/11/22/07/09/spruce-1848543__340.jpg'); - final colorFilter = - ColorFilter.mode(Colors.black.withOpacity(0.67), BlendMode.darken); - const customTitle = GFListTile( - avatar: GFAvatar(), - titleText: 'Card Title', - subTitleText: 'Sub title', - icon: Icon(Icons.favorite_border), - ); - const customButtonBar = GFButtonBar( - children: [ - GFButton( - onPressed: null, - child: Text('Read More'), - icon: Icon(Icons.keyboard_arrow_right), - type: GFButtonType.transparent, - ), - ], - ); - final GFCard card = GFCard( - color: color, - title: customTitle, - imageOverlay: imageOverlay, - colorFilter: colorFilter, - buttonBar: customButtonBar, - image: Image.network( - 'https://cdn.pixabay.com/photo/2021/02/01/16/22/flamingo-5971206__340.jpg'), - ); - - final TestApp app = TestApp(card); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.card.color, color); - expect(app.card.title, customTitle); - expect(app.card.imageOverlay, imageOverlay); - expect(app.card.colorFilter, colorFilter); - expect(app.card.buttonBar, customButtonBar); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.card); - - final GFCard card; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - bool fav = false; - - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.card, - ], - ), - ), - ); -} diff --git a/test/carousel_test.dart b/test/carousel_test.dart deleted file mode 100644 index 9b3e616a..00000000 --- a/test/carousel_test.dart +++ /dev/null @@ -1,127 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -class StateMarker extends StatefulWidget { - const StateMarker({Key? key, this.child}) : super(key: key); - final Widget? child; - @override - StateMarkerState createState() => StateMarkerState(); -} - -class StateMarkerState extends State { - String? marker; - @override - Widget build(BuildContext context) { - if (widget.child != null) { - return widget.child!; - } - return Container(); - } -} - -void main() { - final Key carouselKey = UniqueKey(); - final List textList = [ - 'AAAAAA', - 'BBBBBB', - 'CCCCCC', - 'DDDDDD', - 'EEEEEE' - ]; - final List itemList = [ - Text(textList[0]), - Text(textList[1]), - Text(textList[2]), - Text(textList[3]), - Text(textList[4]) - ]; - - testWidgets('GFCarousel can be constructed', (tester) async { - String value = textList[0]; - late int changedIndex; - - final GFCarousel carousel = GFCarousel( - key: carouselKey, - items: itemList.map((text) => StateMarker(child: text)).toList(), - onPageChanged: (index) { - changedIndex = index; - print('inr $index $changedIndex'); - }, - ); - - StateMarkerState findStateMarkerState(String name) => - tester.state(find.widgetWithText(StateMarker, name)); - - final TestApp app = TestApp(carousel); - await tester.pumpWidget(app); - - // find carousel by key - expect(find.byKey(carouselKey), findsOneWidget); - // find the 'AAAAAA' text in carousel - expect(find.text('AAAAAA'), findsOneWidget); - - TestGesture gesture = - await tester.startGesture(tester.getCenter(find.text('AAAAAA'))); - await gesture.moveBy(const Offset(-600, 0)); - await tester.pump(); - expect(value, equals(textList[0])); - findStateMarkerState(textList[1]).marker = 'marked'; - await gesture.up(); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - value = textList[changedIndex]; - expect(value, equals(textList[1])); - await tester.pumpWidget(app); - expect(findStateMarkerState(textList[1]).marker, equals('marked')); - - // slide on to the third slide. - gesture = - await tester.startGesture(tester.getCenter(find.text(textList[1]))); - await gesture.moveBy(const Offset(-600, 0)); - await gesture.up(); - await tester.pump(); - expect(findStateMarkerState(textList[1]).marker, equals('marked')); - await tester.pump(const Duration(seconds: 1)); - value = textList[changedIndex]; - expect(value, equals(textList[2])); - await tester.pumpWidget(app); - expect(find.text(textList[2]), findsOneWidget); - // slide back to the second slide. - gesture = - await tester.startGesture(tester.getCenter(find.text(textList[2]))); - await gesture.moveBy(const Offset(600, 0)); - await tester.pump(); - final StateMarkerState markerState = findStateMarkerState(textList[1]); - markerState.marker = 'marked'; - await gesture.up(); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - value = textList[changedIndex]; - expect(value, equals(textList[1])); - await tester.pumpWidget(app); - expect(findStateMarkerState(textList[1]).marker, equals('marked')); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.carousel); - - final GFCarousel carousel; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.carousel, - ], - ), - ), - ); -} diff --git a/test/checkbox_list_tile_test.dart b/test/checkbox_list_tile_test.dart deleted file mode 100644 index 1eb251af..00000000 --- a/test/checkbox_list_tile_test.dart +++ /dev/null @@ -1,208 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -Widget wrap({required Widget child}) => MediaQuery( - data: const MediaQueryData(), - child: Directionality( - textDirection: TextDirection.ltr, - child: Material(child: child), - ), - ); - -void main() { - final UniqueKey checkboxlistileKey = UniqueKey(); - const bool isChecked = false; - testWidgets('GFCheckboxListTile can be constructed Function call Null', - (tester) async { - final GFCheckboxListTile checkboxListTile = GFCheckboxListTile( - key: checkboxlistileKey, - onChanged: null, - value: isChecked, - ); - - final TestApp app = TestApp(checkboxListTile); - await tester.pumpWidget(app); - await tester.pump(); - expect(find.byKey(checkboxlistileKey), findsOneWidget); - expect(app.checkboxListTile.onChanged, null); - }); - - testWidgets('CheckboxListTile can autofocus unless disabled', (tester) async { - final GlobalKey childKey = GlobalKey(); - final checkboxListTile = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFCheckboxListTile( - value: true, - onChanged: (_) {}, - title: Text('Hello', key: childKey), - autofocus: false, - ), - )), - ); - await tester.pumpWidget(checkboxListTile); - await tester.pump(); - expect(Focus.maybeOf(childKey.currentContext!)!.hasPrimaryFocus, isFalse); - }); - - testWidgets('CheckboxListTile can autofocus is True', (tester) async { - final GlobalKey childKey = GlobalKey(); - final checkboxListTile = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFCheckboxListTile( - value: true, - onChanged: (_) {}, - title: Text('Hello', key: childKey), - autofocus: true, - ), - )), - ); - await tester.pumpWidget(checkboxListTile); - await tester.pump(); - expect(Focus.maybeOf(childKey.currentContext!)!.hasPrimaryFocus, isTrue); - }); - - testWidgets('CheckboxListTile values test', (WidgetTester tester) async { - bool _value = false; - - await tester.pumpWidget( - Material( - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => wrap( - child: GFCheckboxListTile( - title: const Text('Title'), - value: _value, - onChanged: (bool value) { - setState(() { - _value = value; - }); - }, - ), - ), - ), - ), - ); - - expect(tester.widget(find.byType(GFCheckbox)).value, false); - - // Tap the checkbox when value is disabled. - await tester.tap(find.byType(GFCheckbox)); - await tester.pumpAndSettle(); - expect(_value, true); - - await tester.tap(find.byType(GFCheckbox)); - await tester.pumpAndSettle(); - expect(_value, false); - - // Tap the listTile when value is disabled. - await tester.tap(find.byType(GFListTile)); - await tester.pumpAndSettle(); - expect(_value, true); - - await tester.tap(find.byType(GFListTile)); - await tester.pumpAndSettle(); - expect(_value, false); - }); - - testWidgets('CheckboxListTile selected item text Color', - (WidgetTester tester) async { - const Color colors = Color(0xff00ff00); - - Widget buildFrame({Color? colors, Color? toggleableActiveColor}) => - MaterialApp( - theme: ThemeData.light().copyWith( - switchTheme: SwitchThemeData( - thumbColor: MaterialStateProperty.resolveWith( - (Set states) { - if (states.contains(MaterialState.disabled)) { - return null; - } - if (states.contains(MaterialState.selected)) { - return toggleableActiveColor; - } - return null; - }), - trackColor: MaterialStateProperty.resolveWith( - (Set states) { - if (states.contains(MaterialState.disabled)) { - return null; - } - if (states.contains(MaterialState.selected)) { - return toggleableActiveColor; - } - return null; - }), - ), - radioTheme: RadioThemeData( - fillColor: MaterialStateProperty.resolveWith( - (Set states) { - if (states.contains(MaterialState.disabled)) { - return null; - } - if (states.contains(MaterialState.selected)) { - return toggleableActiveColor; - } - return null; - }), - ), - checkboxTheme: CheckboxThemeData( - fillColor: MaterialStateProperty.resolveWith( - (Set states) { - if (states.contains(MaterialState.disabled)) { - return null; - } - if (states.contains(MaterialState.selected)) { - return toggleableActiveColor; - } - return null; - }), - ), - ), - home: Scaffold( - body: Center( - child: GFCheckboxListTile( - color: colors, - selected: true, - title: const Text('title'), - value: true, - onChanged: (bool? value) {}, - ), - ), - ), - ); - - Color? textColor(String text) => - tester.renderObject(find.text(text)).text.style?.color; - - await tester.pumpWidget(buildFrame(toggleableActiveColor: colors)); - print(textColor('title')); - expect(textColor('title'), const Color(0xdd000000)); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.checkboxListTile); - - final GFCheckboxListTile checkboxListTile; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.checkboxListTile, - ], - ), - ), - ); -} diff --git a/test/checkbox_test.dart b/test/checkbox_test.dart deleted file mode 100644 index 7cea8864..00000000 --- a/test/checkbox_test.dart +++ /dev/null @@ -1,260 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final UniqueKey checkboxKey = UniqueKey(); - bool isChecked = false; - testWidgets('Checkbox button can be constructed Function call Null', - (tester) async { - final GFCheckbox checkbox = GFCheckbox( - key: checkboxKey, - onChanged: null, - value: isChecked, - ); - - final TestApp app = TestApp(checkbox); - await tester.pumpWidget(app); - await tester.pump(); - expect(find.byKey(checkboxKey), findsOneWidget); - expect(app.checkbox.onChanged, null); - expect( - app.checkbox.value, - isChecked, - ); - }); - - testWidgets('Basic Checkbox can be constructed with Value ', (tester) async { - final checkbox = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFCheckbox( - key: checkboxKey, - size: GFSize.SMALL, - activeBgColor: GFColors.DANGER, - onChanged: (value) { - setState(() { - isChecked = value; - }); - }, - value: isChecked, - ), - )), - ); - await tester.pumpWidget(checkbox); - expect(find.byKey(checkboxKey), findsOneWidget); - expect(isChecked, isFalse); - }); - - testWidgets('Checkbox button set True and False Values', - (WidgetTester tester) async { - final checkbox = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFCheckbox( - key: checkboxKey, - size: GFSize.SMALL, - activeBgColor: GFColors.DANGER, - onChanged: (value) { - setState(() { - isChecked = value; - }); - }, - value: isChecked, - ), - )), - ); - // find checkbox key - await tester.pumpWidget(checkbox); - expect(find.byKey(checkboxKey), findsOneWidget); - - // finds value - expect(isChecked, isFalse); - expect(tester.widget(find.byType(GFCheckbox)).value, isChecked); - await tester.tap(find.byType(GFCheckbox)); - - await tester.pumpAndSettle(); - print(isChecked); - expect(isChecked, isTrue); - - await tester.tap(find.byType(GFCheckbox)); - await tester.pumpAndSettle(); - print(isChecked); - expect(isChecked, isFalse); - - await tester.tap(find.byType(GFCheckbox)); - await tester.pumpAndSettle(); - print(isChecked); - expect(isChecked, isTrue); - - isChecked = true; - await tester.pumpAndSettle(); - expect(isChecked, true); - }); - - testWidgets('Checkbox is focusable and has correct focus color', - (WidgetTester tester) async { - final FocusNode focusNode = FocusNode(debugLabel: 'Checkbox'); - tester.binding.focusManager.highlightStrategy = - FocusHighlightStrategy.alwaysTraditional; - - final checkbox = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: Center( - child: GFCheckbox( - key: checkboxKey, - size: GFSize.SMALL, - activeBgColor: GFColors.DANGER, - onChanged: (value) { - setState(() { - isChecked = value; - }); - }, - value: isChecked, - autofocus: true, - focusNode: focusNode, - ), - )), - ), - ); - - await tester.pumpWidget(checkbox); - expect(find.byKey(checkboxKey), findsOneWidget); - await tester.pumpAndSettle(); - expect(focusNode.hasPrimaryFocus, isTrue); - }); - - testWidgets('Checkbox can be toggled by keyboard shortcuts', - (WidgetTester tester) async { - tester.binding.focusManager.highlightStrategy = - FocusHighlightStrategy.alwaysTraditional; - bool value = true; - - Widget buildApp({bool enabled = true}) => MaterialApp( - home: Material( - child: Center( - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => - GFCheckbox( - value: value, - onChanged: enabled - ? (bool newValue) { - setState(() { - value = newValue; - }); - } - : null, - autofocus: true, - )), - ), - ), - ); - - await tester.pumpWidget(buildApp()); - await tester.pumpAndSettle(); - await tester.sendKeyEvent(LogicalKeyboardKey.enter); - await tester.pumpAndSettle(); - expect(value, isTrue); - }); - - testWidgets('Checkbox size is configurable by ThemeData', - (WidgetTester tester) async { - final checkbox = Theme( - data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap), - child: Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: Center( - child: GFCheckbox( - key: checkboxKey, - activeBgColor: GFColors.DANGER, - onChanged: (value) { - setState(() { - isChecked = value; - }); - }, - value: isChecked, - size: 48, - ), - ))), - ), - ); - await tester.pumpWidget(checkbox); - expect(find.byKey(checkboxKey), findsOneWidget); - expect(tester.getSize(find.byKey(checkboxKey)), const Size(48, 48)); - }); - - testWidgets('Checkbox can be constructed with Active & InactiveIcon ', - (tester) async { - const activeIcon = Icon(Icons.sentiment_satisfied); - const inactiveIcon = Icon(Icons.sentiment_dissatisfied); - - final GFCheckbox checkbox = GFCheckbox( - key: checkboxKey, - value: isChecked, - onChanged: null, - activeIcon: activeIcon, - inactiveIcon: inactiveIcon, - ); - - final TestApp app = TestApp(checkbox); - await tester.pumpWidget(app); - await tester.pump(); - expect(find.byKey(checkboxKey), findsOneWidget); - expect(app.checkbox.activeIcon, activeIcon); - expect(app.checkbox.inactiveIcon, inactiveIcon); - }); - - testWidgets('Checkbox can be constructed with Colors ', (tester) async { - final GFCheckbox checkbox = GFCheckbox( - key: checkboxKey, - activeBgColor: Colors.amber, - customBgColor: Colors.amberAccent, - inactiveBgColor: Colors.blue, - activeBorderColor: Colors.deepPurple, - inactiveBorderColor: Colors.green, - value: isChecked, - onChanged: (value) { - isChecked = true; - }, - ); - - final TestApp app = TestApp(checkbox); - await tester.pumpWidget(app); - await tester.pump(); - expect(find.byKey(checkboxKey), findsOneWidget); - expect(app.checkbox.activeBgColor, Colors.amber); - expect(app.checkbox.customBgColor, Colors.amberAccent); - expect(app.checkbox.inactiveBgColor, Colors.blue); - expect(app.checkbox.activeBorderColor, Colors.deepPurple); - expect(app.checkbox.inactiveBorderColor, Colors.green); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.checkbox); - - final GFCheckbox checkbox; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.checkbox, - ], - ), - ), - ); -} diff --git a/test/dropdown_test.dart b/test/dropdown_test.dart deleted file mode 100644 index 695ce7d4..00000000 --- a/test/dropdown_test.dart +++ /dev/null @@ -1,407 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - const iconSize = 24.0; - final List itemList = ['one', 'two', 'three', 'four', 'five', 'Six']; - - testWidgets('Dropdown button can be constructed Null Values', (tester) async { - const dropdownKey = Key('header'); - final GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: itemList - .map((value) => DropdownMenuItem( - value: value, - child: Text(value), - )) - .toList(), - value: null, - onChanged: null, - ); - final TestApp app = TestApp(dropdown); - await tester.pumpWidget(app); - expect(find.byKey(dropdownKey), findsOneWidget); - await tester.pump(); - expect(app.dropdown.onChanged, null); - expect( - app.dropdown.value, - null, - ); - }); - - testWidgets('Dropdown button control can be constructed', (tester) async { - const dropdownKey = Key('header'); - String value = 'one'; - final GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: itemList - .map((value) => DropdownMenuItem( - value: value, - child: Text(value), - )) - .toList(), - value: value, - onChanged: (newValue) { - value = newValue; - }, - ); - - final TestApp app = TestApp(dropdown); - await tester.pumpWidget(app); - - await tester.pumpWidget(app); - await tester.tap(find.text('one')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - - expect(value, equals('one')); - await tester.tap(find.text('three').last); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(value, equals('three')); - - await tester.tap(find.text('three')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(value, equals('three')); - - await tester.pumpWidget(app); - await tester.tap(find.text('two').last); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(value, equals('two')); - }); - - testWidgets('Dropdown button can be constructed with items length', - (tester) async { - const dropdownKey = Key('header'); - String dropdownValue = 'one'; - final GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: itemList - .map((value) => DropdownMenuItem( - value: value, - child: Text(value), - )) - .toList(), - value: dropdownValue, - onChanged: (newValue) { - dropdownValue = newValue; - }, - ); - final TestApp app = TestApp(dropdown); - await tester.pumpWidget(app); - expect(find.byKey(dropdownKey), findsOneWidget); - await tester.pump(); - expect(app.dropdown.items!.length, itemList.length); - expect(app.dropdown.value, dropdownValue); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(itemList.length, equals(6)); - }); - - testWidgets('DropdownButton disabledHint is null by default', (tester) async { - const dropdownKey = Key('header'); - const String value = 'one'; - final List itemLists = []; - final GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: itemLists - .map((value) => DropdownMenuItem( - value: value, - child: Text(value), - )) - .toList(), - value: value, - onChanged: null, - hint: const Text('hint used when disabled'), - ); - final TestApp app = TestApp(dropdown); - await tester.pumpWidget(app); - - // [hint] should display when [items] is an empty list - expect(find.text('hint used when disabled'), findsOneWidget); - }); - - testWidgets( - 'DropdowwnButton hint displays when the items list is empty, items is null, and disabledHint is null', - (tester) async { - const dropdownKey = Key('header'); - final List itemLists = []; - String value = 'one'; - final GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: itemLists - .map((value) => DropdownMenuItem( - value: value, - child: Text(value), - )) - .toList(), - value: value, - onChanged: null, - disabledHint: null, - hint: const Text('hint used when disabled'), - ); - final TestApp app = TestApp(dropdown); - await tester.pumpWidget(app); - expect(find.text('hint used when disabled'), findsOneWidget); - - expect(find.byKey(dropdownKey), findsOneWidget); - - final RenderBox buttonBoxHintValue = - tester.renderObject(find.byKey(dropdownKey)); - assert(buttonBoxHintValue.attached); - - value = 'one'; - await tester.pumpWidget(app); - final RenderBox buttonBox = tester.renderObject(find.byKey(dropdownKey)); - assert(buttonBox.attached); - print(itemList[0]); - - expect(buttonBox.localToGlobal(Offset.zero), - equals(buttonBoxHintValue.localToGlobal(Offset.zero))); - expect(buttonBox.size, equals(buttonBoxHintValue.size)); - }); - - testWidgets('DropdownButton is activated with the enter key', (tester) async { - const dropdownKey = Key('header'); - final FocusNode focusNode = FocusNode(debugLabel: 'DropdownButton'); - String value = 'one'; - final GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: itemList - .map((value) => DropdownMenuItem( - value: value, - child: Text(value), - )) - .toList(), - value: value, - itemHeight: null, - onChanged: (newValue) { - value = newValue; - }, - focusNode: focusNode, - autofocus: true, - ); - final TestApp app = TestApp(dropdown); - await tester.pumpWidget(app); - - expect(focusNode.hasPrimaryFocus, isTrue); - await tester.sendKeyEvent(LogicalKeyboardKey.enter); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); // finish the menu animation - expect(value, equals('one')); - - await tester.sendKeyEvent(LogicalKeyboardKey.tab); // Focus 'two' - await tester.pump(); - await tester.sendKeyEvent(LogicalKeyboardKey.enter); // Select 'two'. - await tester.pump(); - - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); // finish the menu animation - - expect(value, equals('two')); - }); - - testWidgets('DropdownButton is activated with the space key', (tester) async { - const dropdownKey = Key('header'); - final FocusNode focusNode = FocusNode(debugLabel: 'DropdownButton'); - String value = 'one'; - final GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: itemList - .map((value) => DropdownMenuItem( - value: value, - child: Text(value), - )) - .toList(), - value: value, - itemHeight: null, - onChanged: (newValue) { - value = newValue; - }, - focusNode: focusNode, - autofocus: true, - ); - final TestApp app = TestApp(dropdown); - await tester.pumpWidget(app); - - expect(focusNode.hasPrimaryFocus, isTrue); - await tester.sendKeyEvent(LogicalKeyboardKey.space); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); // finish the menu animation - expect(value, equals('one')); - - await tester.sendKeyEvent(LogicalKeyboardKey.tab); // Focus 'two' - await tester.pump(); - await tester.sendKeyEvent(LogicalKeyboardKey.space); // Select 'two'. - await tester.pump(); - - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); // finish the menu animation - - expect(value, equals('two')); - }); - - testWidgets('DropdownButton won\'t be focused if not enabled', - (tester) async { - final UniqueKey dropdownKey = UniqueKey(); - final FocusNode focusNode = FocusNode(debugLabel: 'DropdownButton'); - final GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: itemList - .map((value) => DropdownMenuItem( - value: value, - child: Text(value), - )) - .toList(), - onChanged: null, - focusNode: focusNode, - autofocus: true, - focusColor: const Color(0xff00ff00)); - final TestApp app = TestApp(dropdown); - await tester.pumpWidget(app); - - await tester - .pump(); // Pump a frame for autofocus to take effect (although it shouldn't). - expect(focusNode.hasPrimaryFocus, isFalse); - }); - - testWidgets('DropdownButton changes selected item with arrow keys', - (tester) async { - final UniqueKey dropdownKey = UniqueKey(); - final FocusNode focusNode = FocusNode(debugLabel: 'DropdownButton'); - String value = 'one'; - final GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: itemList - .map((value) => DropdownMenuItem( - value: value, - child: Text(value), - )) - .toList(), - value: value, - itemHeight: null, - onChanged: (newValue) { - value = newValue; - }, - focusNode: focusNode, - autofocus: true, - focusColor: const Color(0xff00ff00)); - final TestApp app = TestApp(dropdown); - await tester.pumpWidget(app); - - await tester.pumpWidget(app); - await tester.pump(); - expect(focusNode.hasPrimaryFocus, isTrue); - - await tester.sendKeyEvent(LogicalKeyboardKey.enter); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); // finish the menu animation - expect(value, equals('one')); - - await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); // Focus 'two'. - await tester.pump(); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); // Focus 'three'. - await tester.pump(); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); // Back to 'two'. - await tester.pump(); - await tester.sendKeyEvent(LogicalKeyboardKey.enter); // Select 'two'. - await tester.pump(); - - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); // finish the menu animation - - expect(value, equals('two')); - }); - - testWidgets('GFDropdown Color Property can be constructed ', (tester) async { - const dropdownKey = Key('header'); - const GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: null, - onChanged: null, - iconDisabledColor: Colors.amber, - iconEnabledColor: Colors.blue, - dropdownColor: Colors.redAccent, - focusColor: Colors.red, - ); - - const TestApp app = TestApp(dropdown); - - await tester.pumpWidget(app); - expect(app.dropdown.iconDisabledColor, Colors.amber); - expect( - app.dropdown.iconEnabledColor, - Colors.blue, - ); - expect( - app.dropdown.dropdownColor, - Colors.redAccent, - ); - expect( - app.dropdown.focusColor, - Colors.red, - ); - - await tester.tap(find.byKey(dropdownKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); - - testWidgets('GFDropdown Button Property can be constructed', (tester) async { - const dropdownKey = Key('header'); - const GFDropdown dropdown = GFDropdown( - key: dropdownKey, - items: null, - isDense: true, - isExpanded: false, - autofocus: false, - onChanged: null, - iconSize: iconSize, - itemHeight: 40, - elevation: 8, - ); - - const TestApp app = TestApp(dropdown); - await tester.pumpWidget(app); - - expect(app.dropdown.iconSize, iconSize); - expect(app.dropdown.onChanged, null); - expect(app.dropdown.isExpanded, false); - expect(app.dropdown.isDense, true); - expect(app.dropdown.autofocus, false); - expect(app.dropdown.elevation, 8); - expect(app.dropdown.itemHeight, 40); - - await tester.tap(find.byKey(dropdownKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.dropdown); - - final GFDropdown dropdown; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.dropdown, - ], - ), - ), - ); -} diff --git a/test/icon_badge_test.dart b/test/icon_badge_test.dart deleted file mode 100644 index ae6f2ff0..00000000 --- a/test/icon_badge_test.dart +++ /dev/null @@ -1,92 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - const badge = GFBadge( - child: Text('12'), - ); - const size = GFSize.SMALL; - - testWidgets('Disabled GF IconBadge can be constructed', (tester) async { - const iconBadgeKey = Key('header'); - - final GFIconBadge iconBadge = GFIconBadge( - counterChild: badge, - child: GFIconButton( - key: iconBadgeKey, - onPressed: null, - icon: const Icon( - Icons.directions_bike_sharp, - ), - size: size, - disabledColor: Colors.teal.shade300, - ), - ); - - final TestApp app = TestApp(iconBadge); - - await tester.pumpWidget(app); - - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - expect(find.byWidget(badge), findsOneWidget); - expect(app.iconBadge.counterChild, badge); - - await tester.tap(find.byKey(iconBadgeKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); - - testWidgets('GF IconBadge can be constructed', (tester) async { - const iconBadgeKey = Key('header'); - - final GFIconBadge iconBadge = GFIconBadge( - counterChild: badge, - child: GFIconButton( - key: iconBadgeKey, - onPressed: () {}, - icon: const Icon( - Icons.directions_bike_sharp, - ), - size: size, - color: Colors.teal, - ), - ); - - final TestApp app = TestApp(iconBadge); - - await tester.pumpWidget(app); - - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - expect(find.byWidget(badge), findsOneWidget); - expect(app.iconBadge.counterChild, badge); - - await tester.tap(find.byKey(iconBadgeKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.iconBadge); - - final GFIconBadge iconBadge; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.iconBadge, - ], - ), - ), - ); -} diff --git a/test/icon_button_test.dart b/test/icon_button_test.dart deleted file mode 100644 index 6c868cb9..00000000 --- a/test/icon_button_test.dart +++ /dev/null @@ -1,259 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - const size = GFSize.SMALL; - - testWidgets('Disabled GF IconButton can be constructed', (tester) async { - const buttonKey = Key('header'); - - final GFIconButton button = GFIconButton( - key: buttonKey, - onPressed: null, - icon: const Icon( - Icons.directions_bike_sharp, - ), - size: size, - disabledColor: Colors.teal.shade300, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - expect(app.button.size, size); - expect(app.button.onPressed, null); - expect(app.button.disabledColor, Colors.teal.shade300); - - await tester.tap(find.byKey(buttonKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); - - testWidgets('GF IconButton can be constructed', (tester) async { - const buttonKey = Key('header'); - - final GFIconButton button = GFIconButton( - key: buttonKey, - onPressed: () {}, - icon: const Icon( - Icons.directions_bike_sharp, - ), - size: size, - color: GFColors.ALT, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - expect(app.button.size, size); - expect(app.button.color, GFColors.ALT); - - await tester.tap(find.byKey(buttonKey)); - await tester.pump(); - - await tester.pumpWidget(app); - }); - - testWidgets( - 'GF IconButton can be constructed with standard type and shape i.e default', - (tester) async { - const buttonKey = Key('header'); - - final GFIconButton button = GFIconButton( - key: buttonKey, - onPressed: () {}, - size: size, - icon: const Icon( - Icons.directions_bike_sharp, - ), - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - expect(app.button.size, size); - - await tester.tap(find.byKey(buttonKey)); - await tester.pump(); - await tester.press(find.byKey(buttonKey)); - await tester.pump(); - await tester.longPress(find.byKey(buttonKey)); - await tester.pump(); - - // await expectLater(() => tester.tap(find.byKey(buttonKey)), prints('onHighlight changed')); - - await tester.pumpWidget(app); - }); - - testWidgets('GF IconButton with solid type and pills shape ', (tester) async { - const buttonKey = Key('header'); - - final GFIconButton button = GFIconButton( - key: buttonKey, - onPressed: () {}, - iconSize: 24, - icon: const Icon( - Icons.directions_bike_sharp, - ), - type: GFButtonType.solid, - shape: GFIconButtonShape.pills, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - - expect(app.button.iconSize, 24); - expect(app.button.type, GFButtonType.solid); - expect(app.button.shape, GFIconButtonShape.pills); - }); - - testWidgets('GF IconButton with type outline and round shape ', - (tester) async { - const buttonKey = Key('header'); - - final GFIconButton button = GFIconButton( - key: buttonKey, - onPressed: () {}, - icon: const Icon( - Icons.directions_bike_sharp, - ), - size: size, - type: GFButtonType.outline, - shape: GFIconButtonShape.circle, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - - expect(app.button.size, size); - expect(app.button.type, GFButtonType.outline); - expect(app.button.shape, GFIconButtonShape.circle); - }); - - testWidgets('GF IconButton with custom border and shape ', (tester) async { - const buttonKey = Key('header'); - - const border = BorderSide( - color: Colors.tealAccent, width: 1, style: BorderStyle.solid); - const shape = RoundedRectangleBorder( - side: - BorderSide(color: Colors.pink, width: 2, style: BorderStyle.solid), - borderRadius: BorderRadius.zero); - - final GFIconButton button = GFIconButton( - key: buttonKey, - onPressed: () {}, - icon: const Icon( - Icons.directions_bike_sharp, - ), - size: size, - borderShape: shape, - borderSide: border, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - expect(app.button.size, size); - expect(app.button.borderShape, shape); - expect(app.button.borderSide, border); - }); - - testWidgets('GF IconButton with boxshadow ', (tester) async { - const buttonKey = Key('header'); - - const boxshadow = BoxShadow( - color: Colors.pink, - blurRadius: 2, - spreadRadius: 1, - offset: Offset.zero, - ); - - final GFIconButton button = GFIconButton( - key: buttonKey, - onPressed: () {}, - icon: const Icon( - Icons.directions_bike_sharp, - ), - size: size, - buttonBoxShadow: true, - boxShadow: boxshadow, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - expect(app.button.size, size); - expect(app.button.buttonBoxShadow, isTrue); - expect(app.button.boxShadow, boxshadow); - }); - - testWidgets( - 'GF IconButton with hover, focus, highlight and splash color. Works only in web', - (tester) async { - const buttonKey = Key('header'); - - final GFIconButton button = GFIconButton( - key: buttonKey, - onPressed: () {}, - icon: const Icon( - Icons.directions_bike_sharp, - ), - size: size, - hoverColor: Colors.tealAccent, - focusColor: Colors.teal, - highlightColor: Colors.amber, - splashColor: Colors.red, - ); - - final TestApp app = TestApp(button); - - await tester.pumpWidget(app); - - expect(app.button.size, size); - expect(app.button.hoverColor, Colors.tealAccent); - expect(app.button.focusColor, Colors.teal); - expect(app.button.highlightColor, Colors.amber); - expect(app.button.splashColor, Colors.red); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.button); - - final GFIconButton button; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.button, - ], - ), - ), - ); -} diff --git a/test/image_test.dart b/test/image_test.dart deleted file mode 100644 index 491da2cd..00000000 --- a/test/image_test.dart +++ /dev/null @@ -1,142 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final childWidget = Container( - width: 100, - height: 100, - ); - const color = Colors.teal; - const padding = EdgeInsets.all(5); - const margin = EdgeInsets.all(5); - const boxFit = BoxFit.cover; - const bgImage = NetworkImage( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - - testWidgets('GF Image can be created.', (tester) async { - final GFImageOverlay image = GFImageOverlay( - image: bgImage, - color: color, - padding: padding, - boxFit: boxFit, - margin: margin, - child: childWidget); - - final TestApp app = TestApp(image); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.image.image, bgImage); - expect(app.image.color, color); - expect(app.image.padding, padding); - expect(app.image.boxFit, boxFit); - expect(app.image.margin, margin); - expect(app.image.child, childWidget); - }); - - testWidgets('GF Image with border & border radius.', (tester) async { - final borderRadius = BorderRadius.circular(10); - final border = Border.all(color: Colors.red); - - final GFImageOverlay image = GFImageOverlay( - image: bgImage, - color: color, - border: border, - borderRadius: borderRadius, - padding: padding, - margin: margin, - ); - - final TestApp app = TestApp(image); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.image.image, bgImage); - expect(app.image.color, color); - expect(app.image.border, border); - expect(app.image.borderRadius, borderRadius); - expect(app.image.padding, padding); - expect(app.image.margin, margin); - }); - - testWidgets('GF Image with child icon.', (tester) async { - const content = Icon(Icons.car_rental); - - const GFImageOverlay image = GFImageOverlay( - image: bgImage, - color: color, - child: content, - ); - const TestApp app = TestApp(image); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - expect(app.image.image, bgImage); - expect(app.image.color, color); - expect(app.image.child, content); - }); - - testWidgets('GF Image with circular shape', (tester) async { - const shape = BoxShape.circle; - - const GFImageOverlay image = GFImageOverlay( - image: bgImage, - shape: shape, - ); - - const TestApp app = TestApp(image); - - expect(app.image.image, bgImage); - expect(app.image.shape, shape); - }); - - testWidgets('GF Image with image overlay', (tester) async { - const colorFilter = ColorFilter.mode(Colors.black26, BlendMode.colorBurn); - - const GFImageOverlay image = GFImageOverlay( - image: bgImage, - colorFilter: colorFilter, - ); - - const TestApp app = TestApp(image); - - expect(app.image.image, bgImage); - expect(app.image.colorFilter, colorFilter); - }); - - testWidgets('GF Image with alignment of child widget', (tester) async { - const alignment = Alignment.bottomCenter; - - const GFImageOverlay image = GFImageOverlay( - image: bgImage, - alignment: alignment, - ); - - const TestApp app = TestApp(image); - - expect(app.image.image, bgImage); - expect(app.image.alignment, alignment); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.image); - final GFImageOverlay image; - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.image, - ], - ), - ), - ); -} diff --git a/test/intro_screen_test.dart b/test/intro_screen_test.dart deleted file mode 100644 index 4bba1cd5..00000000 --- a/test/intro_screen_test.dart +++ /dev/null @@ -1,536 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -class StateMarker extends StatefulWidget { - const StateMarker({Key? key, this.child}) : super(key: key); - final Widget? child; - @override - StateMarkerState createState() => StateMarkerState(); -} - -class StateMarkerState extends State { - String? marker; - @override - Widget build(BuildContext context) { - if (widget.child != null) { - return widget.child!; - } - return Container(); - } -} - -void main() { - final Key bottomBarKey = UniqueKey(); - final Key introScreenKey = UniqueKey(); - final PageController _pageController = PageController( - initialPage: 0, - ); - final int initialPage = _pageController.initialPage; - final List slideList = [ - Container(color: Colors.teal, child: const Text('Page 1')), - Container(color: Colors.amber, child: const Text('Page 2')), - Container(color: Colors.blueGrey, child: const Text('Page 3')), - Container(color: Colors.orange, child: const Text('Page 4')), - ]; - final textList = ['Page 1', 'Page 2', 'Page 3', 'Page 4']; - final List slide = [ - Container(color: Colors.teal, child: Text(textList[0])), - Container(color: Colors.amber, child: Text(textList[1])), - Container(color: Colors.blueGrey, child: Text(textList[2])), - Container(color: Colors.orange, child: Text(textList[3])), - ]; - String value = textList[0]; - - testWidgets('Basic GFIntroScreen can be constructed', (tester) async { - final GFIntroScreen introScreen = GFIntroScreen( - key: introScreenKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: slide.length, - slides: slide.map((data) => StateMarker(child: data)).toList()); - - StateMarkerState findStateMarkerState(String name) => - tester.state(find.widgetWithText(StateMarker, name)); - - final TestApp app = TestApp(introScreen); - await tester.pumpWidget(app); - - // find intro screen by key - expect(find.byKey(introScreenKey), findsOneWidget); - // find first screen text - expect(find.text('Page 1'), findsOneWidget); - - TestGesture gesture = - await tester.startGesture(tester.getCenter(find.text('Page 1'))); - await gesture.moveBy(const Offset(-600, 0)); - await tester.pump(); - expect(value, equals(textList[0])); - findStateMarkerState(textList[1]).marker = 'marked'; - await gesture.up(); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - value = textList[_pageController.page!.toInt()]; - expect(value, equals(textList[1])); - await tester.pumpWidget(app); - expect(findStateMarkerState(textList[1]).marker, equals('marked')); - - // slide on to the third tab. - gesture = - await tester.startGesture(tester.getCenter(find.text(textList[1]))); - await gesture.moveBy(const Offset(-600, 0)); - await gesture.up(); - await tester.pump(); - expect(findStateMarkerState(textList[1]).marker, equals('marked')); - await tester.pump(const Duration(seconds: 1)); - value = textList[_pageController.page!.toInt()]; - expect(value, equals(textList[2])); - await tester.pumpWidget(app); - expect(find.text(textList[1]), findsNothing); - // slide back to the second tab. - gesture = - await tester.startGesture(tester.getCenter(find.text(textList[2]))); - await gesture.moveBy(const Offset(600, 0)); - await tester.pump(); - final StateMarkerState markerState = findStateMarkerState(textList[1]); - expect(markerState.marker, isNull); - markerState.marker = 'marked'; - await gesture.up(); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - value = textList[_pageController.page!.toInt()]; - expect(value, equals(textList[1])); - await tester.pumpWidget(app); - expect(findStateMarkerState(textList[1]).marker, equals('marked')); - }); - - testWidgets( - 'Basic GFIntroScreen can be constructed with GFIntroScreenBottomNavigationBar', - (tester) async { - final PageController _pageController = PageController( - initialPage: 0, - ); - final int initialPage = _pageController.initialPage; - - final GFIntroScreen introScreen = GFIntroScreen( - key: introScreenKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: slide.length, - slides: slide.map((data) => StateMarker(child: data)).toList(), - showIntroScreenBottomNavigationBar: true, - introScreenBottomNavigationBar: GFIntroScreenBottomNavigationBar( - key: bottomBarKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: 4, - ), - ); - - final TestApp app = TestApp(introScreen); - await tester.pumpWidget(app); - - // find intro screen by key - expect(find.byKey(bottomBarKey), findsOneWidget); - // find intro screen by key - expect(find.byKey(introScreenKey), findsOneWidget); - // find first screen text - expect(find.text('Page 1'), findsOneWidget); - expect(find.byKey(bottomBarKey), findsOneWidget); - expect(introScreen.showIntroScreenBottomNavigationBar, isTrue); - expect(_pageController, isNotNull); - expect(_pageController.initialPage, 0); - expect(_pageController.page!.toInt(), 0); - await tester.tap(find.text('NEXT')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 1); - expect(find.text('Page 2'), findsOneWidget); - await tester.tap(find.text('NEXT')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 2); - expect(find.text('Page 3'), findsOneWidget); - await tester.tap(find.text('BACK')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 1); - expect(find.text('Page 2'), findsOneWidget); - }); - - testWidgets( - 'Basic GFIntroScreenBottomNavigationBar can be constructed with no pagination and custom button text', - (tester) async { - final PageController _pageController = PageController( - initialPage: 0, - ); - final int initialPage = _pageController.initialPage; - - final GFIntroScreen introScreen = GFIntroScreen( - key: introScreenKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: slide.length, - slides: slide.map((data) => StateMarker(child: data)).toList(), - showIntroScreenBottomNavigationBar: true, - introScreenBottomNavigationBar: GFIntroScreenBottomNavigationBar( - key: bottomBarKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: 4, - showPagination: false, - forwardButtonText: 'go to next', - backButtonText: 'back to previous', - skipButtonText: 'skip to last', - doneButtonText: 'done, start from first', - onForwardButtonTap: () { - _pageController.nextPage( - duration: const Duration(milliseconds: 500), - curve: Curves.linear); - }, - onBackButtonTap: () { - _pageController.previousPage( - duration: const Duration(milliseconds: 500), - curve: Curves.linear); - }, - onSkipTap: () { - _pageController.jumpToPage(3); - }, - onDoneTap: () { - _pageController.jumpToPage(0); - }, - backButtonTextStyle: const TextStyle(fontSize: 12), - doneButtonTextStyle: const TextStyle(fontSize: 12), - forwardButtonTextStyle: const TextStyle(fontSize: 12), - skipButtonTextStyle: const TextStyle(fontSize: 12), - ), - ); - - final TestApp app = TestApp(introScreen); - await tester.pumpWidget(app); - - // find intro screen by key - expect(find.byKey(introScreenKey), findsOneWidget); - // find first screen text - expect(find.text('Page 1'), findsOneWidget); - expect(find.byKey(bottomBarKey), findsOneWidget); - expect(introScreen.showIntroScreenBottomNavigationBar, isTrue); - expect(_pageController, isNotNull); - // on first screen - expect(_pageController.initialPage, 0); - expect(_pageController.page!.toInt(), 0); - // tap go to next, to go to second screen - await tester.tap(find.text('go to next')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 1); - // find second screen - expect(find.text('Page 2'), findsOneWidget); - // tap back to previous to go back to first screen - await tester.tap(find.text('back to previous')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 0); - // find first screen - expect(find.text('Page 1'), findsOneWidget); - // tap skip to last, to jump to last screen - await tester.tap(find.text('skip to last')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 3); - // find fourth screen - expect(find.text('Page 4'), findsOneWidget); - // tap done, start from first to jump to first screen - await tester.tap(find.text('done, start from first')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 0); - // find first screen - expect(find.text('Page 1'), findsOneWidget); - }); - - testWidgets( - 'Basic GFIntroScreenBottomNavigationBar can be constructed with no pagination and custom button', - (tester) async { - final PageController _pageController = PageController( - initialPage: 0, - ); - final int initialPage = _pageController.initialPage; - - final GFIntroScreen introScreen = GFIntroScreen( - key: introScreenKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: slide.length, - slides: slide.map((data) => StateMarker(child: data)).toList(), - showIntroScreenBottomNavigationBar: true, - introScreenBottomNavigationBar: GFIntroScreenBottomNavigationBar( - key: bottomBarKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: 4, - showPagination: false, - forwardButton: GFButton( - onPressed: () { - _pageController.nextPage( - duration: const Duration(milliseconds: 500), - curve: Curves.linear); - }, - child: const Text('go to next'), - ), - backButton: GFButton( - onPressed: () { - _pageController.previousPage( - duration: const Duration(milliseconds: 500), - curve: Curves.linear); - }, - child: const Text('back to previous'), - ), - skipButton: GFButton( - onPressed: () { - _pageController.jumpToPage(3); - }, - child: const Text('skip to last'), - ), - doneButton: GFButton( - onPressed: () { - _pageController.jumpToPage(0); - }, - child: const Text('done, start from first'), - ), - ), - ); - - final TestApp app = TestApp(introScreen); - await tester.pumpWidget(app); - - // find intro screen by key - expect(find.byKey(introScreenKey), findsOneWidget); - // find first screen text - expect(find.text('Page 1'), findsOneWidget); - expect(find.byKey(bottomBarKey), findsOneWidget); - expect(introScreen.showIntroScreenBottomNavigationBar, isTrue); - expect(_pageController, isNotNull); - // on first screen - expect(_pageController.initialPage, 0); - expect(_pageController.page!.toInt(), 0); - // tap go to next, to go to second screen - await tester.tap(find.text('go to next')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 1); - // find second screen - expect(find.text('Page 2'), findsOneWidget); - // tap back to previous to go back to first screen - await tester.tap(find.text('back to previous')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 0); - // find first screen - expect(find.text('Page 1'), findsOneWidget); - // tap skip to last, to jump to last screen - await tester.tap(find.text('skip to last')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 3); - // find fourth screen - expect(find.text('Page 4'), findsOneWidget); - // tap done, start from first to jump to first screen - await tester.tap(find.text('done, start from first')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(_pageController.page!.toInt(), 0); - // find first screen - expect(find.text('Page 1'), findsOneWidget); - }); - - testWidgets( - 'Basic GFIntroScreenBottomNavigationBar can be constructed with custom pagination and no buttons', - (tester) async { - final PageController _pageController = PageController( - initialPage: 0, - ); - final int initialPage = _pageController.initialPage; - - final GFIntroScreen introScreen = GFIntroScreen( - key: introScreenKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: slide.length, - slides: slide.map((data) => StateMarker(child: data)).toList(), - showIntroScreenBottomNavigationBar: true, - introScreenBottomNavigationBar: GFIntroScreenBottomNavigationBar( - key: bottomBarKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: 4, - showButton: false, - dotHeight: 10, - dotWidth: 16, - dotShape: RoundedRectangleBorder( - side: const BorderSide(color: Colors.red, width: 2), - borderRadius: BorderRadius.circular(5)), - inactiveColor: Colors.black12, - activeColor: Colors.black87, - dotMargin: const EdgeInsets.symmetric(horizontal: 6), - ), - ); - - final TestApp app = TestApp(introScreen); - await tester.pumpWidget(app); - - // find intro screen by key - expect(find.byKey(introScreenKey), findsOneWidget); - // find first screen text - expect(find.text('Page 1'), findsOneWidget); - expect(find.byKey(bottomBarKey), findsOneWidget); - expect(introScreen.showIntroScreenBottomNavigationBar, isTrue); - expect(_pageController, isNotNull); - // on first screen - expect(_pageController.initialPage, 0); - expect(_pageController.page!.toInt(), 0); - expect(introScreen.currentIndex, _pageController.page!.toInt()); - }); - - testWidgets( - 'Basic GFIntroScreenBottomNavigationBar can be constructed with custom child', - (tester) async { - final PageController _pageController = PageController( - initialPage: 0, - ); - final int initialPage = _pageController.initialPage; - - final GFIntroScreen introScreen = GFIntroScreen( - key: introScreenKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: slide.length, - slides: slide.map((data) => StateMarker(child: data)).toList(), - showIntroScreenBottomNavigationBar: true, - introScreenBottomNavigationBar: GFIntroScreenBottomNavigationBar( - key: bottomBarKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: 4, - child: const Text('bottom bar'), - ), - ); - - final TestApp app = TestApp(introScreen); - await tester.pumpWidget(app); - - // find intro screen by key - expect(find.byKey(introScreenKey), findsOneWidget); - // find first screen text - expect(find.text('Page 1'), findsOneWidget); - expect(find.byKey(bottomBarKey), findsOneWidget); - // find first screen text - expect(find.text('bottom bar'), findsOneWidget); - }); - - testWidgets( - 'Customized GFIntroScreenBottomNavigationBar can be constructed with properties', - (tester) async { - final PageController _pageController = PageController( - initialPage: 0, - ); - final int initialPage = _pageController.initialPage; - - final GFIntroScreen introScreen = GFIntroScreen( - key: introScreenKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: slide.length, - slides: slide.map((data) => StateMarker(child: data)).toList(), - showIntroScreenBottomNavigationBar: true, - introScreenBottomNavigationBar: GFIntroScreenBottomNavigationBar( - key: bottomBarKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: 4, - navigationBarHeight: 60, - navigationBarWidth: 400, - navigationBarMargin: const EdgeInsets.all(6), - navigationBarPadding: const EdgeInsets.all(5), - navigationBarShape: RoundedRectangleBorder( - side: const BorderSide(color: Colors.teal, width: 1), - borderRadius: BorderRadius.circular(5), - ), - navigationBarColor: Colors.amber, - showDivider: true, - dividerHeight: 2, - dividerThickness: 4, - dividerColor: Colors.black, - dotHeight: 10, - dotWidth: 16, - dotShape: RoundedRectangleBorder( - side: const BorderSide(color: Colors.red, width: 2), - borderRadius: BorderRadius.circular(5)), - inactiveColor: Colors.black12, - activeColor: Colors.black87, - dotMargin: const EdgeInsets.symmetric(horizontal: 6), - ), - ); - - final TestApp app = TestApp(introScreen); - await tester.pumpWidget(app); - - // find intro screen by key - expect(find.byKey(bottomBarKey), findsOneWidget); - expect(app.introScreen.pageController, _pageController); - expect(app.introScreen.currentIndex, initialPage); - expect(app.introScreen.pageCount, 4); - }); - - testWidgets('Customized GFIntroScreen can be constructed with properties', - (tester) async { - final GFIntroScreen introScreen = GFIntroScreen( - key: introScreenKey, - pageController: _pageController, - currentIndex: initialPage, - pageCount: slideList.length, - slides: slideList, - height: 500, - width: 300, - color: Colors.blueGrey, - borderRadius: BorderRadius.circular(4), - border: Border.all(color: Colors.blueGrey.shade700, width: 3), - ); - - final TestApp app = TestApp(introScreen); - await tester.pumpWidget(app); - - // find introScreen by key - expect(find.byKey(introScreenKey), findsOneWidget); - // find first screen text - expect(find.text('Page 1'), findsOneWidget); - - expect(app.introScreen.pageCount, 4); - expect(app.introScreen.currentIndex, initialPage); - expect(app.introScreen.height, 500); - expect(app.introScreen.width, 300); - expect(app.introScreen.color, Colors.blueGrey); - expect(app.introScreen.borderRadius, BorderRadius.circular(4)); - expect(app.introScreen.border, - Border.all(color: Colors.blueGrey.shade700, width: 3)); - expect(app.introScreen.showIntroScreenBottomNavigationBar, isFalse); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.introScreen); - - final GFIntroScreen introScreen; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: widget.introScreen, - ), - ); -} diff --git a/test/items_carousel_test.dart b/test/items_carousel_test.dart deleted file mode 100644 index 002d3b33..00000000 --- a/test/items_carousel_test.dart +++ /dev/null @@ -1,116 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -class StateMarker extends StatefulWidget { - const StateMarker({Key? key, this.child}) : super(key: key); - final Widget? child; - @override - StateMarkerState createState() => StateMarkerState(); -} - -class StateMarkerState extends State { - String? marker; - @override - Widget build(BuildContext context) { - if (widget.child != null) { - return widget.child!; - } - return Container(); - } -} - -void main() { - final Key carouselKey = UniqueKey(); - final List textList = [ - 'AAAAAA', - 'BBBBBB', - 'CCCCCC', - 'DDDDDD', - 'EEEEEE' - ]; - final List itemList = [ - Text(textList[0]), - Text(textList[1]), - Text(textList[2]), - Text(textList[3]), - Text(textList[4]) - ]; - - testWidgets('GFItemsCarousel can be constructed', (tester) async { - final GFItemsCarousel carousel = GFItemsCarousel( - key: carouselKey, - rowCount: 3, - children: itemList.map((text) => StateMarker(child: text)).toList(), - ); - - StateMarkerState findStateMarkerState(String name) => - tester.state(find.widgetWithText(StateMarker, name)); - - final TestApp app = TestApp(carousel); - await tester.pumpWidget(app); - - // find carousel by key - expect(find.byKey(carouselKey), findsOneWidget); - // find the 'AAAAAA', 'BBBBBB' and 'CCCCCC' text in carousel - expect(find.text('AAAAAA'), findsOneWidget); - expect(find.text('BBBBBB'), findsOneWidget); - expect(find.text('CCCCCC'), findsOneWidget); - - // slide to the second slide. - - TestGesture gesture = - await tester.startGesture(tester.getCenter(find.text('AAAAAA'))); - await gesture.moveBy(const Offset(-600, 0)); - await tester.pump(); - findStateMarkerState(textList[1]).marker = 'marked'; - await gesture.up(); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - // find the 'CCCCCC', 'DDDDDD' and 'EEEEEE' text in carousel - expect(find.text('DDDDDD'), findsOneWidget); - expect(find.text('EEEEEE'), findsOneWidget); - expect(find.text('CCCCCC'), findsOneWidget); - await tester.pumpWidget(app); - expect(findStateMarkerState(textList[1]).marker, equals('marked')); - - // slide back to the first slide. - gesture = - await tester.startGesture(tester.getCenter(find.text(textList[2]))); - await gesture.moveBy(const Offset(600, 0)); - await tester.pump(); - final StateMarkerState markerState = findStateMarkerState(textList[1]); - markerState.marker = 'marked'; - await gesture.up(); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - // find the 'AAAAAA', 'BBBBBB' and 'CCCCCC' text in carousel - expect(find.text('AAAAAA'), findsOneWidget); - expect(find.text('BBBBBB'), findsOneWidget); - expect(find.text('CCCCCC'), findsOneWidget); - await tester.pumpWidget(app); - expect(findStateMarkerState(textList[1]).marker, equals('marked')); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.carousel); - - final GFItemsCarousel carousel; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.carousel, - ], - ), - ), - ); -} diff --git a/test/list_tile_test.dart b/test/list_tile_test.dart deleted file mode 100644 index 43ab7ce7..00000000 --- a/test/list_tile_test.dart +++ /dev/null @@ -1,188 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final Key listTileKey = UniqueKey(); - - testWidgets('GFListTile can be constructed', (tester) async { - const title = 'title text'; - const subTitle = 'sub title text'; - const icon = Icon(Icons.favorite); - const avatar = GFAvatar( - backgroundColor: Colors.tealAccent, - ); - const description = Text('description'); - - final GFListTile listTile = GFListTile( - key: listTileKey, - titleText: title, - subTitleText: subTitle, - color: Colors.teal, - avatar: avatar, - icon: icon, - description: description, - ); - - final TestApp app = TestApp(listTile); - await tester.pumpWidget(app); - - // find listTile by key - expect(find.byKey(listTileKey), findsOneWidget); - // find title text - expect(find.text('title text'), findsOneWidget); - // find sub title text - expect(find.text('sub title text'), findsOneWidget); - // find description - expect(find.text('description'), findsOneWidget); - // find icon - expect(find.byIcon(Icons.favorite), findsOneWidget); - // find avatar - expect(find.byType(GFAvatar), findsOneWidget); - - expect(app.tile.avatar, avatar); - expect(app.tile.titleText, title); - expect(app.tile.subTitleText, subTitle); - expect(app.tile.description, description); - expect(app.tile.icon, icon); - expect(app.tile.color, Colors.teal); - }); - - testWidgets('GFListTile can be constructed with text', (tester) async { - var i = 5; - final titleText = Text('title $i'); - const subTitleText = Text('sub title'); - const icon = Icon(Icons.favorite); - const avatar = GFAvatar( - backgroundColor: Colors.tealAccent, - ); - const description = Text('description'); - - final GFListTile listTile = GFListTile( - key: listTileKey, - title: titleText, - subTitle: subTitleText, - color: Colors.teal, - avatar: avatar, - icon: icon, - description: description, - padding: const EdgeInsets.all(6), - margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 6), - onTap: () { - i++; - print('tapped $i'); - }, - onLongPress: () { - i--; - print('long pressed $i'); - }, - ); - - final TestApp app = TestApp(listTile); - await tester.pumpWidget(app); - - // find listTile by key - expect(find.byKey(listTileKey), findsOneWidget); - // find title text - expect(find.text('title 5'), findsOneWidget); - // find sub title text - expect(find.text('sub title'), findsOneWidget); - // find description - expect(find.text('description'), findsOneWidget); - // find icon - expect(find.byIcon(Icons.favorite), findsOneWidget); - // find avatar - expect(find.byType(GFAvatar), findsOneWidget); - await tester.tap(find.text('title 5')); - await tester.pump(); - await tester.longPress(find.text('sub title')); - await tester.pump(); - - expect(app.tile.avatar, avatar); - expect(app.tile.title, titleText); - expect(app.tile.subTitle, subTitleText); - expect(app.tile.description, description); - expect(app.tile.icon, icon); - expect(app.tile.color, Colors.teal); - expect(app.tile.padding, const EdgeInsets.all(6)); - expect(app.tile.margin, - const EdgeInsets.symmetric(vertical: 8, horizontal: 6)); - }); - - testWidgets('GFListTile can be constructed with hover color and focus color', - (tester) async { - const titleText = Text('title'); - const subTitleText = Text('sub title'); - const icon = Icon(Icons.favorite); - const avatar = GFAvatar( - backgroundColor: Colors.tealAccent, - ); - const description = Text('description'); - final FocusNode focusNode = FocusNode(debugLabel: 'GFListTile'); - - final GFListTile listTile = GFListTile( - key: listTileKey, - title: titleText, - subTitle: subTitleText, - color: Colors.teal, - avatar: avatar, - icon: icon, - description: description, - enabled: true, - focusColor: Colors.amber, - hoverColor: Colors.blue, - focusNode: focusNode, - autofocus: true, - ); - - final TestApp app = TestApp(listTile); - await tester.pumpWidget(app); - - // find listTile by key - expect(find.byKey(listTileKey), findsOneWidget); - // find title text - expect(find.text('title'), findsOneWidget); - // find sub title text - expect(find.text('sub title'), findsOneWidget); - // find description - expect(find.text('description'), findsOneWidget); - // find icon - expect(find.byIcon(Icons.favorite), findsOneWidget); - // find avatar - expect(find.byType(GFAvatar), findsOneWidget); - - await tester.pumpAndSettle(); - - expect(app.tile.avatar, avatar); - expect(app.tile.title, titleText); - expect(app.tile.subTitle, subTitleText); - expect(app.tile.description, description); - expect(app.tile.icon, icon); - expect(app.tile.avatar, avatar); - expect(app.tile.color, Colors.teal); - expect(app.tile.focusColor, Colors.amber); - expect(app.tile.hoverColor, Colors.blue); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.tile); - - final GFListTile tile; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.tile, - ], - ), - ), - ); -} diff --git a/test/loader_test.dart b/test/loader_test.dart deleted file mode 100644 index 50c05e29..00000000 --- a/test/loader_test.dart +++ /dev/null @@ -1,207 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final Widget childWidget = Container( - width: 111, - height: 222, - ); - - const iconOne = Icon(Icons.directions_bike_sharp); - const iconTwo = Icon(Icons.directions_car); - const iconThree = Icon(Icons.directions_bus); - - const duration = Duration(milliseconds: 1000); - - const firstColor = Colors.teal; - const secondColor = Colors.tealAccent; - const thirdColor = Colors.tealAccent; - - const stroke = 4.0; - - debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - - testWidgets('GF Loader can be constructed', (tester) async { - final GFLoader loader = GFLoader( - loaderColorOne: firstColor, - loaderColorTwo: secondColor, - duration: duration, - type: GFLoaderType.ios, - loaderIconOne: iconOne, - loaderstrokeWidth: stroke, - size: GFSize.MEDIUM, - child: childWidget, - ); - - final TestApp app = TestApp(loader); - - await tester.pumpWidget(app); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - await tester.pump(duration); - - expect(app.loader.child, childWidget); - expect(app.loader.loaderIconOne, iconOne); - expect(app.loader.loaderColorOne, firstColor); - expect(app.loader.loaderstrokeWidth, stroke); - expect(app.loader.size, GFSize.MEDIUM); - - debugDefaultTargetPlatformOverride = null; - }); - - testWidgets('Basic GF Loader can be constructed', (tester) async { - const GFLoader loader = GFLoader(); - - const TestApp app = TestApp(loader); - - await tester.pumpWidget(app); - }); - - testWidgets('GF Loader with icons can be constructed', (tester) async { - const customType = GFLoaderType.custom; - - const GFLoader loader = GFLoader( - type: customType, - duration: duration, - loaderIconOne: iconOne, - loaderIconTwo: iconTwo, - loaderIconThree: iconThree, - loaderstrokeWidth: stroke, - ); - - const TestApp app = TestApp(loader); - - await tester.pumpWidget(app); - - await tester.pump(duration); - - expect(app.loader.type, customType); - expect(app.loader.loaderIconOne, iconOne); - expect(app.loader.loaderIconTwo, iconTwo); - expect(app.loader.loaderIconThree, iconThree); - expect(app.loader.loaderstrokeWidth, stroke); - }); - - testWidgets('GF Loader with square type can be constructed', (tester) async { - const customType = GFLoaderType.square; - - const GFLoader loader = GFLoader( - type: customType, - duration: duration, - loaderColorOne: firstColor, - loaderColorTwo: secondColor, - loaderColorThree: thirdColor, - loaderstrokeWidth: stroke, - ); - - const TestApp app = TestApp(loader); - - await tester.pumpWidget(app); - - await tester.pump(duration); - - expect(app.loader.type, customType); - expect(app.loader.loaderColorOne, firstColor); - expect(app.loader.loaderColorTwo, secondColor); - expect(app.loader.loaderColorThree, thirdColor); - expect(app.loader.loaderstrokeWidth, stroke); - }); - - testWidgets('GF Loader with round type can be constructed', (tester) async { - const customType = GFLoaderType.circle; - - const GFLoader loader = GFLoader( - type: customType, - duration: duration, - loaderColorOne: firstColor, - loaderColorTwo: secondColor, - loaderColorThree: thirdColor, - loaderstrokeWidth: stroke, - ); - - const TestApp app = TestApp(loader); - - await tester.pumpWidget(app); - - await tester.pump(duration); - - expect(app.loader.type, customType); - expect(app.loader.loaderColorOne, firstColor); - expect(app.loader.loaderColorTwo, secondColor); - expect(app.loader.loaderColorThree, thirdColor); - expect(app.loader.loaderstrokeWidth, stroke); - }); - - testWidgets('GF Loader with android type loader can be constructed', - (tester) async { - const customType = GFLoaderType.android; - const color = AlwaysStoppedAnimation(Colors.green); - - const GFLoader loader = - GFLoader(type: customType, androidLoaderColor: color); - - const TestApp app = TestApp(loader); - - await tester.pumpWidget(app); - - expect(app.loader.type, customType); - expect(app.loader.androidLoaderColor, color); - }); - - testWidgets('GF Loader with custom loader can be constructed using child', - (tester) async { - const customType = GFLoaderType.custom; - - final GFLoader loader = GFLoader(type: customType, child: childWidget); - - final TestApp app = TestApp(loader); - - await tester.pumpWidget(app); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - await tester.pump(duration); - - expect(app.loader.child, childWidget); - expect(app.loader.type, customType); - }); - - testWidgets('Custom GF Loader can be constructed with wrong type', - (tester) async { - const GFLoader loader = GFLoader( - type: GFLoaderType.custom, - loaderIconOne: iconOne, - ); - - const TestApp app = TestApp(loader); - - await tester.pumpWidget(app); - expect(app.loader.type, GFLoaderType.custom, reason: 'custom icon'); - expect(app.loader.loaderIconOne, iconOne); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.loader); - - final GFLoader loader; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.loader, - ], - ), - ), - ); -} diff --git a/test/radio_list_tile_test.dart b/test/radio_list_tile_test.dart deleted file mode 100644 index bc3f2bbc..00000000 --- a/test/radio_list_tile_test.dart +++ /dev/null @@ -1,269 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -Widget wrap({Widget? child}) => MediaQuery( - data: const MediaQueryData(), - child: Directionality( - textDirection: TextDirection.ltr, - child: Material(child: child), - ), - ); - -void main() { - final UniqueKey radioKey = UniqueKey(); - const int groupValue = 0; - testWidgets('GFRadioListTile can be constructed Function call Null', - (tester) async { - final GFRadioListTile radioListTile = GFRadioListTile( - key: radioKey, - onChanged: null, - value: 2, - groupValue: groupValue, - toggleable: false, - ); - - final TestApp app = TestApp(radioListTile); - await tester.pumpWidget(app); - await tester.pump(); - expect(find.byKey(radioKey), findsOneWidget); - expect(app.radioListTile.onChanged, null); - expect( - app.radioListTile.value, - 2, - ); - }); - - testWidgets('GFRadioListTile can be constructed Function call Null', - (tester) async { - final GFRadioListTile radioListTile = GFRadioListTile( - key: radioKey, - onChanged: null, - value: 2, - groupValue: groupValue, - toggleable: false, - ); - - final TestApp app = TestApp(radioListTile); - await tester.pumpWidget(app); - await tester.pump(); - expect(find.byKey(radioKey), findsOneWidget); - expect(app.radioListTile.onChanged, null); - expect( - app.radioListTile.value, - 2, - ); - }); - - testWidgets('GFRadioListTile should initialize according to groupValue', - (WidgetTester tester) async { - final List values = [0, 1, 2]; - int groupValue = 0; - final Type radioListTileType = const GFRadioListTile( - value: 0, - groupValue: 0, - onChanged: null, - ).runtimeType; - - List> generatedRadioListTiles; - List> findTiles() => find - .byType(radioListTileType) - .evaluate() - .map((Element element) => element.widget) - .cast>() - .toList(); - - Widget buildFrame() => wrap( - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Scaffold( - body: ListView.builder( - itemCount: values.length, - itemBuilder: (BuildContext context, int index) => - GFRadioListTile( - groupValue: groupValue, - onChanged: (value) { - setState(() { - groupValue = value; - }); - }, - value: values[index], - title: Text(values[index].toString()), - ), - ), - ), - ), - ); - - await tester.pumpWidget(buildFrame()); - generatedRadioListTiles = findTiles(); - - // first RadioButton is True then other option false - print(generatedRadioListTiles[0].checked); - print(generatedRadioListTiles[1].checked); - print(generatedRadioListTiles[2].checked); - print('*************'); - expect(generatedRadioListTiles[0].checked, equals(true)); - expect(generatedRadioListTiles[1].checked, equals(false)); - expect(generatedRadioListTiles[2].checked, equals(false)); - - // Second RadioButton is True then other option false - groupValue = 1; - await tester.pumpWidget(buildFrame()); - generatedRadioListTiles = findTiles(); - print(generatedRadioListTiles[0].checked); - print(generatedRadioListTiles[1].checked); - print(generatedRadioListTiles[2].checked); - print('*************'); - - expect(generatedRadioListTiles[0].checked, equals(false)); - expect(generatedRadioListTiles[1].checked, equals(true)); - expect(generatedRadioListTiles[2].checked, equals(false)); - - // third RadioButton is True then other option false - groupValue = 2; - await tester.pumpWidget(buildFrame()); - generatedRadioListTiles = findTiles(); - print(generatedRadioListTiles[0].checked); - print(generatedRadioListTiles[1].checked); - print(generatedRadioListTiles[2].checked); - print('*************'); - - expect(generatedRadioListTiles[0].checked, equals(false)); - expect(generatedRadioListTiles[1].checked, equals(false)); - expect(generatedRadioListTiles[2].checked, equals(true)); - }); - - testWidgets('GFRadioListTile simple control test', - (WidgetTester tester) async { - final Key key = UniqueKey(); - final Key titleKey = UniqueKey(); - final List log = []; - - await tester.pumpWidget( - wrap( - child: GFRadioListTile( - key: key, - value: 1, - groupValue: 2, - onChanged: log.add, - title: Text('Title', key: titleKey), - ), - ), - ); - - await tester.tap(find.byKey(key)); - - expect(log, equals([1])); - log.clear(); - - await tester.pumpWidget( - wrap( - child: GFRadioListTile( - key: key, - value: 1, - groupValue: 1, - onChanged: log.add, - // activeColor: Colors.green[500], - title: Text('Title', key: titleKey), - ), - ), - ); - - await tester.tap(find.byKey(key)); - - expect(log, isEmpty); - - await tester.pumpWidget( - wrap( - child: GFRadioListTile( - key: key, - value: 1, - groupValue: 2, - onChanged: null, - title: Text('Title', key: titleKey), - ), - ), - ); - - await tester.tap(find.byKey(key)); - - expect(log, isEmpty); - - await tester.pumpWidget( - wrap( - child: GFRadioListTile( - key: key, - value: 1, - groupValue: 2, - onChanged: log.add, - title: Text('Title', key: titleKey), - ), - ), - ); - - await tester.tap(find.byKey(titleKey)); - - expect(log, equals([1])); - }); - - testWidgets('GFRadioListTile control tests', (WidgetTester tester) async { - final List values = [0, 1, 2]; - int groupValue = 0; - - final List log = []; - - Widget buildFrame() => wrap( - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Scaffold( - body: ListView.builder( - itemCount: values.length, - itemBuilder: (BuildContext context, int index) => - GFRadioListTile( - groupValue: groupValue, - onChanged: (value) { - log.add(value); - setState(() { - groupValue = value; - }); - }, - value: values[index], - title: Text(values[index].toString()), - ), - ), - ), - ), - ); - - // Tests for tapping between [Radio] and [ListTile] - await tester.pumpWidget(buildFrame()); - await tester.tap(find.text('0')); - log.add('-'); - print(log); - await tester.tap(find.text('1')); - await tester.tap(find.text('2')); - print(log); - // expect(log, equals(['-', 1, 2] - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.radioListTile); - - final GFRadioListTile radioListTile; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.radioListTile, - ], - ), - ), - ); -} diff --git a/test/radio_test.dart b/test/radio_test.dart deleted file mode 100644 index 9abc5e14..00000000 --- a/test/radio_test.dart +++ /dev/null @@ -1,221 +0,0 @@ -import 'package:flutter/gestures.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final UniqueKey radioKey = UniqueKey(); - const int groupValue = 0; - testWidgets('Radio button can be constructed Function call Null', - (tester) async { - final GFRadio radio = GFRadio( - key: radioKey, - onChanged: null, - value: 2, - groupValue: groupValue, - toggleable: false, - ); - - final TestApp app = TestApp(radio); - await tester.pumpWidget(app); - await tester.pump(); - expect(find.byKey(radioKey), findsOneWidget); - expect(app.radio.onChanged, null); - expect( - app.radio.value, - 2, - ); - }); - - testWidgets('Radio control test', (tester) async { - final List log = []; - const value = 2; - final radiobutton = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFRadio( - key: radioKey, - size: GFSize.SMALL, - value: value, - groupValue: groupValue, - onChanged: log.add, - // (value) { - // setState(() { - // log.add(value); - // }); - // }, - inactiveIcon: null, - activeBorderColor: GFColors.SUCCESS, - radioColor: GFColors.SUCCESS, - ), - )), - ); - await tester.pumpWidget(radiobutton); - expect(find.byKey(radioKey), findsOneWidget); - - await tester.tap(find.byKey(radioKey)); - expect(groupValue, 0); - print(log); - expect(log, equals([2])); - log.clear(); - - print(log); - expect(log, isEmpty); - - await tester.tap(find.byKey(radioKey)); - await tester.pumpAndSettle(); - print(log); - expect(log, equals([2])); - log.clear(); - }); - - testWidgets('Radio can be toggled when toggleable is set', (tester) async { - final List log = []; - const value = 1; - const groupValue = 2; - final radiobutton = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFRadio( - key: radioKey, - size: GFSize.SMALL, - value: value, - groupValue: groupValue, - onChanged: log.add, - // (value) { - // setState(() { - // log.add(value); - // }); - // }, - toggleable: true, - ), - )), - ); - - await tester.pumpWidget(radiobutton); - expect(find.byKey(radioKey), findsOneWidget); - expect(groupValue, 2); - await tester.tap(find.byKey(radioKey)); - await tester.tap(find.byKey(radioKey)); - print(log[0]); - print(log[1]); - expect(log, equals([1, 1])); - log.clear(); - - await tester.pumpAndSettle(); - log.insert(0, 5); - print(log[0]); - expect(log, equals([5])); - log.clear(); - - expect(log, isEmpty); - }); - - testWidgets('Radio size is configurable by themeData', - (WidgetTester tester) async { - final Key key1 = UniqueKey(); - await tester.pumpWidget( - Theme( - data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.padded), - child: Directionality( - textDirection: TextDirection.ltr, - child: Material( - child: Center( - child: GFRadio( - key: key1, - groupValue: true, - value: true, - onChanged: (bool newValue) {}, - size: 20, - ), - ), - ), - ), - ), - ); - - expect(tester.getSize(find.byKey(key1)), const Size(20, 20)); - - final Key key2 = UniqueKey(); - await tester.pumpWidget( - Theme( - data: - ThemeData(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap), - child: Directionality( - textDirection: TextDirection.ltr, - child: Material( - child: Center( - child: GFRadio( - key: key2, - groupValue: true, - value: true, - onChanged: (bool newValue) {}, - size: 40), - ), - ), - ), - ), - ); - - expect(tester.getSize(find.byKey(key2)), const Size(40, 40)); - }); - - testWidgets('Radio changes mouse cursor when hovered Default click', - (WidgetTester tester) async { - const Key key = ValueKey(1); - await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: Align( - alignment: Alignment.topLeft, - child: Material( - child: MouseRegion( - cursor: SystemMouseCursors.forbidden, - child: GFRadio( - key: key, - value: 1, - onChanged: (int? v) {}, - groupValue: 2, - ), - ), - ), - ), - ), - ), - ); - - final TestGesture gesture = - await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1); - await gesture.addPointer(location: tester.getCenter(find.byKey(key))); - addTearDown(gesture.removePointer); - - await tester.pump(); - expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), - SystemMouseCursors.click); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.radio); - - final GFRadio radio; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.radio, - ], - ), - ), - ); -} diff --git a/test/rating_test.dart b/test/rating_test.dart deleted file mode 100644 index 08b7f68d..00000000 --- a/test/rating_test.dart +++ /dev/null @@ -1,211 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final Key ratingKey = UniqueKey(); - final Key buttonKey = UniqueKey(); - - const filledIcon = Icon(Icons.favorite); - const defaultIcon = Icon(Icons.favorite_border); - - testWidgets('GFRating can be constructed', (tester) async { - double _rating = 4; - - final rating = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => GFRating( - key: ratingKey, - value: _rating, - onChanged: (value) { - print('value $value'); - setState(() { - _rating = value; - }); - }, - )), - ); - - await tester.pumpWidget(rating); - - // find rating by key - expect(find.byKey(ratingKey), findsOneWidget); - expect(find.byIcon(Icons.star), findsNWidgets(4)); - expect(find.byIcon(Icons.star_border), findsNWidgets(1)); - await tester.tap(find.byIcon(Icons.star_border)); - await tester.pump(); - expect(find.byIcon(Icons.star), findsNWidgets(5)); - expect(find.byIcon(Icons.star_border), findsNothing); - await tester.tap(find.byIcon(Icons.star).first); - await tester.pump(); - expect(find.byIcon(Icons.star), findsNWidgets(1)); - expect(find.byIcon(Icons.star_border), findsNWidgets(4)); - }); - - testWidgets('GFRating with icons.', (WidgetTester tester) async { - double _rating = 1; - - final rating = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => GFRating( - key: ratingKey, - value: _rating, - defaultIcon: defaultIcon, - filledIcon: filledIcon, - onChanged: (value) { - print('value $value'); - setState(() { - _rating = value; - }); - }, - )), - ); - - await tester.pumpWidget(rating); - - // find rating by key - expect(find.byKey(ratingKey), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsNWidgets(1)); - expect(find.byIcon(Icons.favorite_border), findsNWidgets(4)); - await tester.tap(find.byIcon(Icons.favorite_border).last); - await tester.pump(); - expect(find.byIcon(Icons.favorite), findsNWidgets(5)); - expect(find.byIcon(Icons.favorite_border), findsNothing); - await tester.tap(find.byIcon(Icons.favorite).first); - await tester.pump(); - expect(find.byIcon(Icons.favorite), findsNWidgets(1)); - expect(find.byIcon(Icons.favorite_border), findsNWidgets(4)); - }); - - testWidgets('GFRating with half rating property on dragging.', - (WidgetTester tester) async { - double _rating = 3; - - final rating = GFRating( - key: ratingKey, - value: _rating, - allowHalfRating: true, - onChanged: (value) { - _rating = value; - }, - ); - - final TestApp app = TestApp(rating); - await tester.pumpWidget(app); - - // find rating by key - expect(find.byKey(ratingKey), findsOneWidget); - expect(find.byIcon(Icons.star), findsNWidgets(3)); - expect(find.byIcon(Icons.star_border), findsNWidgets(2)); - // Swipe the item to rate 5 star - await tester.drag(find.byKey(ratingKey), const Offset(158.1, 45.1)); - await tester.pump(); - await tester.pump(const Duration(seconds: 2)); - // find rating 5 star - expect(_rating, 5); - }); - - testWidgets('GF Rating using textFormField data input.', - (WidgetTester tester) async { - final _ratingController = TextEditingController(); - double _rating = 3.5; - _ratingController.text = '3.5'; - - final rating = MaterialApp( - home: Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFRating( - key: ratingKey, - value: _rating, - controller: _ratingController, - showTextForm: true, - suffixIcon: GFButton( - key: buttonKey, - type: GFButtonType.transparent, - onPressed: () { - setState(() { - _rating = double.parse(_ratingController.text); - }); - }, - child: const Text('Rate'), - ), - onChanged: (value) {}, - ), - ), - ), - ), - ); - - await tester.pumpWidget(rating); - - // find rating by key - expect(find.byKey(ratingKey), findsOneWidget); - expect(find.byIcon(Icons.star), findsNWidgets(3)); - expect(find.byIcon(Icons.star_half), findsNWidgets(1)); - expect(find.byIcon(Icons.star_border), findsNWidgets(1)); - await tester.tap(find.byType(TextFormField)); - await tester.pump(); - await tester.enterText(find.byWidget(rating), '4.5'); - expect(find.text('4.5'), findsOneWidget); - await tester.tap(find.byType(GFButton)); - await tester.pumpAndSettle(const Duration(seconds: 5)); - expect(find.byIcon(Icons.star), findsNWidgets(4)); - expect(find.byIcon(Icons.star_half), findsNWidgets(1)); - expect(find.byIcon(Icons.star_border), findsNothing); - }); - - testWidgets('GFRating with all properties.', (WidgetTester tester) async { - double _rating = 3; - - final GFRating rating = GFRating( - key: ratingKey, - value: _rating, - itemCount: 6, - spacing: 6, - color: GFColors.ALT, - borderColor: GFColors.DARK, - size: GFSize.LARGE, - allowHalfRating: false, - showTextForm: false, - onChanged: (value) { - _rating = value; - }, - ); - - final TestApp app = TestApp(rating); - await tester.pumpWidget(app); - - expect(app.rating.value, _rating); - expect(app.rating.itemCount, 6); - expect(app.rating.spacing, 6); - expect(app.rating.color, GFColors.ALT); - expect(app.rating.borderColor, GFColors.DARK); - expect(app.rating.size, GFSize.LARGE); - expect(app.rating.allowHalfRating, isFalse); - expect(app.rating.showTextForm, isFalse); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.rating); - final GFRating rating; - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.rating, - ], - ), - ), - ); -} diff --git a/test/searchbar_test.dart b/test/searchbar_test.dart deleted file mode 100644 index 8136cc75..00000000 --- a/test/searchbar_test.dart +++ /dev/null @@ -1,210 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final Key searchBarKey = UniqueKey(); - const List searchList = [ - 'Flutter', - 'React', - 'Ionic', - 'Xamarin', - 'Flutter2', - 'Angular' - ]; - - const notFound = 'oopsy...no items found'; - - final noItemsFound = Container( - child: const Text(notFound), - ); - - final decoration = InputDecoration( - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Colors.teal, - ), - borderRadius: BorderRadius.circular(50)), - ); - - testWidgets('GF SearchBar can be constructed', (tester) async { - final GFSearchBar searchBar = GFSearchBar( - key: searchBarKey, - searchList: searchList, - overlaySearchListItemBuilder: (item) => Container( - padding: const EdgeInsets.all(8), - child: Text( - item, - style: const TextStyle(fontSize: 18), - ), - ), - searchQueryBuilder: (query, list) => list - .where((item) => item.toLowerCase().contains(query.toLowerCase())) - .toList(), - ); - - final TestApp app = TestApp(searchBar); - await tester.pumpWidget(app); - - // find searchBar by key - expect(find.byKey(searchBarKey), findsOneWidget); - // tap the textField to display overlay search list items - await tester.tap(find.byType(TextField)); - // rebuild the widget - await tester.pump(); - // find overlay search list item - expect(find.text('${searchList[1]}'), findsOneWidget); - // enter 'flutter' to the textField - await tester.enterText(find.byWidget(searchBar), 'flutter'); - // find the text 'flutter' in textField - expect(find.text('flutter'), findsOneWidget); - // find the text 'flutter' in overlay search list items - expect(find.widgetWithText(Container, 'flutter'), findsOneWidget); - // tap the close icon to close the overlay search list items - await tester.tap(find.byIcon(Icons.close)); - // find the text 'flutter' in overlay search list items - expect(find.widgetWithText(Container, 'flutter'), findsNothing); - }); - - testWidgets('Can hide searchBox when item selected', (tester) async { - final GFSearchBar searchBar = GFSearchBar( - key: searchBarKey, - searchList: searchList, - overlaySearchListItemBuilder: (item) => Container( - padding: const EdgeInsets.all(8), - child: Text( - item, - style: const TextStyle(fontSize: 18), - ), - ), - hideSearchBoxWhenItemSelected: true, - searchQueryBuilder: (query, list) => list - .where((item) => item.toLowerCase().contains(query.toLowerCase())) - .toList(), - overlaySearchListHeight: 115, - ); - - final TestApp app = TestApp(searchBar); - await tester.pumpWidget(app); - - // find searchBar by key - expect(find.byKey(searchBarKey), findsOneWidget); - // set searchBar.hideSearchBoxWhenItemSelected = true state to hide searchBar when item selected - expect(app.searchBar.hideSearchBoxWhenItemSelected, isTrue); - // tap the textField to display overlay search list items - await tester.tap(find.byType(TextField)); - // rebuild the widget - await tester.pump(); - // find overlay search list item - expect(find.text('${searchList[1]}'), findsOneWidget); - // tap to select item from overlay search list items - await tester.tap(find.text('${searchList[1]}')); - // rebuild the widget - await tester.pump(); - // find searchBar - expect(find.byType(TextField), findsNothing); - - expect(app.searchBar.hideSearchBoxWhenItemSelected, isTrue); - expect(app.searchBar.overlaySearchListHeight, 115); - }); - - testWidgets('On item selected and when item not found in GFSearchBar List', - (tester) async { - final GFSearchBar searchBar = GFSearchBar( - key: searchBarKey, - searchList: searchList, - overlaySearchListItemBuilder: (item) => Container( - padding: const EdgeInsets.all(8), - child: Text( - item, - style: const TextStyle(fontSize: 18), - ), - ), - searchQueryBuilder: (query, list) => list - .where((item) => item.toLowerCase().contains(query.toLowerCase())) - .toList(), - onItemSelected: (item) { - print('selected item $item'); - }, - noItemsFoundWidget: noItemsFound, - ); - - final TestApp app = TestApp(searchBar); - await tester.pumpWidget(app); - - // find searchBar by key - expect(find.byKey(searchBarKey), findsOneWidget); - // tap the textField to display overlay search list items - await tester.tap(find.byType(TextField)); - // rebuild the widget - await tester.pump(); - // find overlay search list item - expect(find.text('${searchList[1]}'), findsOneWidget); - // enter 'flutter' to the textField - await tester.enterText(find.byWidget(searchBar), 'flu'); - // find text 'flutter' in overlay search list item - expect(find.text('flu'), findsOneWidget); - // find text 'flutter' in overlay search list item - expect(find.text('${searchList[1]}'), findsOneWidget); - // tap to select 'flutter' item from overlay search list items - await tester.tap(find.text('${searchList[1]}')); - // rebuild the widget - await tester.pump(); - // // find overlay search list - // expect(find.text('${searchList[1]}'), findsNothing); - // // enter 'dart' to the textField - // await tester.enterText(find.byWidget(searchBar), 'dart'); - // // find text 'oopsy...no items found' in overlay search list item - // // expect(find.text(notFound), findsOneWidget); - - expect(app.searchBar.noItemsFoundWidget, noItemsFound); - }); - - testWidgets('GFSearchBar with search box input decoration', (tester) async { - final GFSearchBar searchBar = GFSearchBar( - key: searchBarKey, - searchList: searchList, - overlaySearchListItemBuilder: (item) => Container( - padding: const EdgeInsets.all(8), - child: Text( - item, - style: const TextStyle(fontSize: 18), - ), - ), - searchQueryBuilder: (query, list) => list - .where((item) => item.toLowerCase().contains(query.toLowerCase())) - .toList(), - onItemSelected: (item) { - print('selected item $item'); - }, - searchBoxInputDecoration: decoration, - ); - - final TestApp app = TestApp(searchBar); - await tester.pumpWidget(app); - - expect(app.searchBar.searchBoxInputDecoration, decoration); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.searchBar); - - final GFSearchBar searchBar; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.searchBar, - ], - ), - ), - ); -} diff --git a/test/segment_tabs_test.dart b/test/segment_tabs_test.dart deleted file mode 100644 index 62be8943..00000000 --- a/test/segment_tabs_test.dart +++ /dev/null @@ -1,253 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final Key segmentTabsKey = UniqueKey(); - - final List tabList = [ - const Text( - 'Tab1', - ), - const Tab( - icon: Icon(Icons.favorite), - ), - const Text( - 'Tab3', - ), - ]; - - final indicator = BoxDecoration( - color: Colors.teal, - border: Border.all(color: Colors.tealAccent, width: 2)); - - testWidgets('GFSegmentTabs can be constructed', (tester) async { - final TabController tabController = - TabController(length: 3, initialIndex: 0, vsync: tester); - - final GFSegmentTabs segmentTabs = GFSegmentTabs( - key: segmentTabsKey, - tabController: tabController, - length: tabList.length, - tabs: tabList, - ); - - final TestApp app = TestApp(segmentTabs); - await tester.pumpWidget(app); - - // find segmentTabs by key - expect(find.byKey(segmentTabsKey), findsOneWidget); - // find the 'Tab1' text in segmentTabs - expect(find.text('Tab1'), findsOneWidget); - - expect(tabController, isNotNull); - expect(tabController.index, 0); - expect(tabController.previousIndex, 0); - await tester.tap(find.byIcon(Icons.favorite)); - await tester.pump(); - expect(tabController.indexIsChanging, true); - await tester.pump(const Duration(seconds: 1)); - expect(tabController.index, 1); - expect(tabController.previousIndex, 0); - expect(tabController.indexIsChanging, false); - await tester.tap(find.byWidget(tabList[2])); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(tabController.index, 2); - expect(tabController.previousIndex, 1); - await tester.tap(find.text('Tab1')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(tabController.index, 0); - expect(tabController.previousIndex, 2); - }); - - testWidgets('GFSegmentTabs with on taps selected tab', (tester) async { - final TabController tabController = - TabController(length: 3, initialIndex: 0, vsync: tester); - - final GFSegmentTabs segmentTabs = GFSegmentTabs( - key: segmentTabsKey, - tabController: tabController, - length: tabList.length, - tabs: tabList, - ); - - final TestApp app = TestApp(segmentTabs); - await tester.pumpWidget(app); - - // find segmentTabs by key - expect(find.byKey(segmentTabsKey), findsOneWidget); - // find the 'Tab1' text in segmentTabs - expect(find.text('Tab1'), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - expect(find.byWidget(tabList[2]), findsOneWidget); - expect(tabController.index, 0); - expect(tabController.previousIndex, 0); - await tester.tap(find.byWidget(tabList[2])); - await tester.pumpAndSettle(); - expect(tabController.index, 2); - await tester.tap(find.byIcon(Icons.favorite)); - await tester.pumpAndSettle(); - expect(tabController.index, 1); - await tester.tap(find.text('Tab1')); - await tester.pumpAndSettle(); - expect(tabController.index, 0); - }); - - testWidgets('GFSegmentTabs with on taps center selected tab', (tester) async { - final TabController controller = - TabController(length: 12, initialIndex: 0, vsync: tester); - final List tabs = [ - const Text( - 'Tab_A', - ), - const Text( - 'Tab_B', - ), - const Text( - 'Tab_C', - ), - const Text( - 'Tab_D', - ), - const Text( - 'Tab_E', - ), - const Text( - 'Tab_F', - ), - const Text( - 'Tab_G', - ), - const Text( - 'Tab_H', - ), - const Text( - 'Tab_I', - ), - const Text( - 'Tab_J', - ), - const Text( - 'Tab_K', - ), - const Text( - 'Tab_L', - ), - ]; - - final GFSegmentTabs segmentTabs = GFSegmentTabs( - key: segmentTabsKey, - tabController: controller, - length: tabs.length, - tabs: tabs, - ); - - final TestApp app = TestApp(segmentTabs); - await tester.pumpWidget(app); - - // find segmentTabs by key - expect(find.byKey(segmentTabsKey), findsOneWidget); - // find the 'Tab_A' text in segmentTabs - expect(find.text('Tab_A'), findsOneWidget); - expect(controller, isNotNull); - expect(controller.index, 0); - expect(tester.getSize(find.byKey(segmentTabsKey)).width, equals(800.0)); - // The center of the 'Tab_F' item is to the right of the TabBar's center - expect(tester.getCenter(find.text('Tab_F')).dx, greaterThan(301.0)); - await tester.tap(find.text('Tab_F')); - await tester.pumpAndSettle(); - expect(controller.index, 5); - // The center of the 'Tab_F' item is now at the TabBar's center - expect(tester.getCenter(find.text('Tab_F')).dx, closeTo(366.0, 1.0)); - }); - - testWidgets('GFSegmentTabs can be constructed with properties', - (tester) async { - final TabController tabController = - TabController(length: 3, initialIndex: 0, vsync: tester); - - final GFSegmentTabs segmentTabs = GFSegmentTabs( - key: segmentTabsKey, - tabController: tabController, - length: tabList.length, - tabs: tabList, - tabBarColor: Colors.blueGrey, - height: 66, - width: 244, - border: Border.all(color: Colors.teal), - borderRadius: BorderRadius.circular(5), - indicator: indicator, - indicatorWeight: 5, - indicatorPadding: const EdgeInsets.all(8), - indicatorColor: GFColors.WHITE, - indicatorSize: TabBarIndicatorSize.tab, - labelPadding: const EdgeInsets.all(8), - labelColor: Colors.lightGreen, - unselectedLabelColor: Colors.black, - labelStyle: const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 16, - ), - unselectedLabelStyle: const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 12, - ), - ); - - final TestApp app = TestApp(segmentTabs); - await tester.pumpWidget(app); - - expect(app.segmentTabs.tabController, tabController); - expect(app.segmentTabs.length, tabList.length); - expect(app.segmentTabs.tabs, tabList); - expect(app.segmentTabs.tabBarColor, Colors.blueGrey); - expect(app.segmentTabs.height, 66); - expect(app.segmentTabs.width, 244); - expect(app.segmentTabs.border, Border.all(color: Colors.teal)); - expect(app.segmentTabs.borderRadius, BorderRadius.circular(5)); - expect(app.segmentTabs.indicator, indicator); - expect(app.segmentTabs.indicatorWeight, 5); - expect(app.segmentTabs.indicatorPadding, const EdgeInsets.all(8)); - expect(app.segmentTabs.indicatorColor, GFColors.WHITE); - expect(app.segmentTabs.indicatorSize, TabBarIndicatorSize.tab); - expect(app.segmentTabs.labelPadding, const EdgeInsets.all(8)); - expect(app.segmentTabs.labelColor, Colors.lightGreen); - expect(app.segmentTabs.unselectedLabelColor, Colors.black); - expect( - app.segmentTabs.labelStyle, - const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 16, - )); - expect( - app.segmentTabs.unselectedLabelStyle, - const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 12, - )); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.segmentTabs); - - final GFSegmentTabs segmentTabs; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - appBar: AppBar( - title: const Text('Segment Tabs'), - ), - body: const Text('Body'), - bottomNavigationBar: widget.segmentTabs, - ), - ); -} diff --git a/test/shimmer_test.dart b/test/shimmer_test.dart deleted file mode 100644 index ceae39c3..00000000 --- a/test/shimmer_test.dart +++ /dev/null @@ -1,111 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final childWidget = Container( - width: 111, - height: 222, - ); - const firstColor = Colors.teal; - const secondColor = Colors.tealAccent; - - const count = 5; - const duration = Duration(milliseconds: 3000); - - final gradient = LinearGradient( - begin: Alignment.bottomRight, - end: Alignment.centerLeft, - stops: const [0, 0.3, 0.6, 0.9, 1], - colors: [ - Colors.teal[100]!, - Colors.teal[200]!, - Colors.teal[300]!, - Colors.teal[400]!, - Colors.teal[500]!, - ], - ); - - testWidgets('GF Shimmer can be constructed', (tester) async { - // final childWidget = Icon(Icons.directions_bike_sharp, size: 45,); - - final GFShimmer shimmer = GFShimmer( - child: childWidget, - mainColor: firstColor, - secondaryColor: secondColor, - shimmerEffectCount: count, - duration: duration, - ); - - final TestApp app = TestApp(shimmer); - - await tester.pumpWidget(app); - await tester.pump(duration); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - }); - - testWidgets('GF Shimmer can be constructed with icon widget', (tester) async { - const GFShimmer shimmer = GFShimmer( - child: Icon( - Icons.directions_bike_sharp, - size: 45, - ), - mainColor: firstColor, - secondaryColor: secondColor, - shimmerEffectCount: count, - ); - - const TestApp app = TestApp(shimmer); - - await tester.pumpWidget(app); - - expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - }); - - test('should emit the right values for shimmerEffectCount', () async { - final GFShimmer shimmer = GFShimmer( - child: childWidget, - mainColor: firstColor, - secondaryColor: secondColor, - shimmerEffectCount: count, - ); - expect(shimmer.shimmerEffectCount, count); - }); - - test('GF Shimmer with gradient', () async { - final GFShimmer shimmer = GFShimmer( - child: childWidget, - mainColor: firstColor, - secondaryColor: secondColor, - shimmerEffectCount: count, - showGradient: true, - gradient: gradient, - ); - expect(shimmer.showGradient, isTrue); - expect(shimmer.gradient, gradient); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.shimmer); - - final GFShimmer shimmer; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.shimmer, - ], - ), - ), - ); -} diff --git a/test/social_button_test.dart b/test/social_button_test.dart deleted file mode 100644 index 7848f17e..00000000 --- a/test/social_button_test.dart +++ /dev/null @@ -1,377 +0,0 @@ -// import 'package:flutter/material.dart'; -// import 'package:flutter_test/flutter_test.dart'; -// import 'package:getwidget/getwidget.dart'; - -// void main() { -// const text = 'click me'; -// const textStyle = TextStyle(fontSize: 14, color: Colors.black); -// const size = GFSize.SMALL; -// const childWidget = Text('tap me'); - -// testWidgets('Disabled GF Button can be constructed', (tester) async { -// const buttonKey = Key('header'); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: null, -// text: text, -// size: size, -// disabledColor: Colors.teal.shade300, -// disabledElevation: 3, -// disabledTextColor: GFColors.LIGHT, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); - -// expect(app.button.text, text); -// expect(app.button.size, size); -// expect(app.button.onPressed, null); -// expect(app.button.disabledColor, Colors.teal.shade300); -// expect(app.button.disabledElevation, 3); -// expect(app.button.disabledTextColor, GFColors.LIGHT); - -// await tester.tap(find.byKey(buttonKey)); -// await tester.pump(); - -// await tester.pumpWidget(app); -// }); - -// testWidgets('GF Button can be constructed', (tester) async { -// const buttonKey = Key('header'); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: () {}, -// text: text, -// size: size, -// color: GFColors.ALT, -// textStyle: textStyle, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); - -// expect(app.button.text, text); -// expect(app.button.textStyle, textStyle); -// expect(app.button.size, size); -// expect(app.button.color, GFColors.ALT); - -// await tester.tap(find.byKey(buttonKey)); -// await tester.pump(); - -// await tester.pumpWidget(app); -// }); - -// testWidgets('GF Button can be constructed with child for custom text', -// (tester) async { -// const buttonKey = Key('header'); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: () {}, -// text: text, -// size: size, -// child: childWidget, -// color: Colors.amber, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); -// expect(app.button.child, childWidget); - -// expect(app.button.text, text); -// expect(app.button.size, size); -// expect(app.button.color, Colors.amber); - -// await tester.tap(find.byKey(buttonKey)); -// await tester.pump(); - -// await tester.pumpWidget(app); -// }); - -// testWidgets( -// 'GF Button can be constructed with standard type and shape i.e default', -// (tester) async { -// const buttonKey = Key('header'); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: () {}, -// text: text, -// size: size, -// textColor: GFColors.DARK, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); - -// expect(app.button.text, text); -// expect(app.button.textColor, GFColors.DARK); -// expect(app.button.size, size); - -// await tester.tap(find.byKey(buttonKey)); -// await tester.pump(); -// await tester.press(find.byKey(buttonKey)); -// await tester.pump(); -// await tester.longPress(find.byKey(buttonKey)); -// await tester.pump(); - -// // await expectLater(() => tester.tap(find.byKey(buttonKey)), prints('onHighlight changed')); - -// await tester.pumpWidget(app); -// }); - -// testWidgets( -// 'GF Button with icon and icon position' -// 'and with Block Button', (tester) async { -// const buttonKey = Key('header'); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: () {}, -// text: text, -// size: size, -// child: childWidget, -// icon: const Icon( -// Icons.directions_bike_sharp, -// ), -// position: GFPosition.start, -// blockButton: true, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); -// expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - -// expect(app.button.text, text); -// expect(app.button.size, size); -// expect(app.button.position, GFPosition.start); -// expect(app.button.blockButton, isTrue); -// }); - -// testWidgets( -// 'GF Button with solid type and pills shape ' -// 'and Full Width Button', (tester) async { -// const buttonKey = Key('header'); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: () {}, -// text: text, -// size: size, -// child: childWidget, -// icon: const Icon( -// Icons.directions_bike_sharp, -// ), -// position: GFPosition.start, -// type: GFButtonType.solid, -// shape: GFButtonShape.pills, -// fullWidthButton: true, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); -// expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - -// expect(app.button.text, text); -// expect(app.button.size, size); -// expect(app.button.position, GFPosition.start); -// expect(app.button.type, GFButtonType.solid); -// expect(app.button.shape, GFButtonShape.pills); -// expect(app.button.fullWidthButton, isTrue); -// }); - -// testWidgets('GF Button with type outline and square shape ', (tester) async { -// const buttonKey = Key('header'); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: () {}, -// text: text, -// size: size, -// child: childWidget, -// icon: const Icon( -// Icons.directions_bike_sharp, -// ), -// position: GFPosition.start, -// type: GFButtonType.outline, -// shape: GFButtonShape.square, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); -// expect(find.byIcon(Icons.directions_bike_sharp), findsOneWidget); - -// expect(app.button.text, text); -// expect(app.button.size, size); -// expect(app.button.position, GFPosition.start); -// expect(app.button.type, GFButtonType.outline); -// expect(app.button.shape, GFButtonShape.square); -// }); - -// testWidgets('GF Button with custom border and shape ', (tester) async { -// const buttonKey = Key('header'); - -// const border = BorderSide( -// color: Colors.tealAccent, width: 1, style: BorderStyle.solid); -// const shape = RoundedRectangleBorder( -// side: -// BorderSide(color: Colors.pink, width: 2, style: BorderStyle.solid), -// borderRadius: BorderRadius.zero); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: () {}, -// text: text, -// size: size, -// borderShape: shape, -// borderSide: border, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); - -// expect(app.button.text, text); -// expect(app.button.size, size); -// expect(app.button.borderShape, shape); -// expect(app.button.borderSide, border); -// }); - -// testWidgets('GF Button with boxshadow ', (tester) async { -// const buttonKey = Key('header'); - -// const boxshadow = BoxShadow( -// color: Colors.pink, -// blurRadius: 2, -// spreadRadius: 1, -// offset: Offset.zero, -// ); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: () {}, -// text: text, -// size: size, -// buttonBoxShadow: true, -// boxShadow: boxshadow, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); - -// expect(app.button.text, text); -// expect(app.button.size, size); -// expect(app.button.buttonBoxShadow, isTrue); -// expect(app.button.boxShadow, boxshadow); -// }); - -// testWidgets( -// 'GF Button with hover, focus, highlight and splash color. Works only in web', -// (tester) async { -// const buttonKey = Key('header'); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: () {}, -// text: text, -// size: size, -// hoverColor: Colors.tealAccent, -// focusColor: Colors.teal, -// highlightColor: Colors.amber, -// splashColor: Colors.red, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); - -// expect(app.button.text, text); -// expect(app.button.size, size); -// expect(app.button.hoverColor, Colors.tealAccent); -// expect(app.button.focusColor, Colors.teal); -// expect(app.button.highlightColor, Colors.amber); -// expect(app.button.splashColor, Colors.red); -// }); - -// testWidgets( -// 'GF Button with hover, focus, highlight and splash color. Works only in web', -// (tester) async { -// const buttonKey = Key('header'); - -// final GFSocialButton button = GFSocialButton( -// key: buttonKey, -// onPressed: () {}, -// text: text, -// size: size, -// elevation: 3, -// focusElevation: 2, -// hoverElevation: 2, -// highlightElevation: 4, -// ); - -// final TestApp app = TestApp(button); - -// await tester.pumpWidget(app); - -// expect(find.text('click me'), findsOneWidget); - -// expect(app.button.text, text); -// expect(app.button.size, size); -// expect(app.button.elevation, 3); -// expect(app.button.focusElevation, 2); -// expect(app.button.hoverElevation, 2); -// expect(app.button.highlightElevation, 4); -// }); -// } - -// class TestApp extends StatefulWidget { -// const TestApp(this.button); - -// final GFSocialButton button; - -// @override -// _TestAppState createState() => _TestAppState(); -// } - -// class _TestAppState extends State { -// @override -// Widget build(BuildContext context) => MaterialApp( -// home: Scaffold( -// body: Column( -// children: [ -// widget.button, -// ], -// ), -// ), -// ); -// } diff --git a/test/sticky_header_test.dart b/test/sticky_header_test.dart deleted file mode 100644 index 1bf36e97..00000000 --- a/test/sticky_header_test.dart +++ /dev/null @@ -1,302 +0,0 @@ -import 'dart:core'; -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - // testWidgets('GFStickyHeader can be constructed', (tester) async { - // const itemCount = 12; - // - // final stickyHeader = Directionality( - // textDirection: TextDirection.ltr, - // child: ListView.builder( - // itemCount: itemCount, - // itemBuilder: (BuildContext context, int index) => GFStickyHeader( - // stickyContent: Container( - // alignment: AlignmentDirectional.center, - // height: 50, - // color: Colors.teal.shade200, - // child: Text( - // 'Header tile $index', - // ), - // ), - // content: Container( - // color: Colors.blueGrey.shade200, - // height: 111, - // child: Text('List tile $index'))), - // ), - // ); - // - // final TestApp app = TestApp(stickyHeader); - // await tester.pumpWidget(app); - // - // // displays first 3 index - // - // // expect(find.text('Header tile 1'), findsOneWidget); - // // expect(find.text('List tile 1'), findsOneWidget); - // // - // // expect(find.text('Header tile 2'), findsOneWidget); - // // expect(find.text('List tile 2'), findsOneWidget); - // // - // // expect(find.text('Header tile 3'), findsOneWidget); - // // expect(find.text('List tile 3'), findsOneWidget); - // // - // // expect(find.text('Header tile 4'), findsNothing); - // // expect(find.text('List tile 4'), findsNothing); - // - // // scroll ups first index and display index 4 - // - // TestGesture gesture = - // await tester.startGesture(tester.getCenter(find.text('List tile 1'))); - // await gesture.moveBy(const Offset(600, -330)); - // await tester.pump(); - // - // // expect(find.text('Header tile 1'), findsNothing); - // // expect(find.text('List tile 1'), findsNothing); - // // - // // expect(find.text('Header tile 4'), findsOneWidget); - // // expect(find.text('List tile 4'), findsOneWidget); - // // - // // await gesture.up(); - // // await tester.pump(); - // // await tester.pump(const Duration(seconds: 1)); - // // - // // await tester.pumpWidget(app); - // // - // // expect(find.text('Header tile 5'), findsOneWidget); - // // expect(find.text('List tile 5'), findsOneWidget); - // - // // scroll ups third index and display index 6 - // - // gesture = - // await tester.startGesture(tester.getCenter(find.text('List tile 5'))); - // await gesture.moveBy(const Offset(600, -330)); - // await tester.pump(); - // - // // expect(find.text('Header tile 3'), findsNothing); - // // expect(find.text('List tile 3'), findsNothing); - // // - // // expect(find.text('Header tile 6'), findsOneWidget); - // // expect(find.text('List tile 6'), findsOneWidget); - // // - // // await gesture.up(); - // // await tester.pump(); - // // await tester.pump(const Duration(seconds: 1)); - // // - // // await tester.pumpWidget(app); - // // - // // expect(find.text('Header tile 7'), findsOneWidget); - // // expect(find.text('List tile 7'), findsOneWidget); - // // - // // expect(find.text('Header tile 8'), findsNothing); - // // expect(find.text('List tile 8'), findsNothing); - // }); - // - // testWidgets('GFStickyHeader horizontal can be constructed', (tester) async { - // const itemCount = 12; - // - // final stickyHeader = Directionality( - // textDirection: TextDirection.ltr, - // child: ListView.builder( - // itemCount: itemCount, - // itemBuilder: (BuildContext context, int index) => GFStickyHeader( - // enableHeaderOverlap: true, - // direction: Axis.horizontal, - // // stickyContentPosition: GFPosition.end, - // stickyContent: Container( - // alignment: AlignmentDirectional.center, - // height: 50, - // color: Colors.teal.shade200, - // child: Text( - // 'Header tile $index', - // ), - // ), - // content: Container( - // alignment: AlignmentDirectional.center, - // height: 111, - // color: Colors.blueGrey.shade200, - // child: Text('List tile $index'))), - // ), - // ); - // - // final TestApp app = TestApp(stickyHeader); - // await tester.pumpWidget(app); - // - // // displays first 6 index - // - // // expect(find.text('Header tile 1'), findsOneWidget); - // // expect(find.text('List tile 1'), findsOneWidget); - // // - // // expect(find.text('Header tile 2'), findsOneWidget); - // // expect(find.text('List tile 2'), findsOneWidget); - // // - // // expect(find.text('Header tile 3'), findsOneWidget); - // // expect(find.text('List tile 3'), findsOneWidget); - // // - // // expect(find.text('Header tile 6'), findsNothing); - // // expect(find.text('List tile 6'), findsNothing); - // - // // scroll ups first index and display index 4 - // - // TestGesture gesture = - // await tester.startGesture(tester.getCenter(find.text('List tile 3'))); - // await gesture.moveBy(const Offset(600, -330)); - // await tester.pump(); - // - // // expect(find.text('Header tile 1'), findsNothing); - // // expect(find.text('List tile 1'), findsNothing); - // // - // // expect(find.text('Header tile 6'), findsOneWidget); - // // expect(find.text('List tile 6'), findsOneWidget); - // - // await gesture.up(); - // await tester.pump(); - // await tester.pump(const Duration(seconds: 1)); - // - // await tester.pumpWidget(app); - // - // // scroll ups seventh index and display index 11 - // - // gesture = - // await tester.startGesture(tester.getCenter(find.text('List tile 7'))); - // await gesture.moveBy(const Offset(600, -330)); - // await tester.pump(); - // - // // expect(find.text('Header tile 3'), findsNothing); - // // expect(find.text('List tile 3'), findsNothing); - // // - // // expect(find.text('Header tile 10'), findsOneWidget); - // // expect(find.text('List tile 10'), findsOneWidget); - // // - // // await gesture.up(); - // // await tester.pump(); - // // await tester.pump(const Duration(seconds: 1)); - // // - // // await tester.pumpWidget(app); - // // - // // expect(find.text('Header tile 11'), findsOneWidget); - // // expect(find.text('List tile 11'), findsOneWidget); - // }); - - // testWidgets('GFStickyHeader can be constructed with properties', - // (tester) async { - // final GFStickyHeader stickyHeader = GFStickyHeader( - // enableHeaderOverlap: true, - // direction: Axis.horizontal, - // stickyContentPosition: GFPosition.end, - // stickyContent: Container( - // alignment: AlignmentDirectional.center, - // height: 50, - // color: Colors.teal.shade200, - // child: const Text( - // 'Header tile', - // ), - // ), - // content: Container( - // alignment: AlignmentDirectional.center, - // height: 111, - // color: Colors.blueGrey.shade200, - // child: const Text('List tile'))); - // - // final Tester app = Tester(stickyHeader); - // await tester.pumpWidget(app); - // - // expect(find.text('Header tile'), findsOneWidget); - // expect(find.text('List tile'), findsOneWidget); - // - // expect(stickyHeader.enableHeaderOverlap, isTrue); - // expect(stickyHeader.direction, Axis.horizontal); - // expect(stickyHeader.stickyContentPosition, GFPosition.end); - // }); - - testWidgets('GFStickyHeaderBuilder can be constructed with properties', - (tester) async { - final stickyHeader = Directionality( - textDirection: TextDirection.ltr, - child: ListView.builder( - shrinkWrap: true, - physics: const ScrollPhysics(), - itemCount: 12, - itemBuilder: (context, index) => GFStickyHeaderBuilder( - // direction: Axis.horizontal, - // enableHeaderOverlap: true, - // stickyContentPosition: GFPosition.end, - stickyContentBuilder: (BuildContext context, double stuckValue) { - stuckValue = 1.0 - stuckValue.clamp(0.0, 1.0); - return Container( - height: 50, - width: MediaQuery.of(context).size.width * 0.5, - color: Color.lerp(Colors.teal[100], Colors.teal[600], stuckValue), - padding: const EdgeInsets.symmetric(horizontal: 16), - alignment: Alignment.centerLeft, - child: Row( - children: [ - Expanded( - child: Text( - 'Image #$index', - style: const TextStyle(color: Colors.white), - ), - ), - Offstage( - offstage: stuckValue <= 0.0, - child: Opacity( - opacity: stuckValue, - child: IconButton( - icon: const Icon(Icons.image, color: Colors.white), - // ignore: deprecated_member_use - onPressed: () => ScaffoldMessenger.of(context) - .showSnackBar( - SnackBar(content: Text('Favorite #$index'))), - ), - ), - ), - ], - ), - ); - }, - content: Container( - height: 200, - width: MediaQuery.of(context).size.width * 0.5, - color: Colors.teal, - child: const Text('Content tile'), - ), - ), - ), - ); - - final TestApp app = TestApp(stickyHeader); - await tester.pumpWidget(app); - }); -} - -class Tester extends StatefulWidget { - const Tester(this.stickyHeader); - - final Widget stickyHeader; - - @override - _TesterState createState() => _TesterState(); -} - -class _TesterState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold(body: SingleChildScrollView(child: widget.stickyHeader)), - ); -} - -class TestApp extends StatefulWidget { - const TestApp(this.stickyHeader); - - final Widget stickyHeader; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold(body: widget.stickyHeader), - ); -} diff --git a/test/tabbar_test.dart b/test/tabbar_test.dart deleted file mode 100644 index 9595f775..00000000 --- a/test/tabbar_test.dart +++ /dev/null @@ -1,333 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final Key tabBarKey = UniqueKey(); - - final List tabList = [ - const Text( - 'Tab1', - ), - const Tab( - icon: Icon(Icons.favorite), - ), - const Tab( - icon: Icon(Icons.directions_railway), - child: Text( - 'Tab3', - ), - ), - ]; - - final indicator = BoxDecoration( - color: Colors.teal, - border: Border.all(color: Colors.tealAccent, width: 2)); - const tabBarShape = RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(24), topRight: Radius.circular(24))); - - testWidgets('GFTabBar can be constructed', (tester) async { - final TabController tabController = - TabController(length: 3, initialIndex: 0, vsync: tester); - - final GFTabBar tabBar = GFTabBar( - key: tabBarKey, - controller: tabController, - length: tabList.length, - tabs: tabList, - ); - - final TestApp app = TestApp(tabBar); - await tester.pumpWidget(app); - - // find tabBar by key - expect(find.byKey(tabBarKey), findsOneWidget); - // find the 'Tab1' text in tabBar - expect(find.text('Tab1'), findsOneWidget); - - expect(tabController, isNotNull); - expect(tabController.index, 0); - expect(tabController.previousIndex, 0); - await tester.tap(find.byIcon(Icons.favorite)); - await tester.pump(); - expect(tabController.indexIsChanging, true); - await tester.pump(const Duration(seconds: 1)); - expect(tabController.index, 1); - expect(tabController.previousIndex, 0); - expect(tabController.indexIsChanging, false); - await tester.tap(find.byWidget(tabList[2])); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(tabController.index, 2); - expect(tabController.previousIndex, 1); - await tester.tap(find.text('Tab1')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(tabController.index, 0); - expect(tabController.previousIndex, 2); - }); - - testWidgets('GFTabBar with scrollable taps selected tab', (tester) async { - final TabController tabController = - TabController(length: 3, initialIndex: 0, vsync: tester); - - final GFTabBar tabBar = GFTabBar( - key: tabBarKey, - controller: tabController, - length: tabList.length, - tabs: tabList, - isScrollable: true, - ); - - final TestApp app = TestApp(tabBar); - await tester.pumpWidget(app); - - // find tabBar by key - expect(find.byKey(tabBarKey), findsOneWidget); - // find the 'Tab1' text in tabBar - expect(app.tabBar.isScrollable, isTrue); - expect(find.text('Tab1'), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - expect(find.byWidget(tabList[2]), findsOneWidget); - expect(tabController.index, 0); - expect(tabController.previousIndex, 0); - await tester.tap(find.byWidget(tabList[2])); - await tester.pumpAndSettle(); - expect(tabController.index, 2); - await tester.tap(find.byIcon(Icons.favorite)); - await tester.pumpAndSettle(); - expect(tabController.index, 1); - await tester.tap(find.text('Tab1')); - await tester.pumpAndSettle(); - expect(tabController.index, 0); - }); - - testWidgets('GFTabBar with scrollable taps center selected tab', - (tester) async { - final TabController controller = - TabController(length: 12, initialIndex: 0, vsync: tester); - final List tabs = [ - const Text( - 'Tab_A', - ), - const Text( - 'Tab_B', - ), - const Text( - 'Tab_C', - ), - const Text( - 'Tab_D', - ), - const Text( - 'Tab_E', - ), - const Text( - 'Tab_F', - ), - const Text( - 'Tab_G', - ), - const Text( - 'Tab_H', - ), - const Text( - 'Tab_I', - ), - const Text( - 'Tab_J', - ), - const Text( - 'Tab_K', - ), - const Text( - 'Tab_L', - ), - ]; - - final GFTabBar tabBar = GFTabBar( - key: tabBarKey, - controller: controller, - length: tabs.length, - tabs: tabs, - isScrollable: true, - ); - - final TestApp app = TestApp(tabBar); - await tester.pumpWidget(app); - - // find tabBar by key - expect(find.byKey(tabBarKey), findsOneWidget); - // find the 'Tab_A' text in tabBar - expect(app.tabBar.isScrollable, isTrue); - expect(find.text('Tab_A'), findsOneWidget); - expect(controller, isNotNull); - expect(controller.index, 0); - expect(tester.getSize(find.byKey(tabBarKey)).width, equals(800.0)); - // The center of the 'Tab_F' item is to the right of the TabBar's center - expect(tester.getCenter(find.text('Tab_F')).dx, greaterThan(401.0)); - await tester.tap(find.text('Tab_F')); - await tester.pumpAndSettle(); - expect(controller.index, 5); - // The center of the 'Tab_F' item is now at the TabBar's center - expect(tester.getCenter(find.text('Tab_F')).dx, closeTo(400.0, 1.0)); - }); - - testWidgets('GFTabBar can be scrolled independent of the selection', - (tester) async { - final TabController controller = - TabController(length: 12, initialIndex: 0, vsync: tester); - final List tabs = [ - const Text( - 'TabA', - ), - const Text( - 'TabB', - ), - const Text( - 'TabC', - ), - const Text( - 'TabD', - ), - const Text( - 'TabE', - ), - const Text( - 'TabF', - ), - const Text( - 'TabG', - ), - const Text( - 'TabH', - ), - const Text( - 'TabI', - ), - const Text( - 'TabJ', - ), - const Text( - 'TabK', - ), - const Text( - 'TabL', - ), - ]; - - final GFTabBar tabBar = GFTabBar( - key: tabBarKey, - controller: controller, - length: tabs.length, - tabs: tabs, - isScrollable: true, - ); - - final TestApp app = TestApp(tabBar); - await tester.pumpWidget(app); - - // find tabBar by key - expect(find.byKey(tabBarKey), findsOneWidget); - // find the 'Tab_A' text in tabBar - expect(app.tabBar.isScrollable, isTrue); - expect(find.text('TabA'), findsOneWidget); - expect(controller, isNotNull); - expect(controller.index, 0); - // Fling-scroll the TabBar to the left - expect(tester.getCenter(find.text('TabH')).dx, lessThan(700.0)); - await tester.fling(find.byKey(tabBarKey), const Offset(-200, 0), 10000); - await tester.pump(); - await tester - .pump(const Duration(seconds: 1)); // finish the scroll animation - expect(tester.getCenter(find.text('TabH')).dx, lessThan(500.0)); - // Scrolling the TabBar doesn't change the selection - expect(controller.index, 0); - }); - - testWidgets('GFTabBar can be constructed with properties', (tester) async { - final TabController tabController = - TabController(length: 3, initialIndex: 0, vsync: tester); - - final GFTabBar tabBar = GFTabBar( - key: tabBarKey, - controller: tabController, - length: tabList.length, - tabs: tabList, - tabBarColor: Colors.blueGrey, - tabBarHeight: 66, - isScrollable: false, - shape: tabBarShape, - indicator: indicator, - indicatorWeight: 5, - indicatorPadding: const EdgeInsets.all(8), - indicatorColor: GFColors.WHITE, - indicatorSize: TabBarIndicatorSize.tab, - labelPadding: const EdgeInsets.all(8), - labelColor: Colors.lightGreen, - unselectedLabelColor: Colors.black, - labelStyle: const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 16, - ), - unselectedLabelStyle: const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 12, - ), - ); - - final TestApp app = TestApp(tabBar); - await tester.pumpWidget(app); - - expect(app.tabBar.controller, tabController); - expect(app.tabBar.length, tabList.length); - expect(app.tabBar.tabs, tabList); - expect(app.tabBar.tabBarColor, Colors.blueGrey); - expect(app.tabBar.tabBarHeight, 66); - expect(app.tabBar.isScrollable, isFalse); - expect(app.tabBar.shape, tabBarShape); - expect(app.tabBar.indicator, indicator); - expect(app.tabBar.indicatorWeight, 5); - expect(app.tabBar.indicatorPadding, const EdgeInsets.all(8)); - expect(app.tabBar.indicatorColor, GFColors.WHITE); - expect(app.tabBar.indicatorSize, TabBarIndicatorSize.tab); - expect(app.tabBar.labelPadding, const EdgeInsets.all(8)); - expect(app.tabBar.labelColor, Colors.lightGreen); - expect(app.tabBar.unselectedLabelColor, Colors.black); - expect( - app.tabBar.labelStyle, - const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 16, - )); - expect( - app.tabBar.unselectedLabelStyle, - const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 12, - )); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.tabBar); - - final GFTabBar tabBar; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - appBar: AppBar( - title: const Text('TabBar'), - ), - body: const Text('Body'), - bottomNavigationBar: widget.tabBar, - ), - ); -} diff --git a/test/tabbarview_test.dart b/test/tabbarview_test.dart deleted file mode 100644 index cbfeb5a9..00000000 --- a/test/tabbarview_test.dart +++ /dev/null @@ -1,101 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final Key tabBarViewKey = UniqueKey(); - final List tabs = [ - 'AAAAAA', - 'BBBBBB', - 'CCCCCC', - 'DDDDDD', - 'EEEEEE' - ]; - final List tabList = [ - Text(tabs[0]), - Text(tabs[1]), - Text(tabs[2]), - Text(tabs[3]), - Text(tabs[4]) - ]; - - testWidgets('GFTabBarView can be constructed', (tester) async { - final TabController tabController = - TabController(length: 3, initialIndex: 0, vsync: tester); - - final GFTabBarView tabBarView = - GFTabBarView(controller: tabController, children: [ - Container( - child: const Text('aaa'), - ), - Container( - child: const Text('bbb'), - ), - Container( - child: const Text('ccc'), - ), - ]); - - final TestApp app = TestApp(tabBarView); - await tester.pumpWidget(app); - - expect(find.text('aaa'), findsOneWidget); - expect(find.text('bbb'), findsNothing); - - Offset point = tester.getCenter(find.text('aaa')); - await tester.dragFrom(point, const Offset(-600, 0)); - await tester.pump(); - expect(find.text('bbb'), findsOneWidget); - - point = tester.getCenter(find.text('bbb')); - await tester.dragFrom(point, const Offset(-600, 0)); - await tester.pump(); - expect(find.text('ccc'), findsOneWidget); - - point = tester.getCenter(find.text('ccc')); - await tester.dragFrom(point, const Offset(600, 0)); - await tester.pump(); - expect(find.text('bbb'), findsOneWidget); - }); - - testWidgets('GFTabBarView can be constructed with properties', - (tester) async { - final TabController tabController = - TabController(length: tabList.length, initialIndex: 0, vsync: tester); - - final GFTabBarView tabBarView = GFTabBarView( - key: tabBarViewKey, - controller: tabController, - children: tabList, - height: 345, - ); - - final TestApp app = TestApp(tabBarView); - await tester.pumpWidget(app); - - expect(app.tabBarView.controller, tabController); - expect(app.tabBarView.children, tabList); - expect(app.tabBarView.height, 345); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.tabBarView); - - final GFTabBarView tabBarView; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - appBar: AppBar( - title: const Text('TabBarView'), - ), - body: widget.tabBarView, - ), - ); -} diff --git a/test/tabs_test.dart b/test/tabs_test.dart deleted file mode 100644 index 0daa0f1c..00000000 --- a/test/tabs_test.dart +++ /dev/null @@ -1,560 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -class StateMarker extends StatefulWidget { - const StateMarker({Key? key, this.child}) : super(key: key); - final Widget? child; - @override - StateMarkerState createState() => StateMarkerState(); -} - -class StateMarkerState extends State { - String? marker; - @override - Widget build(BuildContext context) { - if (widget.child != null) { - return widget.child!; - } - return Container(); - } -} - -void main() { - final Key tabsKey = UniqueKey(); - final Key tabBarViewKey = UniqueKey(); - - final indicator = BoxDecoration( - color: Colors.teal, - border: Border.all(color: Colors.tealAccent, width: 2)); - const tabsShape = RoundedRectangleBorder( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(24), topRight: Radius.circular(24))); - - testWidgets('GFTabs can be constructed', (tester) async { - final List tabList = [ - const Text( - 'Tab1', - ), - const Tab( - icon: Icon(Icons.favorite), - ), - const Tab( - icon: Icon(Icons.directions_railway), - child: Text( - 'Tab3', - ), - ), - ]; - final List bodyText = ['AAAAAA', 'BBBBBB', 'CCCCCC']; - final List tabViewList = [ - Text(bodyText[0]), - Text(bodyText[1]), - Text(bodyText[2]) - ]; - final TabController tabController = - TabController(length: tabList.length, vsync: tester); - - final GFTabs tabs = GFTabs( - key: tabsKey, - initialIndex: 0, - controller: tabController, - length: tabList.length, - tabs: tabList, - tabBarView: GFTabBarView( - controller: tabController, - children: - tabViewList.map((text) => StateMarker(child: text)).toList()), - ); - - final TestApp app = TestApp(tabs); - await tester.pumpWidget(app); - - // find tabs by key - expect(find.byKey(tabsKey), findsOneWidget); - // find the 'Tab1' text in tabs - expect(find.text('Tab1'), findsOneWidget); - - expect(tabController, isNotNull); - expect(tabController.index, 0); - expect(tabController.previousIndex, 0); - expect(bodyText[tabController.index], 'AAAAAA'); - await tester.tap(find.byIcon(Icons.favorite)); - await tester.pump(); - expect(tabController.indexIsChanging, true); - await tester.pump(const Duration(seconds: 1)); - expect(tabController.index, 1); - expect(bodyText[tabController.index], 'BBBBBB'); - expect(tabController.previousIndex, 0); - expect(tabController.indexIsChanging, false); - await tester.tap(find.byWidget(tabList[2])); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(tabController.index, 2); - expect(bodyText[tabController.index], 'CCCCCC'); - expect(tabController.previousIndex, 1); - await tester.tap(find.text('Tab1')); - await tester.pump(); - await tester.pump(const Duration(seconds: 1)); - expect(tabController.index, 0); - expect(tabController.previousIndex, 2); - }); - - testWidgets('GFTabs with scrollable taps selected tab', (tester) async { - final List tabList = [ - const Text( - 'Tab1', - ), - const Tab( - icon: Icon(Icons.favorite), - ), - const Tab( - icon: Icon(Icons.directions_railway), - child: Text( - 'Tab3', - ), - ), - ]; - final List bodyText = ['AAAAAA', 'BBBBBB', 'CCCCCC']; - final List tabViewList = [ - Text(bodyText[0]), - Text(bodyText[1]), - Text(bodyText[2]) - ]; - final TabController tabController = - TabController(length: tabList.length, initialIndex: 0, vsync: tester); - - final GFTabs tabs = GFTabs( - key: tabsKey, - controller: tabController, - length: tabList.length, - tabs: tabList, - isScrollable: true, - tabBarView: GFTabBarView( - controller: tabController, - children: - tabViewList.map((text) => StateMarker(child: text)).toList()), - ); - - final TestApp app = TestApp(tabs); - await tester.pumpWidget(app); - - // find tabs by key - expect(find.byKey(tabsKey), findsOneWidget); - // find the 'Tab1' text in tabs - expect(app.tabs.isScrollable, isTrue); - expect(find.text('Tab1'), findsOneWidget); - expect(find.byIcon(Icons.favorite), findsOneWidget); - expect(find.byWidget(tabList[2]), findsOneWidget); - expect(tabController.index, 0); - expect(bodyText[tabController.index], 'AAAAAA'); - expect(tabController.previousIndex, 0); - await tester.tap(find.byWidget(tabList[2])); - await tester.pumpAndSettle(); - expect(tabController.index, 2); - expect(bodyText[tabController.index], 'CCCCCC'); - await tester.tap(find.byIcon(Icons.favorite)); - await tester.pumpAndSettle(); - expect(tabController.index, 1); - expect(bodyText[tabController.index], 'BBBBBB'); - await tester.tap(find.text('Tab1')); - await tester.pumpAndSettle(); - expect(tabController.index, 0); - }); - - testWidgets('GFTabs with scrollable taps center selected tab', - (tester) async { - final List tabList = [ - const Text( - 'Tab_A', - ), - const Text( - 'Tab_B', - ), - const Text( - 'Tab_C', - ), - const Text( - 'Tab_D', - ), - const Text( - 'Tab_E', - ), - const Text( - 'Tab_F', - ), - const Text( - 'Tab_G', - ), - const Text( - 'Tab_H', - ), - const Text( - 'Tab_I', - ), - const Text( - 'Tab_J', - ), - const Text( - 'Tab_K', - ), - const Text( - 'Tab_L', - ), - ]; - final List bodyText = [ - 'AAAAAA', - 'BBBBBB', - 'CCCCCC', - 'DDDDDD', - 'EEEEEE', - 'FFFFFF', - 'GGGGGG', - 'HHHHHH', - 'IIIIII', - 'JJJJJJ', - 'KKKKKK', - 'LLLLLL' - ]; - final List tabViewList = [ - Text(bodyText[0]), - Text(bodyText[1]), - Text(bodyText[2]), - Text(bodyText[3]), - Text(bodyText[4]), - Text(bodyText[5]), - Text(bodyText[6]), - Text(bodyText[7]), - Text(bodyText[8]), - Text(bodyText[9]), - Text(bodyText[10]), - Text(bodyText[11]) - ]; - final TabController tabController = - TabController(length: tabList.length, initialIndex: 0, vsync: tester); - - final GFTabs tabs = GFTabs( - key: tabsKey, - controller: tabController, - length: tabList.length, - tabs: tabList, - isScrollable: true, - tabBarView: GFTabBarView( - controller: tabController, - children: - tabViewList.map((text) => StateMarker(child: text)).toList()), - ); - - final TestApp app = TestApp(tabs); - await tester.pumpWidget(app); - - // find tabs by key - expect(find.byKey(tabsKey), findsOneWidget); - // find the 'Tab_A' text in tabs - expect(app.tabs.isScrollable, isTrue); - expect(find.text('Tab_A'), findsOneWidget); - expect(tabController, isNotNull); - expect(tabController.index, 0); - expect(bodyText[tabController.index], 'AAAAAA'); - expect(tester.getSize(find.byKey(tabsKey)).width, equals(800.0)); - // The center of the 'Tab_F' item is to the right of the TabBar's center - expect(tester.getCenter(find.text('Tab_F')).dx, greaterThan(401.0)); - await tester.tap(find.text('Tab_F')); - await tester.pumpAndSettle(); - expect(tabController.index, 5); - expect(bodyText[tabController.index], 'FFFFFF'); - // The center of the 'Tab_F' item is now at the TabBar's center - expect(tester.getCenter(find.text('Tab_F')).dx, closeTo(400.0, 1.0)); - }); - - testWidgets('GFTabs can be scrolled independent of the selection', - (tester) async { - final List tabList = [ - const Text( - 'TabA', - ), - const Text( - 'TabB', - ), - const Text( - 'TabC', - ), - const Text( - 'TabD', - ), - const Text( - 'TabE', - ), - const Text( - 'TabF', - ), - const Text( - 'TabG', - ), - const Text( - 'TabH', - ), - const Text( - 'TabI', - ), - const Text( - 'TabJ', - ), - const Text( - 'TabK', - ), - const Text( - 'TabL', - ), - ]; - final List bodyText = [ - 'AAAAAA', - 'BBBBBB', - 'CCCCCC', - 'DDDDDD', - 'EEEEEE', - 'FFFFFF', - 'GGGGGG', - 'HHHHHH', - 'IIIIII', - 'JJJJJJ', - 'KKKKKK', - 'LLLLLL' - ]; - final List tabViewList = [ - Text(bodyText[0]), - Text(bodyText[1]), - Text(bodyText[2]), - Text(bodyText[3]), - Text(bodyText[4]), - Text(bodyText[5]), - Text(bodyText[6]), - Text(bodyText[7]), - Text(bodyText[8]), - Text(bodyText[9]), - Text(bodyText[10]), - Text(bodyText[11]) - ]; - final TabController tabController = - TabController(length: tabList.length, initialIndex: 0, vsync: tester); - - final GFTabs tabs = GFTabs( - key: tabsKey, - isScrollable: true, - controller: tabController, - length: tabList.length, - tabs: tabList, - tabBarView: GFTabBarView( - controller: tabController, - children: - tabViewList.map((text) => StateMarker(child: text)).toList()), - ); - - final TestApp app = TestApp(tabs); - await tester.pumpWidget(app); - - // find tabs by key - expect(find.byKey(tabsKey), findsOneWidget); - // find the 'Tab_A' text in tabs - expect(app.tabs.isScrollable, isTrue); - expect(find.text('TabA'), findsOneWidget); - expect(tabController, isNotNull); - expect(tabController.index, 0); - expect(bodyText[tabController.index], 'AAAAAA'); - // Fling-scroll the TabBar to the left - expect(tester.getCenter(find.text('TabH')).dx, lessThan(700.0)); - await tester.fling(find.byType(TabBar), const Offset(-200, 0), 10000); - await tester.pump(); - await tester - .pump(const Duration(seconds: 1)); // finish the scroll animation - expect(tester.getCenter(find.text('TabH')).dx, lessThan(500.0)); - // Scrolling the TabBar doesn't change the selection - expect(tabController.index, 0); - expect(bodyText[tabController.index], 'AAAAAA'); - }); - - testWidgets('GFTabs can be constructed', (tester) async { - final List tabBarList = [ - const Text('TabA'), - const Text('TabB'), - const Text('TabC'), - const Text('TabD'), - const Text('TabE') - ]; - final List tabs = [ - 'AAAAAA', - 'BBBBBB', - 'CCCCCC', - 'DDDDDD', - 'EEEEEE' - ]; - final List tabList = [ - Text(tabs[0]), - Text(tabs[1]), - Text(tabs[2]), - Text(tabs[3]), - Text(tabs[4]) - ]; - final TabController tabController = - TabController(length: tabList.length, initialIndex: 0, vsync: tester); - - final GFTabs tab = GFTabs( - key: tabsKey, - height: 960, - controller: tabController, - length: tabs.length, - tabs: tabBarList, - tabBarView: GFTabBarView( - controller: tabController, - key: tabBarViewKey, - children: tabList.map((text) => Container(child: text)).toList()), - ); - - final TestApp app = TestApp(tab); - await tester.pumpWidget(app); - - expect(find.text('AAAAAA'), findsOneWidget); - expect(find.text('BBBBBB'), findsNothing); - - Offset point = tester.getCenter(find.text('AAAAAA')); - await tester.dragFrom(point, const Offset(-600, 0)); - await tester.pump(); - expect(find.text('BBBBBB'), findsOneWidget); - - point = tester.getCenter(find.text('BBBBBB')); - await tester.dragFrom(point, const Offset(-600, 0)); - await tester.pump(); - expect(find.text('CCCCCC'), findsOneWidget); - - point = tester.getCenter(find.text('CCCCCC')); - await tester.dragFrom(point, const Offset(600, 0)); - await tester.pump(); - expect(find.text('BBBBBB'), findsOneWidget); - }); - - testWidgets('GFTabs can be constructed with properties', (tester) async { - final List tabList = [ - const Text( - 'TabA', - ), - const Text( - 'TabB', - ), - const Text( - 'TabC', - ), - const Text( - 'TabD', - ), - const Text( - 'TabE', - ), - ]; - final List tabText = [ - 'AAAAAA', - 'BBBBBB', - 'CCCCCC', - 'DDDDDD', - 'EEEEEE' - ]; - final List tabViewList = [ - Text(tabText[0]), - Text(tabText[1]), - Text(tabText[2]), - Text(tabText[3]), - Text(tabText[4]) - ]; - final TabController tabController = - TabController(length: tabList.length, initialIndex: 0, vsync: tester); - - final GFTabs tabs = GFTabs( - key: tabsKey, - controller: tabController, - length: tabList.length, - tabs: tabList, - tabBarView: GFTabBarView( - controller: tabController, - children: - tabViewList.map((text) => StateMarker(child: text)).toList()), - tabBarColor: Colors.blueGrey, - tabBarHeight: 66, - height: 345, - isScrollable: false, - shape: tabsShape, - indicator: indicator, - indicatorWeight: 5, - indicatorPadding: const EdgeInsets.all(8), - indicatorColor: GFColors.WHITE, - indicatorSize: TabBarIndicatorSize.tab, - labelPadding: const EdgeInsets.all(8), - labelColor: Colors.lightGreen, - unselectedLabelColor: Colors.black, - labelStyle: const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 16, - ), - unselectedLabelStyle: const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 12, - ), - ); - - final TestApp app = TestApp(tabs); - await tester.pumpWidget(app); - - expect(app.tabs.controller, tabController); - expect(app.tabs.length, tabList.length); - expect(app.tabs.tabs, tabList); - expect(app.tabs.controller, tabController); - // expect(app.tabs.tabBarView, GFTabBarView( - // children: tabViewList.map((text) => StateMarker( - // child: text - // )).toList() - // ),); - expect(app.tabs.height, 345); - expect(app.tabs.tabBarColor, Colors.blueGrey); - expect(app.tabs.tabBarHeight, 66); - expect(app.tabs.isScrollable, isFalse); - expect(app.tabs.shape, tabsShape); - expect(app.tabs.indicator, indicator); - expect(app.tabs.indicatorWeight, 5); - expect(app.tabs.indicatorPadding, const EdgeInsets.all(8)); - expect(app.tabs.indicatorColor, GFColors.WHITE); - expect(app.tabs.indicatorSize, TabBarIndicatorSize.tab); - expect(app.tabs.labelPadding, const EdgeInsets.all(8)); - expect(app.tabs.labelColor, Colors.lightGreen); - expect(app.tabs.unselectedLabelColor, Colors.black); - expect( - app.tabs.labelStyle, - const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 16, - )); - expect( - app.tabs.unselectedLabelStyle, - const TextStyle( - fontWeight: FontWeight.w500, - fontSize: 12, - )); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.tabs); - - final GFTabs tabs; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - appBar: AppBar( - title: const Text('TabBar'), - ), - body: widget.tabs), - ); -} diff --git a/test/toggle_test.dart b/test/toggle_test.dart deleted file mode 100644 index 0aa2dbc4..00000000 --- a/test/toggle_test.dart +++ /dev/null @@ -1,518 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final Key toggleKey = UniqueKey(); - - const enabledTextStyle = TextStyle(color: Colors.green); - const disabledTextStyle = TextStyle(color: Colors.red); - - testWidgets('GFToggle can be constructed', (WidgetTester tester) async { - bool isSelected = false; - - final toggle = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: Center( - child: GFToggle( - key: toggleKey, - value: isSelected, - onChanged: (value) { - setState(() { - isSelected = value!; - }); - }, - ), - ), - ), - ), - ); - - await tester.pumpWidget(toggle); - - expect(isSelected, isFalse); - await tester.tap(find.byKey(toggleKey)); - await tester.pump(); - expect(isSelected, isTrue); - }); - - testWidgets('GFToggle can be constructed with enabled and disabled Text', - (tester) async { - bool isOn = false; - - final toggle = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFToggle( - key: toggleKey, - value: isOn, - enabledText: 'ON', - disabledText: 'OFF', - onChanged: (value) { - setState(() { - isOn = value!; - }); - }, - ), - )), - ); - - // final TestApp app = TestApp(toggle); - await tester.pumpWidget(toggle); - - // find toggle by key - expect(find.byKey(toggleKey), findsOneWidget); - - // find text 'OFF' - expect(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.data!.contains('OFF'); - } - return toggleWidget.textSpan!.toPlainText().contains('OFF'); - } - return false; - }), findsOneWidget); - - // tap on text 'OFF; - await tester.tap(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.data!.contains('OFF'); - } - return toggleWidget.textSpan!.toPlainText().contains('OFF'); - } - return false; - })); - - // Rebuild the widget after the state has changed. - await tester.pump(); - - // find text 'ON' - expect(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.data!.contains('ON'); - } - return toggleWidget.textSpan!.toPlainText().contains('ON'); - } - return false; - }), findsOneWidget); - - // tap on text 'ON' - await tester.tap(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.data!.contains('ON'); - } - return toggleWidget.textSpan!.toPlainText().contains('ON'); - } - return false; - })); - - // Rebuild the widget after the state has changed. - await tester.pump(const Duration(milliseconds: 500)); - - // find text 'OFF' - expect(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.data!.contains('OFF'); - } - return toggleWidget.textSpan!.toPlainText().contains('OFF'); - } - return false; - }), findsOneWidget); - }); - - testWidgets('GFToggle with enabled and disabled color', - (WidgetTester tester) async { - bool isOn = false; - - final toggle = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFToggle( - key: toggleKey, - value: isOn, - enabledText: 'ON', - disabledText: 'OFF', - disabledThumbColor: Colors.amber, - disabledTrackColor: Colors.amberAccent, - enabledThumbColor: Colors.teal, - enabledTrackColor: Colors.tealAccent, - boxShape: BoxShape.rectangle, - borderRadius: const BorderRadius.all(Radius.circular(4)), - onChanged: (value) { - setState(() { - isOn = value!; - }); - }, - ), - )), - ); - - // find toggle key - await tester.pumpWidget(toggle); - - // finds value false - expect(isOn, isFalse); - - // find disabled color, finds one widget - expect(find.byWidgetPredicate((widget) { - if (widget is DecoratedBox) { - final DecoratedBox toggleWidget = widget; - // ignore: avoid_as - final BoxDecoration toggle = toggleWidget.decoration as BoxDecoration; - return toggle.color == Colors.amber; - } - return false; - }), findsOneWidget); - - // finds enabled color, finds nothing - expect(find.byWidgetPredicate((widget) { - if (widget is DecoratedBox) { - final DecoratedBox toggleWidget = widget; - // ignore: avoid_as - final BoxDecoration toggle = toggleWidget.decoration as BoxDecoration; - return toggle.color == Colors.teal; - } - return false; - }), findsNothing); - - // tap on text 'OFF' - await tester.tap(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.data!.contains('OFF'); - } - return toggleWidget.textSpan!.toPlainText().contains('OFF'); - } - return false; - })); - - // Rebuild the widget after the state has changed. - await tester.pump(); - - // finds value true - expect(isOn, isTrue); - - // finds enabled color, finds one widget - expect(find.byWidgetPredicate((widget) { - if (widget is DecoratedBox) { - final DecoratedBox toggleWidget = widget; - // ignore: avoid_as - final BoxDecoration toggle = toggleWidget.decoration as BoxDecoration; - return toggle.color == Colors.teal; - } - return false; - }), findsOneWidget); - - // finds disabled color, finds nothing - expect(find.byWidgetPredicate((widget) { - if (widget is DecoratedBox) { - final DecoratedBox toggleWidget = widget; - // ignore: avoid_as - final BoxDecoration toggle = toggleWidget.decoration as BoxDecoration; - return toggle.color == Colors.amber; - } - return false; - }), findsNothing); - }); - - testWidgets('GFToggle with borderRadius and boxShape', - (WidgetTester tester) async { - bool isOn = false; - - final toggle = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFToggle( - key: toggleKey, - value: isOn, - enabledText: 'ON', - disabledText: 'OFF', - disabledThumbColor: Colors.amber, - disabledTrackColor: Colors.amberAccent, - enabledThumbColor: Colors.teal, - enabledTrackColor: Colors.tealAccent, - boxShape: BoxShape.rectangle, - borderRadius: const BorderRadius.all(Radius.circular(4)), - onChanged: (value) { - setState(() { - isOn = value!; - }); - }, - ), - )), - ); - - // find toggle key - await tester.pumpWidget(toggle); - - // finds value false - expect(isOn, isFalse); - - // find border radius, finds one widget - expect(find.byWidgetPredicate((widget) { - if (widget is DecoratedBox) { - final DecoratedBox toggleWidget = widget; - // ignore: avoid_as - final BoxDecoration toggle = toggleWidget.decoration as BoxDecoration; - return toggle.borderRadius == - const BorderRadius.all(Radius.circular(4)); - } - return false; - }), findsOneWidget); - - // find boxShape, rectangle - expect(find.byWidgetPredicate((widget) { - if (widget is PhysicalModel) { - final PhysicalModel toggleWidget = widget; - final PhysicalModel toggle = toggleWidget; - return toggle.shape == BoxShape.rectangle; - } - return false; - }), findsOneWidget); - }); - - testWidgets('GFToggle with enabled and disabled textStyle', - (WidgetTester tester) async { - bool isOn = false; - - final toggle = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFToggle( - key: toggleKey, - value: isOn, - enabledText: 'ON', - disabledText: 'OFF', - enabledTextStyle: enabledTextStyle, - disabledTextStyle: disabledTextStyle, - disabledThumbColor: Colors.amber, - disabledTrackColor: Colors.amberAccent, - enabledThumbColor: Colors.teal, - enabledTrackColor: Colors.tealAccent, - boxShape: BoxShape.rectangle, - borderRadius: const BorderRadius.all(Radius.circular(4)), - onChanged: (value) { - setState(() { - isOn = value!; - }); - }, - ), - )), - ); - - // find toggle key - await tester.pumpWidget(toggle); - - // finds value false - expect(isOn, isFalse); - - // find disabled text color - expect(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.style!.color == disabledTextStyle.color; - } - } - return false; - }), findsOneWidget); - - // find enabled text color - expect(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.style!.color == enabledTextStyle.color; - } - } - return false; - }), findsNothing); - - // tap on text 'OFF' - await tester.tap(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.data!.contains('OFF'); - } - return toggleWidget.textSpan!.toPlainText().contains('OFF'); - } - return false; - })); - - // Rebuild the widget after the state has changed. - await tester.pump(); - - // find disabled text color - expect(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.style!.color == disabledTextStyle.color; - } - } - return false; - }), findsNothing); - - // find enabled text color - expect(find.byWidgetPredicate((widget) { - if (widget is Text) { - final Text toggleWidget = widget; - if (toggleWidget.data != null) { - return toggleWidget.style!.color == enabledTextStyle.color; - } - } - return false; - }), findsOneWidget); - }); - - testWidgets('GFToggle with type ios', (WidgetTester tester) async { - bool isOn = false; - - final toggle = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: GFToggle( - key: toggleKey, - value: isOn, - enabledText: 'ON', - disabledText: 'OFF', - type: GFToggleType.ios, - onChanged: (value) { - setState(() { - isOn = value!; - }); - }, - ), - )), - ); - - // find toggle key - await tester.pumpWidget(toggle); - - // finds value false - expect(isOn, isFalse); - - // find toggle type, ios - expect(find.byWidgetPredicate((widget) { - if (widget is DecoratedBox) { - final DecoratedBox toggleWidget = widget; - // ignore: avoid_as - final BoxDecoration toggle = toggleWidget.decoration as BoxDecoration; - return toggle.shape == BoxShape.circle; - } - return false; - }), findsOneWidget); - }); - - testWidgets('GFToggle can be constructed with long duration', - (WidgetTester tester) async { - bool isSelected = false; - - final toggle = Directionality( - textDirection: TextDirection.ltr, - child: StatefulBuilder( - builder: (BuildContext context, StateSetter setState) => Material( - child: Center( - child: GFToggle( - key: toggleKey, - value: isSelected, - onChanged: (value) { - setState(() { - isSelected = value!; - }); - }, - duration: const Duration(milliseconds: 800), - ), - ), - ), - ), - ); - - await tester.pumpWidget(toggle); - - expect(isSelected, isFalse); - await tester.tap(find.byKey(toggleKey)); - await tester.pump(); - expect(isSelected, isTrue); - }); - - testWidgets('GFToggle with all properties.', (WidgetTester tester) async { - bool isOn = false; - - final GFToggle toggle = GFToggle( - key: toggleKey, - value: isOn, - enabledText: 'ON', - disabledText: 'OFF', - enabledTextStyle: enabledTextStyle, - disabledTextStyle: disabledTextStyle, - disabledThumbColor: Colors.amber, - disabledTrackColor: Colors.amberAccent, - enabledThumbColor: Colors.teal, - enabledTrackColor: Colors.tealAccent, - boxShape: BoxShape.rectangle, - borderRadius: const BorderRadius.all(Radius.circular(4)), - duration: const Duration(milliseconds: 400), - type: GFToggleType.ios, - onChanged: (value) { - isOn = value!; - }, - ); - - final TestApp app = TestApp(toggle); - await tester.pumpWidget(app); - - expect(app.toggle.value, isOn); - expect(app.toggle.enabledText, 'ON'); - expect(app.toggle.disabledText, 'OFF'); - expect(app.toggle.enabledTextStyle, enabledTextStyle); - expect(app.toggle.disabledTextStyle, disabledTextStyle); - expect(app.toggle.enabledThumbColor, Colors.teal); - expect(app.toggle.enabledTrackColor, Colors.tealAccent); - expect(app.toggle.disabledThumbColor, Colors.amber); - expect(app.toggle.disabledTrackColor, Colors.amberAccent); - expect(app.toggle.boxShape, BoxShape.rectangle); - expect(app.toggle.borderRadius, const BorderRadius.all(Radius.circular(4))); - expect(app.toggle.duration, const Duration(milliseconds: 400)); - expect(app.toggle.type, GFToggleType.ios); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.toggle); - final GFToggle toggle; - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - widget.toggle, - ], - ), - ), - ); -} diff --git a/test/typography_test.dart b/test/typography_test.dart deleted file mode 100644 index dfc9d797..00000000 --- a/test/typography_test.dart +++ /dev/null @@ -1,121 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:getwidget/getwidget.dart'; - -void main() { - final Widget childWidget = Container( - width: 11, - height: 22, - ); - - const icon = Icon(Icons.home); - const text = 'Hello'; - - const dividerRadius = BorderRadius.all(Radius.circular(2)); - const textcolor = GFColors.INFO; - const dividerposition = Alignment.center; - const fontWeight = FontWeight.w500; - - testWidgets('GFTypograpgy can be created', (WidgetTester tester) async { - final GFTypography typography = GFTypography( - icon: icon, - dividerBorderRadius: dividerRadius, - text: text, - textColor: textcolor, - dividerAlignment: dividerposition, - type: GFTypographyType.typo2, - child: childWidget, - ); - - final TestApp app = TestApp(typography); - - await tester.pumpWidget(app); - - await tester.pumpWidget(Container(child: childWidget)); - expect(find.byWidget(childWidget), findsOneWidget); - - expect(app.typography.child, childWidget); - expect(app.typography.icon, icon); - expect(app.typography.dividerAlignment, Alignment.center); - expect(app.typography.dividerBorderRadius, dividerRadius); - expect(app.typography.textColor, textcolor); - expect(app.typography.fontWeight, fontWeight); - }); - - testWidgets('GF Typography with divider', (tester) async { - const bool divider = true; - - const GFTypography typography = GFTypography( - text: 'type 1', - showDivider: divider, - ); - - const TestApp app = TestApp(typography); - - expect(app.typography.showDivider, divider); - }); - - testWidgets('GF Typography with opacity', (tester) async { - final textopacity = Colors.black.withOpacity(0.56); - - final GFTypography typography = GFTypography( - text: 'type1', - textColor: textopacity, - ); - - final TestApp app = TestApp(typography); - - expect(app.typography.textColor, textopacity); - }); - - testWidgets('GF Typography with Custom Heading', (tester) async { - final textopacity = Colors.black.withOpacity(0.56); - const bool divider = true; - const icon = GFAvatar(); - const colorfilter = ColorFilter.mode(Colors.black, BlendMode.darken); - const bgImage = NetworkImage( - 'https://images.unsplash.com/photo-1547721064-da6cfb341d50', - ); - - final GFTypography typography = GFTypography( - textColor: textopacity, - showDivider: divider, - icon: icon, - backgroundImage: bgImage, - backgroundImagecolorFilter: colorfilter, - text: 'type1', - ); - - final TestApp app = TestApp(typography); - - expect(app.typography.textColor, textopacity); - expect(app.typography.showDivider, divider); - expect(app.typography.icon, icon); - expect(app.typography.backgroundImage, bgImage); - expect(app.typography.backgroundImagecolorFilter, colorfilter); - }); -} - -class TestApp extends StatefulWidget { - const TestApp(this.typography); - - final GFTypography typography; - - @override - _TestAppState createState() => _TestAppState(); -} - -class _TestAppState extends State { - @override - Widget build(BuildContext context) => MaterialApp( - home: Scaffold( - body: Column( - children: [ - Expanded( - child: widget.typography, - ) - ], - ), - ), - ); -}