-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d43467d
commit 625d3ac
Showing
7 changed files
with
193 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import './run.dart'; | ||
|
||
// page_entry 中的页面切换直接使用的 stack,性能存在问题,在此模板中尝试下 TabBar+TabBarView+AutomaticKeepAliveClientMixin | ||
|
||
class _TabChoice { | ||
final String title; | ||
final IconData icon; | ||
const _TabChoice({this.title, this.icon}); | ||
} | ||
|
||
const List<_TabChoice> _tabChoiceList = <_TabChoice>[ | ||
_TabChoice(title: '跑步',icon: Icons.directions_run), | ||
_TabChoice(title: '徒步', icon: Icons.directions_walk), | ||
_TabChoice(title: '跑步',icon: Icons.directions_run), | ||
_TabChoice(title: '徒步', icon: Icons.directions_walk), | ||
_TabChoice(title: '跑步',icon: Icons.directions_run), | ||
_TabChoice(title: '徒步', icon: Icons.directions_walk), | ||
_TabChoice(title: '跑步',icon: Icons.directions_run), | ||
_TabChoice(title: '徒步', icon: Icons.directions_walk), | ||
_TabChoice(title: '跑步',icon: Icons.directions_run), | ||
_TabChoice(title: '徒步', icon: Icons.directions_walk), | ||
_TabChoice(title: '跑步',icon: Icons.directions_run), | ||
_TabChoice(title: '徒步', icon: Icons.directions_walk), | ||
_TabChoice(title: '跑步',icon: Icons.directions_run), | ||
_TabChoice(title: '徒步', icon: Icons.directions_walk), | ||
_TabChoice(title: '跑步',icon: Icons.directions_run), | ||
_TabChoice(title: '徒步', icon: Icons.directions_walk), | ||
]; | ||
|
||
class SportsIndexPage extends StatefulWidget { | ||
@override | ||
createState() => _SportsIndexState(); | ||
} | ||
|
||
class _SportsIndexState extends State { | ||
@override | ||
Widget build(BuildContext context) { | ||
return DefaultTabController( | ||
child: Scaffold( | ||
appBar: AppBar( | ||
title: Text('运动模块'), | ||
bottom: TabBar( | ||
isScrollable: true, | ||
tabs: _tabChoiceList.map((choice) { | ||
return Tab( | ||
text: choice.title, | ||
icon: Icon(choice.icon), | ||
); | ||
}).toList(), | ||
), | ||
), | ||
body: TabBarView( | ||
children: _tabChoiceList.map((choice) { | ||
return SportsRunPage(); | ||
}).toList(), | ||
), | ||
), | ||
length: _tabChoiceList.length, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class SportsRunPage extends StatefulWidget { | ||
@override | ||
createState() => _SportsRunPageState(); | ||
} | ||
|
||
class _SportsRunPageState extends State with AutomaticKeepAliveClientMixin { | ||
|
||
int count = 0; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
print('--------异步实例化--------'); | ||
} | ||
|
||
@override | ||
bool get wantKeepAlive => true; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Text('runnding $count'), | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: () => setState(() { count = count + 1; }), | ||
child: Icon(Icons.add), | ||
), | ||
); | ||
} | ||
} |