Flutter / Dart:如何使选项卡仅呈现一次?

时间:2018-12-14 01:21:39

标签: tabs dart flutter render

我目前使用底部导航栏导航三个标签,但是我刚刚注意到它实际上重新呈现了每个标签更改。如何解决此问题,使其仅渲染一次,并使用该渲染直到手动刷新(稍后将实现)。

import 'package:flutter/material.dart';

import '../styles.dart';

import 'one.dart';
import 'two.dart';
import 'three.dart';

class Home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _HomeState();
}

class _HomeState extends State<Home> {

  final List<Widget> _children = [ One(), Two(), Three(), ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.blue,
        title: Text( 'RefLog', style: Styles.headerLarge ),
        actions: <Widget>[
          new IconButton(
            icon: Icon(Icons.list),
            onPressed: () {},
          )
        ],
      ),
      body: DefaultTabController(
        length: 3,
        child: Scaffold(
          body: TabBarView(
            children: _children,
          ),
          bottomNavigationBar: TabBar(
            tabs: [
              Tab( text: 'One', icon: Icon(Icons.import_contacts, size: 20.0) ),
              Tab( text: 'Two', icon: Icon(Icons.restaurant, size: 20.0) ),
              Tab( text: 'Three', icon: Icon(Icons.record_voice_over, size: 20.0) ),
            ],
            labelStyle: TextStyle(fontSize: 12.0),
            labelColor: Colors.white,
            unselectedLabelColor: Colors.white30,
            indicatorSize: TabBarIndicatorSize.label,
            indicatorColor: Colors.white,
          ),
          backgroundColor: Colors.blue,
        ),
      ),
    );
  }
}

0 个答案:

没有答案