Newer
Older
flutterBaseApp / lib / ui / pages / demo / tabPage / dynamic_tab_page copy.dart
StephanieGitHub on 9 Feb 2021 2 KB first commit
import 'package:base_app/res/index.dart';
import 'package:fluintl/fluintl.dart';
import 'package:flutter/material.dart';

class DynamicTabPage extends StatefulWidget {
  const DynamicTabPage({Key key, this.labelId, this.title, this.titleId})
      : super(key: key);

  final String labelId;
  final String title;
  final String titleId;

  @override
  State<StatefulWidget> createState() {
    return new DynamicTabPageState();
  }
}

class DynamicTabPageState extends State<DynamicTabPage> {
  // List<BlocProvider<ComListBloc>> _children = new List();

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // 定义tab文字
    List<Tab> _tabs = [
      Tab(text: "选项卡1"),
      Tab(text: "选项卡2"),
      Tab(text: "选项卡3"),
    ];
    // 子页面
    List<Widget> _children = [
      new Text("tab1"),
      new Text("tab2"),
      new Text("tab3")
    ];
    return new Scaffold(
      appBar: new AppBar(
        elevation: 0.0, //控件的zindex, 可以隐藏阴影
        title: new Text(
            widget.title ?? IntlUtil.getString(context, widget.titleId)),
        centerTitle: true, // 标题居中
      ),
      body: new DefaultTabController(
          length: 3,
          child: new Column(children: <Widget>[
            new Material(
              color: Theme.of(context).primaryColor,
              //elevation: 4.0,
              child: new SizedBox(
                height: 48.0,
                width: double.infinity,
                child: new TabBar(
                  // isScrollable: true, // 是否滚动
                  indicatorWeight: 4, // 标签高度
                  indicatorSize:
                      TabBarIndicatorSize.tab, // 标签长度,等宽用tab, 实际用label
                  indicatorColor: Colours.blue_light, // 选中时标签下方的颜色
                  tabs: _tabs,
                ),
              ),
            ),
            new Expanded(child: new TabBarView(children: _children))
          ])),
    );
  }

  @override
  void dispose() {
    // for (int i = 0, length = _children.length; i < length; i++) {
    //   _children[i].bloc.dispose();
    // }
    super.dispose();
  }
}