Skip to content

Commit 2d4f681

Browse files
authored
Merge pull request #58 from deepikahr/badge_testing
Badge testing
2 parents 39b1b4e + 90a4c55 commit 2d4f681

File tree

7 files changed

+862
-43
lines changed

7 files changed

+862
-43
lines changed

example/lib/main_temp.dart

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -447,38 +447,38 @@ class _MyHomePageState extends State<MyHomePage>
447447
// ),
448448
// ),
449449

450-
// GFSearchBar(
451-
// // searchBoxInputDecoration: InputDecoration(
452-
// // enabledBorder: OutlineInputBorder(
453-
// // borderSide: BorderSide(
454-
// // color: Colors.teal,
455-
// // ),
456-
// // borderRadius: BorderRadius.circular(50)
457-
// // ),
458-
// // ),
459-
// searchList: list,
460-
// // hideSearchBoxWhenItemSelected: false,
461-
// // overlaySearchListHeight: 100.0,
462-
// searchQueryBuilder: (query, list) => list
463-
// .where((item) =>
464-
// item.toLowerCase().contains(query.toLowerCase()))
465-
// .toList(),
466-
// overlaySearchListItemBuilder: (item) => Container(
467-
// padding: const EdgeInsets.all(8),
468-
// child: Text(
469-
// item,
470-
// style: const TextStyle(fontSize: 18),
471-
// ),
472-
// ),
473-
// // noItemsFoundWidget: Container(
474-
// // color: Colors.green,
475-
// // child: Text("no items found..."),
476-
// // ),
477-
// onItemSelected: (item) {
478-
// setState(() {
479-
// print('selected item $item');
480-
// });
481-
// }),
450+
GFSearchBar(
451+
// searchBoxInputDecoration: InputDecoration(
452+
// enabledBorder: OutlineInputBorder(
453+
// borderSide: BorderSide(
454+
// color: Colors.teal,
455+
// ),
456+
// borderRadius: BorderRadius.circular(50)
457+
// ),
458+
// ),
459+
searchList: list,
460+
// hideSearchBoxWhenItemSelected: false,
461+
// overlaySearchListHeight: 100.0,
462+
searchQueryBuilder: (query, list) => list
463+
.where((item) =>
464+
item.toLowerCase().contains(query.toLowerCase()))
465+
.toList(),
466+
overlaySearchListItemBuilder: (item) => Container(
467+
padding: const EdgeInsets.all(8),
468+
child: Text(
469+
item,
470+
style: const TextStyle(fontSize: 18),
471+
),
472+
),
473+
// noItemsFoundWidget: Container(
474+
// color: Colors.green,
475+
// child: Text("no items found..."),
476+
// ),
477+
onItemSelected: (item) {
478+
setState(() {
479+
print('selected item $item');
480+
});
481+
}),
482482

483483
// GFCard(
484484
// content: Column(
@@ -1742,15 +1742,16 @@ class _MyHomePageState extends State<MyHomePage>
17421742
// // borderShape: RoundedRectangleBorder(side: BorderSide(color: Colors.pink, width: 2.0, style: BorderStyle.solid), borderRadius: BorderRadius.zero),
17431743
// ),
17441744

1745-
// GFBadge(
1746-
// text: '12',
1747-
//// color: GFColors.DARK,
1745+
// ignore: prefer_const_constructors
1746+
GFBadge(
1747+
// text: '12',
1748+
// color: GFColors.DARK,
17481749
// shape: GFBadgeShape.circle,
1749-
//// size: GFSize.small,
1750-
//// border: BorderSide(color: Colors.pink, width: 1.0, style: BorderStyle.solid),
1751-
//// textColor: GFColors.WHITE,
1752-
//// textStyle: TextStyle(fontWeight: FontWeight.w500, fontSize: 8.0),
1753-
// ),
1750+
// size: GFSize.MEDIUM,
1751+
// border: BorderSide(color: Colors.pink, width: 1.0, style: BorderStyle.solid),
1752+
// textColor: GFColors.WHITE,
1753+
// textStyle: TextStyle(fontWeight: FontWeight.w500, fontSize: 8.0),
1754+
),
17541755

17551756
RaisedButton(
17561757
onPressed: () {},

lib/components/search_bar/gf_search_bar.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ typedef QueryBuilder<T> = List<T> Function(
99
);
1010

1111
class GFSearchBar<T> extends StatefulWidget {
12-
/// search bar with variuos customization option
12+
/// search bar with various customization option
1313
const GFSearchBar({
1414
@required this.searchList,
1515
@required this.overlaySearchListItemBuilder,
@@ -21,7 +21,10 @@ class GFSearchBar<T> extends StatefulWidget {
2121
this.overlaySearchListHeight,
2222
this.noItemsFoundWidget,
2323
this.searchBoxInputDecoration,
24-
}) : super(key: key);
24+
}) : assert(searchList != null),
25+
assert(overlaySearchListItemBuilder != null),
26+
assert(searchQueryBuilder != null),
27+
super(key: key);
2528

2629
/// List of text or [Widget] reference for users
2730
final List<T> searchList;

test/badge_test.dart

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:getwidget/getwidget.dart';
4+
5+
void main() {
6+
const text = '1';
7+
const textStyle = TextStyle(fontSize: 14, color: Colors.black);
8+
const size = GFSize.SMALL;
9+
const textColor = GFColors.INFO;
10+
const color = Colors.amber;
11+
const border =
12+
BorderSide(color: Colors.tealAccent, width: 1, style: BorderStyle.solid);
13+
const shape = RoundedRectangleBorder(
14+
side: BorderSide(color: Colors.pink, width: 2, style: BorderStyle.solid),
15+
borderRadius: BorderRadius.zero);
16+
const childWidget = Text('hey');
17+
18+
testWidgets('GF Badge without shape', (tester) async {
19+
// `GFBadge.shape` null.
20+
expect(
21+
() => GFBadge(
22+
shape: null,
23+
),
24+
throwsAssertionError,
25+
);
26+
});
27+
28+
testWidgets('GF Badge can be constructed', (tester) async {
29+
const GFBadge badge = GFBadge(
30+
text: text,
31+
textStyle: textStyle,
32+
size: size,
33+
);
34+
35+
const TestApp app = TestApp(badge);
36+
37+
await tester.pumpWidget(app);
38+
39+
expect(find.text('1'), findsOneWidget);
40+
41+
expect(app.badge.text, text);
42+
expect(app.badge.textStyle, textStyle);
43+
expect(app.badge.size, size);
44+
45+
await tester.pumpWidget(app);
46+
});
47+
48+
testWidgets('GF Badge with color and textColor', (tester) async {
49+
const GFBadge badge = GFBadge(
50+
text: text,
51+
size: size,
52+
textColor: textColor,
53+
color: color,
54+
);
55+
56+
const TestApp app = TestApp(badge);
57+
58+
await tester.pumpWidget(app);
59+
60+
expect(find.text('1'), findsOneWidget);
61+
62+
expect(app.badge.text, text);
63+
expect(app.badge.size, size);
64+
expect(app.badge.textColor, textColor);
65+
expect(app.badge.color, color);
66+
67+
await tester.pumpWidget(app);
68+
});
69+
70+
testWidgets(
71+
'GF Badge with GFBadgeShape like circle, standard, square and pills',
72+
(tester) async {
73+
const GFBadge badge = GFBadge(
74+
text: text,
75+
size: size,
76+
textColor: textColor,
77+
color: color,
78+
shape: GFBadgeShape.circle,
79+
);
80+
81+
const TestApp app = TestApp(badge);
82+
83+
await tester.pumpWidget(app);
84+
85+
expect(find.text('1'), findsOneWidget);
86+
87+
expect(app.badge.text, text);
88+
expect(app.badge.size, size);
89+
expect(app.badge.textColor, textColor);
90+
expect(app.badge.color, color);
91+
expect(app.badge.shape, GFBadgeShape.circle);
92+
93+
await tester.pumpWidget(app);
94+
});
95+
96+
testWidgets('GF Badge with custom border and shape', (tester) async {
97+
const GFBadge badge = GFBadge(
98+
text: text,
99+
size: size,
100+
textColor: textColor,
101+
color: color,
102+
borderShape: shape,
103+
border: border,
104+
);
105+
106+
const TestApp app = TestApp(badge);
107+
108+
await tester.pumpWidget(app);
109+
110+
expect(find.text('1'), findsOneWidget);
111+
112+
expect(app.badge.text, text);
113+
expect(app.badge.size, size);
114+
expect(app.badge.textColor, textColor);
115+
expect(app.badge.color, color);
116+
expect(app.badge.borderShape, shape);
117+
expect(app.badge.border, border);
118+
119+
await tester.pumpWidget(app);
120+
});
121+
122+
testWidgets('GF Badge with custom child', (tester) async {
123+
const GFBadge badge = GFBadge(
124+
child: childWidget,
125+
size: size,
126+
);
127+
128+
const TestApp app = TestApp(badge);
129+
130+
await tester.pumpWidget(app);
131+
132+
expect(find.text('hey'), findsOneWidget);
133+
134+
expect(app.badge.child, childWidget);
135+
136+
await tester.pumpWidget(app);
137+
});
138+
}
139+
140+
class TestApp extends StatefulWidget {
141+
const TestApp(this.badge);
142+
143+
final GFBadge badge;
144+
145+
@override
146+
_TestAppState createState() => _TestAppState();
147+
}
148+
149+
class _TestAppState extends State<TestApp> {
150+
@override
151+
Widget build(BuildContext context) => MaterialApp(
152+
home: Scaffold(
153+
body: Column(
154+
children: [
155+
widget.badge,
156+
],
157+
),
158+
),
159+
);
160+
}

0 commit comments

Comments
 (0)