|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import 'package:getwidget/getwidget.dart'; |
| 4 | +import 'package:flutter/cupertino.dart'; |
| 5 | + |
| 6 | +void main() { |
| 7 | + const color = Colors.teal; |
| 8 | + const bordercolor = Colors.black; |
| 9 | + const spacing = 1.0; |
| 10 | + const itemcount = 5; |
| 11 | + const size = GFSize.MEDIUM; |
| 12 | + const filledicon = Icon(Icons.star); |
| 13 | + const halffilled = Icon(Icons.star_border); |
| 14 | + const allowhalfRating = true; |
| 15 | + const showtextForm = false; |
| 16 | + const suffixicon = Icon(Icons.face_outlined); |
| 17 | + const margin = EdgeInsets.symmetric(vertical: 16); |
| 18 | + const padding = EdgeInsets.symmetric(horizontal: 16); |
| 19 | + const inputdecorations = InputDecoration( |
| 20 | + icon: Icon(Icons.face_outlined), |
| 21 | + labelText: 'Hi', |
| 22 | + labelStyle: TextStyle(fontSize: 14, color: Colors.black)); |
| 23 | + final ratingController = TextEditingController(); |
| 24 | + final customController = TextEditingController(); |
| 25 | + double rating = 3; |
| 26 | + |
| 27 | + testWidgets('Basic GF Rating can be created.', (WidgetTester tester) async { |
| 28 | + await tester.pumpWidget( |
| 29 | + MaterialApp( |
| 30 | + home: StatefulBuilder( |
| 31 | + builder: (BuildContext context, StateSetter setState) => Material( |
| 32 | + child: GFRating( |
| 33 | + itemCount: itemcount, |
| 34 | + inputDecorations: inputdecorations, |
| 35 | + spacing: spacing, |
| 36 | + value: rating, |
| 37 | + margin: margin, |
| 38 | + padding: padding, |
| 39 | + size: size, |
| 40 | + color: color, |
| 41 | + borderColor: bordercolor, |
| 42 | + onChanged: (value) { |
| 43 | + setState(() { |
| 44 | + rating = value; |
| 45 | + }); |
| 46 | + }, |
| 47 | + ))), |
| 48 | + ), |
| 49 | + ); |
| 50 | + }); |
| 51 | + |
| 52 | + testWidgets('GF Rating with icons.', (WidgetTester tester) async { |
| 53 | + await tester.pumpWidget( |
| 54 | + MaterialApp( |
| 55 | + home: StatefulBuilder( |
| 56 | + builder: (BuildContext context, StateSetter setState) => Material( |
| 57 | + child: GFRating( |
| 58 | + itemCount: itemcount, |
| 59 | + size: size, |
| 60 | + color: color, |
| 61 | + filledIcon: filledicon, |
| 62 | + value: rating, |
| 63 | + onChanged: (value) { |
| 64 | + setState(() { |
| 65 | + rating = value; |
| 66 | + }); |
| 67 | + }, |
| 68 | + ))), |
| 69 | + ), |
| 70 | + ); |
| 71 | + }); |
| 72 | + |
| 73 | + testWidgets('GF Rating with half rating property.', |
| 74 | + (WidgetTester tester) async { |
| 75 | + await tester.pumpWidget( |
| 76 | + MaterialApp( |
| 77 | + home: StatefulBuilder( |
| 78 | + builder: (BuildContext context, StateSetter setState) => Material( |
| 79 | + child: GFRating( |
| 80 | + itemCount: itemcount, |
| 81 | + size: size, |
| 82 | + color: color, |
| 83 | + filledIcon: filledicon, |
| 84 | + halfFilledIcon: halffilled, |
| 85 | + allowHalfRating: allowhalfRating, |
| 86 | + value: rating, |
| 87 | + onChanged: (value) { |
| 88 | + setState(() { |
| 89 | + rating = value; |
| 90 | + }); |
| 91 | + }, |
| 92 | + ))), |
| 93 | + ), |
| 94 | + ); |
| 95 | + }); |
| 96 | + |
| 97 | + testWidgets('GF Rating using textformfield data input.', |
| 98 | + (WidgetTester tester) async { |
| 99 | + await tester.pumpWidget( |
| 100 | + MaterialApp( |
| 101 | + home: StatefulBuilder( |
| 102 | + builder: (BuildContext context, StateSetter setState) => Material( |
| 103 | + child: GFRating( |
| 104 | + itemCount: itemcount, |
| 105 | + size: size, |
| 106 | + color: color, |
| 107 | + filledIcon: filledicon, |
| 108 | + controller: ratingController, |
| 109 | + showTextForm: showtextForm, |
| 110 | + value: rating, |
| 111 | + onChanged: (value) { |
| 112 | + setState(() { |
| 113 | + rating = value; |
| 114 | + }); |
| 115 | + }, |
| 116 | + ))), |
| 117 | + ), |
| 118 | + ); |
| 119 | + }); |
| 120 | + |
| 121 | + testWidgets('Custom GF Rating using textformfield & icons.', |
| 122 | + (WidgetTester tester) async { |
| 123 | + await tester.pumpWidget( |
| 124 | + MaterialApp( |
| 125 | + home: StatefulBuilder( |
| 126 | + builder: (BuildContext context, StateSetter setState) => Material( |
| 127 | + child: GFRating( |
| 128 | + itemCount: itemcount, |
| 129 | + size: size, |
| 130 | + color: color, |
| 131 | + filledIcon: filledicon, |
| 132 | + controller: customController, |
| 133 | + suffixIcon: suffixicon, |
| 134 | + showTextForm: showtextForm, |
| 135 | + value: rating, |
| 136 | + onChanged: (value) { |
| 137 | + setState(() { |
| 138 | + rating = value; |
| 139 | + }); |
| 140 | + }, |
| 141 | + ))), |
| 142 | + ), |
| 143 | + ); |
| 144 | + }); |
| 145 | +} |
| 146 | + |
| 147 | +class TestApp extends StatefulWidget { |
| 148 | + const TestApp(this.rating); |
| 149 | + final GFRating rating; |
| 150 | + @override |
| 151 | + _TestAppState createState() => _TestAppState(); |
| 152 | +} |
| 153 | + |
| 154 | +class _TestAppState extends State<TestApp> { |
| 155 | + @override |
| 156 | + Widget build(BuildContext context) => MaterialApp( |
| 157 | + home: Scaffold( |
| 158 | + body: Column( |
| 159 | + children: [ |
| 160 | + widget.rating, |
| 161 | + ], |
| 162 | + ), |
| 163 | + ), |
| 164 | + ); |
| 165 | +} |
0 commit comments