Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd09755

Browse files
author
wz
committed
use DefaultTabController
1 parent 513f910 commit fd09755

2 files changed

Lines changed: 49 additions & 26 deletions

File tree

lib/http/bi_net.dart

Whitespace-only changes.

lib/pages/home_page.dart

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,68 @@ class HomePageRoute extends StatefulWidget {
1010
_HomePageRouteState createState() => _HomePageRouteState();
1111
}
1212

13-
class _HomePageRouteState extends State<HomePageRoute>
14-
with SingleTickerProviderStateMixin {
15-
List _tabs = ['推荐', '热门', '动画', '游戏', '科技', '知识', '运动'];
16-
late TabController _tabController;
13+
class _HomePageRouteState extends State<HomePageRoute> {
14+
final List _tabs = ['推荐', '热门', '动画', '游戏', '科技', '知识', '运动'];
15+
// late TabController _tabController;
1716

1817
@override
1918
void initState() {
2019
super.initState();
21-
_tabController = TabController(length: _tabs.length, vsync: this);
20+
// _tabController = TabController(length: _tabs.length, vsync: this);
2221
}
2322

2423
@override
2524
Widget build(BuildContext context) {
26-
return Scaffold(
27-
body: Column(
28-
children: [
29-
TopNavigationBar(child: _appBar()),
30-
Container(
31-
child: _tabBar(),
32-
color: Colors.white,
33-
),
34-
Flexible(
35-
child: TabBarView(
36-
controller: _tabController,
37-
children: _tabs.map((e) => HomeCategoryPageRoute()).toList()),
38-
),
39-
Image.asset(
40-
'images/avatar.png',
41-
width: 50,
42-
)
43-
],
25+
return DefaultTabController(
26+
length: _tabs.length,
27+
child: Scaffold(
28+
body: Column(
29+
children: [
30+
TopNavigationBar(child: _appBar()),
31+
Container(
32+
child: _tabBar(),
33+
color: Colors.white,
34+
),
35+
Flexible(
36+
child: TabBarView(
37+
// controller: _tabController,
38+
children: _tabs.map((e) => HomeCategoryPageRoute()).toList()),
39+
),
40+
Image.asset(
41+
'images/avatar.png',
42+
width: 50,
43+
)
44+
],
45+
),
4446
),
4547
);
48+
49+
// return Scaffold(
50+
// body: Column(
51+
// children: [
52+
// TopNavigationBar(child: _appBar()),
53+
// Container(
54+
// child: _tabBar(),
55+
// color: Colors.white,
56+
// ),
57+
// Flexible(
58+
// child: TabBarView(
59+
// controller: _tabController,
60+
// children: _tabs.map((e) => HomeCategoryPageRoute()).toList()),
61+
// ),
62+
// Image.asset(
63+
// 'images/avatar.png',
64+
// width: 50,
65+
// )
66+
// ],
67+
// ),
68+
// );
4669
}
4770

4871
// 分类tab
4972
TabBar _tabBar() {
5073
return TabBar(
51-
controller: _tabController,
74+
// controller: _tabController,
5275
isScrollable: true,
5376
labelColor: Colors.black,
5477
indicator: const UnderlineTabIndicator(
@@ -57,10 +80,10 @@ class _HomePageRouteState extends State<HomePageRoute>
5780
tabs: _tabs
5881
.map((e) => Tab(
5982
child: Padding(
60-
padding: EdgeInsets.only(left: 5, right: 5),
83+
padding: const EdgeInsets.only(left: 5, right: 5),
6184
child: Text(
6285
e,
63-
style: TextStyle(fontSize: 16),
86+
style: const TextStyle(fontSize: 16),
6487
),
6588
)))
6689
.toList(),

0 commit comments

Comments
 (0)