zoukankan      html  css  js  c++  java
  • Flutter 原生TabBar切换标签页示例

    效果图:

    代码如下:

    import 'package:flutter/material.dart';
    
    class TabsTestPage extends StatefulWidget {
      _TabsTestPageState createState() => _TabsTestPageState();
    }
    
    class _TabsTestPageState extends State<TabsTestPage> {
      @override
      Widget build(BuildContext context) {
        return Container(
          height: 500.0,
          child: MyTabbedPage(),
        );
      }
    }
    
    class MyTabbedPage extends StatefulWidget {
      _MyTabbedPageState createState() => _MyTabbedPageState();
    }
    
    class _MyTabbedPageState extends State<MyTabbedPage> with SingleTickerProviderStateMixin {
      final List<Tab> myTabs = <Tab>[
        Tab(text: 'LEFT'),
        Tab(text: 'RIGHT'),
      ];
    
      TabController _tabController;
    
      @override
      void initState() {
        super.initState();
        _tabController = TabController(vsync: this, length: myTabs.length);
      }
    
     @override
     void dispose() {
       _tabController.dispose();
       super.dispose();
     }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Tabs'),
            bottom: TabBar(
              controller: _tabController,
              tabs: myTabs,
            ),
          ),
          body: TabBarView(
            controller: _tabController,
            children: myTabs.map((Tab tab) {
              return Center(child: Text(tab.text));
            }).toList(),
          ),
        );
      }
    }
  • 相关阅读:
    Cheatsheet: 2011 03.19 ~ 03.31
    Cheatsheet: 2011 03.07 ~ 03.14
    Cheatsheet: 2011 04.01 ~ 04.10
    Cheatsheet: 2011 04.20 ~ 04.29
    Java动手动脑02
    Java日报10.5
    java四则运算第三阶段
    验证码界面——Java图形界面
    Java四则运算V3.0
    Java日报10.8
  • 原文地址:https://www.cnblogs.com/joe235/p/11692868.html
Copyright © 2011-2022 走看看