Merge pull request #18 from Nealyang/master

feat:切换tab避免重绘g
This commit is contained in:
Nealyang
2019-01-10 21:33:33 +08:00
committed by GitHub
3 changed files with 21 additions and 4 deletions

View File

@ -20,7 +20,12 @@ class FirstPage extends StatefulWidget {
FirstPageState createState() => new FirstPageState(); 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 @override
void initState() { void initState() {
@ -68,6 +73,7 @@ class FirstPageState extends State<FirstPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context);
return new Column( return new Column(
children: <Widget>[ children: <Widget>[
new Container( new Container(

View File

@ -15,7 +15,7 @@ class CollectionPage extends StatefulWidget {
_CollectionPageState createState() => _CollectionPageState(); _CollectionPageState createState() => _CollectionPageState();
} }
class _CollectionPageState extends State<CollectionPage> { class _CollectionPageState extends State<CollectionPage> with AutomaticKeepAliveClientMixin{
_CollectionPageState() { _CollectionPageState() {
final eventBus = new EventBus(); final eventBus = new EventBus();
ApplicationEvent.event = eventBus; ApplicationEvent.event = eventBus;
@ -23,6 +23,11 @@ class _CollectionPageState extends State<CollectionPage> {
CollectionControlModel _collectionControl = new CollectionControlModel(); CollectionControlModel _collectionControl = new CollectionControlModel();
List<Collection> _collectionList; List<Collection> _collectionList;
ScrollController _scrollController = new ScrollController(); ScrollController _scrollController = new ScrollController();
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -102,7 +107,7 @@ class _CollectionPageState extends State<CollectionPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print(_collectionList); super.build(context);
if (_collectionList.length == 0) { if (_collectionList.length == 0) {
return ListView( return ListView(
children: <Widget>[ children: <Widget>[

View File

@ -13,7 +13,7 @@ class WidgetPage extends StatefulWidget {
SecondPageState createState() => new SecondPageState(catModel); SecondPageState createState() => new SecondPageState(catModel);
} }
class SecondPageState extends State<WidgetPage> { class SecondPageState extends State<WidgetPage> with AutomaticKeepAliveClientMixin{
CatControlModel catModel; CatControlModel catModel;
SecondPageState(this.catModel) : super(); SecondPageState(this.catModel) : super();
@ -23,6 +23,11 @@ class SecondPageState extends State<WidgetPage> {
List<Cat> categories = []; List<Cat> categories = [];
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
@override
void initState() { void initState() {
super.initState(); super.initState();
renderCats(); renderCats();
@ -52,6 +57,7 @@ class SecondPageState extends State<WidgetPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
super.build(context);
if (categories.length == 0) { if (categories.length == 0) {
return ListView( return ListView(
children: <Widget>[new Container()], children: <Widget>[new Container()],