Skip to content

Commit

Permalink
feat:切换tab避免重绘g
Browse files Browse the repository at this point in the history
  • Loading branch information
Nealyang committed Jan 10, 2019
1 parent 8dbc11c commit 72aa830
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/views/FirstPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ class FirstPage extends StatefulWidget {
FirstPageState createState() => new FirstPageState();
}

class FirstPageState extends State<FirstPage> {
class FirstPageState extends State<FirstPage> with AutomaticKeepAliveClientMixin{


@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;

@override
void initState() {
Expand Down Expand Up @@ -68,6 +73,7 @@ class FirstPageState extends State<FirstPage> {

@override
Widget build(BuildContext context) {
super.build(context);
return new Column(
children: <Widget>[
new Container(
Expand Down
9 changes: 7 additions & 2 deletions lib/views/collection_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ class CollectionPage extends StatefulWidget {
_CollectionPageState createState() => _CollectionPageState();
}

class _CollectionPageState extends State<CollectionPage> {
class _CollectionPageState extends State<CollectionPage> with AutomaticKeepAliveClientMixin{
_CollectionPageState() {
final eventBus = new EventBus();
ApplicationEvent.event = eventBus;
}
CollectionControlModel _collectionControl = new CollectionControlModel();
List<Collection> _collectionList;
ScrollController _scrollController = new ScrollController();

@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -102,7 +107,7 @@ class _CollectionPageState extends State<CollectionPage> {

@override
Widget build(BuildContext context) {
print(_collectionList);
super.build(context);
if (_collectionList.length == 0) {
return ListView(
children: <Widget>[
Expand Down
8 changes: 7 additions & 1 deletion lib/views/widgetPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class WidgetPage extends StatefulWidget {
SecondPageState createState() => new SecondPageState(catModel);
}

class SecondPageState extends State<WidgetPage> {
class SecondPageState extends State<WidgetPage> with AutomaticKeepAliveClientMixin{
CatControlModel catModel;
SecondPageState(this.catModel) : super();

Expand All @@ -23,6 +23,11 @@ class SecondPageState extends State<WidgetPage> {

List<Cat> categories = [];

@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;

@override
void initState() {
super.initState();
renderCats();
Expand Down Expand Up @@ -52,6 +57,7 @@ class SecondPageState extends State<WidgetPage> {

@override
Widget build(BuildContext context) {
super.build(context);
if (categories.length == 0) {
return ListView(
children: <Widget>[new Container()],
Expand Down

0 comments on commit 72aa830

Please sign in to comment.