Skip to content

Commit b1dfb61

Browse files
committed
tabs testing completed
1 parent e681b8c commit b1dfb61

File tree

6 files changed

+526
-182
lines changed

6 files changed

+526
-182
lines changed

example/lib/main_temp.dart

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ final List<String> imageList = [
1515

1616
void main() => runApp(MyApp());
1717

18+
class StateMarker extends StatefulWidget {
19+
const StateMarker({Key key, this.child}) : super(key: key);
20+
final Widget child;
21+
@override
22+
StateMarkerState createState() => StateMarkerState();
23+
}
24+
25+
class StateMarkerState extends State<StateMarker> {
26+
String marker;
27+
@override
28+
Widget build(BuildContext context) {
29+
if (widget.child != null) {
30+
return widget.child;
31+
}
32+
return Container();
33+
}
34+
}
35+
1836
class MyApp extends StatelessWidget {
1937
@override
2038
Widget build(BuildContext context) => MaterialApp(
@@ -72,7 +90,7 @@ class _MyHomePageState extends State<MyHomePage>
7290
];
7391

7492
final List<Widget> tabList = [
75-
const Text(
93+
Text(
7694
'AAAAAA',
7795
),
7896
const Text(
@@ -315,52 +333,22 @@ class _MyHomePageState extends State<MyHomePage>
315333
),
316334
// backgroundColor: Colors.blueGrey,
317335
body:
318-
GFTabs(
319-
initialIndex: 4,
320-
// isScrollable: true,
321-
length: 5,
322-
tabs: const <Widget>[
323-
Tab(
324-
icon: Icon(Icons.directions_bike),
325-
child: Text(
326-
"Tab1",
327-
),
328-
),
329-
Tab(
330-
icon: Icon(Icons.directions_bus),
331-
child: Text(
332-
"Tab2",
333-
),
334-
),
335-
Tab(
336-
icon: Icon(Icons.directions_railway),
337-
child: Text(
338-
"Tab3",
339-
),
340-
),
341-
Tab(
342-
icon: Icon(Icons.directions_bike),
343-
child: Text(
344-
"Tab4",
345-
),
346-
),
347-
Tab(
348-
icon: Icon(Icons.directions_bus),
349-
child: Text(
350-
"Tab5",
351-
),
352-
),
353-
],
354-
tabBarView: GFTabBarView(
355-
children: <Widget>[
356-
Container(child: Icon(Icons.directions_bike), color: Colors.red,),
357-
Container(child: Icon(Icons.directions_bus), color: Colors.blue,),
358-
Container(child: Icon(Icons.directions_railway), color: Colors.orange,),
359-
Container(child: Icon(Icons.directions_bike), color: Colors.red,),
360-
Container(child: Icon(Icons.directions_bus), color: Colors.blue,),
361-
],
362-
),
363-
),
336+
337+
// GFTabBarView(
338+
// controller: tabController,
339+
// children: tabList.map((text) => StateMarker(
340+
// child: text
341+
// )).toList()
342+
// ),
343+
GFTabs(
344+
height: 960,
345+
// isScrollable: true,
346+
length: 5,
347+
tabs: tabList,
348+
tabBarView: GFTabBarView(
349+
children:
350+
tabList.map((text) => StateMarker(child: text)).toList()),
351+
),
364352
// GFTabBarView(
365353
// height: 200.0,
366354
// controller: tabController,

test/segment_tabs_test.dart

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
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+
final Key segmentTabsKey = UniqueKey();
7+
8+
final List<Widget> tabList = [
9+
const Text(
10+
'Tab1',
11+
),
12+
const Tab(
13+
icon: Icon(Icons.favorite),
14+
),
15+
const Text(
16+
'Tab3',
17+
),
18+
];
19+
20+
final indicator = BoxDecoration(
21+
color: Colors.teal,
22+
border: Border.all(color: Colors.tealAccent, width: 2));
23+
24+
testWidgets('GFSegmentTabs without length, isScrollable', (tester) async {
25+
// `GFSegmentTabs.length` null
26+
expect(
27+
() => GFSegmentTabs(
28+
length: null,
29+
),
30+
throwsAssertionError,
31+
);
32+
});
33+
34+
testWidgets('GFSegmentTabs can be constructed', (tester) async {
35+
final TabController tabController =
36+
TabController(length: 3, initialIndex: 0, vsync: tester);
37+
38+
final GFSegmentTabs segmentTabs = GFSegmentTabs(
39+
key: segmentTabsKey,
40+
tabController: tabController,
41+
length: tabList.length,
42+
tabs: tabList,
43+
);
44+
45+
final TestApp app = TestApp(segmentTabs);
46+
await tester.pumpWidget(app);
47+
48+
// find segmentTabs by key
49+
expect(find.byKey(segmentTabsKey), findsOneWidget);
50+
// find the 'Tab1' text in segmentTabs
51+
expect(find.text('Tab1'), findsOneWidget);
52+
53+
expect(tabController, isNotNull);
54+
expect(tabController.index, 0);
55+
expect(tabController.previousIndex, 0);
56+
await tester.tap(find.byIcon(Icons.favorite));
57+
await tester.pump();
58+
expect(tabController.indexIsChanging, true);
59+
await tester.pump(const Duration(seconds: 1));
60+
expect(tabController.index, 1);
61+
expect(tabController.previousIndex, 0);
62+
expect(tabController.indexIsChanging, false);
63+
await tester.tap(find.byWidget(tabList[2]));
64+
await tester.pump();
65+
await tester.pump(const Duration(seconds: 1));
66+
expect(tabController.index, 2);
67+
expect(tabController.previousIndex, 1);
68+
await tester.tap(find.text('Tab1'));
69+
await tester.pump();
70+
await tester.pump(const Duration(seconds: 1));
71+
expect(tabController.index, 0);
72+
expect(tabController.previousIndex, 2);
73+
});
74+
75+
testWidgets('GFSegmentTabs with on taps selected tab', (tester) async {
76+
final TabController tabController =
77+
TabController(length: 3, initialIndex: 0, vsync: tester);
78+
79+
final GFSegmentTabs segmentTabs = GFSegmentTabs(
80+
key: segmentTabsKey,
81+
tabController: tabController,
82+
length: tabList.length,
83+
tabs: tabList,
84+
);
85+
86+
final TestApp app = TestApp(segmentTabs);
87+
await tester.pumpWidget(app);
88+
89+
// find segmentTabs by key
90+
expect(find.byKey(segmentTabsKey), findsOneWidget);
91+
// find the 'Tab1' text in segmentTabs
92+
expect(find.text('Tab1'), findsOneWidget);
93+
expect(find.byIcon(Icons.favorite), findsOneWidget);
94+
expect(find.byWidget(tabList[2]), findsOneWidget);
95+
expect(tabController.index, 0);
96+
expect(tabController.previousIndex, 0);
97+
await tester.tap(find.byWidget(tabList[2]));
98+
await tester.pumpAndSettle();
99+
expect(tabController.index, 2);
100+
await tester.tap(find.byIcon(Icons.favorite));
101+
await tester.pumpAndSettle();
102+
expect(tabController.index, 1);
103+
await tester.tap(find.text('Tab1'));
104+
await tester.pumpAndSettle();
105+
expect(tabController.index, 0);
106+
});
107+
108+
testWidgets('GFSegmentTabs with on taps center selected tab', (tester) async {
109+
final TabController controller =
110+
TabController(length: 12, initialIndex: 0, vsync: tester);
111+
final List<Widget> tabs = [
112+
const Text(
113+
'Tab_A',
114+
),
115+
const Text(
116+
'Tab_B',
117+
),
118+
const Text(
119+
'Tab_C',
120+
),
121+
const Text(
122+
'Tab_D',
123+
),
124+
const Text(
125+
'Tab_E',
126+
),
127+
const Text(
128+
'Tab_F',
129+
),
130+
const Text(
131+
'Tab_G',
132+
),
133+
const Text(
134+
'Tab_H',
135+
),
136+
const Text(
137+
'Tab_I',
138+
),
139+
const Text(
140+
'Tab_J',
141+
),
142+
const Text(
143+
'Tab_K',
144+
),
145+
const Text(
146+
'Tab_L',
147+
),
148+
];
149+
150+
final GFSegmentTabs segmentTabs = GFSegmentTabs(
151+
key: segmentTabsKey,
152+
tabController: controller,
153+
length: tabs.length,
154+
tabs: tabs,
155+
);
156+
157+
final TestApp app = TestApp(segmentTabs);
158+
await tester.pumpWidget(app);
159+
160+
// find segmentTabs by key
161+
expect(find.byKey(segmentTabsKey), findsOneWidget);
162+
// find the 'Tab_A' text in segmentTabs
163+
expect(find.text('Tab_A'), findsOneWidget);
164+
expect(controller, isNotNull);
165+
expect(controller.index, 0);
166+
expect(tester.getSize(find.byKey(segmentTabsKey)).width, equals(800.0));
167+
// The center of the 'Tab_F' item is to the right of the TabBar's center
168+
expect(tester.getCenter(find.text('Tab_F')).dx, greaterThan(301.0));
169+
await tester.tap(find.text('Tab_F'));
170+
await tester.pumpAndSettle();
171+
expect(controller.index, 5);
172+
// The center of the 'Tab_F' item is now at the TabBar's center
173+
expect(tester.getCenter(find.text('Tab_F')).dx, closeTo(366.0, 1.0));
174+
});
175+
176+
testWidgets('GFSegmentTabs can be constructed with properties',
177+
(tester) async {
178+
final TabController tabController =
179+
TabController(length: 3, initialIndex: 0, vsync: tester);
180+
181+
final GFSegmentTabs segmentTabs = GFSegmentTabs(
182+
key: segmentTabsKey,
183+
tabController: tabController,
184+
length: tabList.length,
185+
tabs: tabList,
186+
tabBarColor: Colors.blueGrey,
187+
height: 66,
188+
width: 244,
189+
border: Border.all(color: Colors.teal),
190+
borderRadius: BorderRadius.circular(5),
191+
indicator: indicator,
192+
indicatorWeight: 5,
193+
indicatorPadding: const EdgeInsets.all(8),
194+
indicatorColor: GFColors.WHITE,
195+
indicatorSize: TabBarIndicatorSize.tab,
196+
labelPadding: const EdgeInsets.all(8),
197+
labelColor: Colors.lightGreen,
198+
unselectedLabelColor: Colors.black,
199+
labelStyle: const TextStyle(
200+
fontWeight: FontWeight.w500,
201+
fontSize: 16,
202+
),
203+
unselectedLabelStyle: const TextStyle(
204+
fontWeight: FontWeight.w500,
205+
fontSize: 12,
206+
),
207+
);
208+
209+
final TestApp app = TestApp(segmentTabs);
210+
await tester.pumpWidget(app);
211+
212+
expect(app.segmentTabs.tabController, tabController);
213+
expect(app.segmentTabs.length, tabList.length);
214+
expect(app.segmentTabs.tabs, tabList);
215+
expect(app.segmentTabs.tabBarColor, Colors.blueGrey);
216+
expect(app.segmentTabs.height, 66);
217+
expect(app.segmentTabs.width, 244);
218+
expect(app.segmentTabs.border, Border.all(color: Colors.teal));
219+
expect(app.segmentTabs.borderRadius, BorderRadius.circular(5));
220+
expect(app.segmentTabs.indicator, indicator);
221+
expect(app.segmentTabs.indicatorWeight, 5);
222+
expect(app.segmentTabs.indicatorPadding, const EdgeInsets.all(8));
223+
expect(app.segmentTabs.indicatorColor, GFColors.WHITE);
224+
expect(app.segmentTabs.indicatorSize, TabBarIndicatorSize.tab);
225+
expect(app.segmentTabs.labelPadding, const EdgeInsets.all(8));
226+
expect(app.segmentTabs.labelColor, Colors.lightGreen);
227+
expect(app.segmentTabs.unselectedLabelColor, Colors.black);
228+
expect(
229+
app.segmentTabs.labelStyle,
230+
const TextStyle(
231+
fontWeight: FontWeight.w500,
232+
fontSize: 16,
233+
));
234+
expect(
235+
app.segmentTabs.unselectedLabelStyle,
236+
const TextStyle(
237+
fontWeight: FontWeight.w500,
238+
fontSize: 12,
239+
));
240+
});
241+
}
242+
243+
class TestApp extends StatefulWidget {
244+
const TestApp(this.segmentTabs);
245+
246+
final GFSegmentTabs segmentTabs;
247+
248+
@override
249+
_TestAppState createState() => _TestAppState();
250+
}
251+
252+
class _TestAppState extends State<TestApp> {
253+
@override
254+
Widget build(BuildContext context) => MaterialApp(
255+
home: Scaffold(
256+
appBar: AppBar(
257+
title: const Text('Segment Tabs'),
258+
),
259+
body: const Text('Body'),
260+
bottomNavigationBar: widget.segmentTabs,
261+
),
262+
);
263+
}

test/shimmer_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void main() {
77
width: 111,
88
height: 222,
99
);
10-
const firstColor = Colors.teal;
10+
final firstColor = Colors.teal;
1111
final secondColor = Colors.tealAccent;
1212

1313
const count = 5;

0 commit comments

Comments
 (0)