zoukankan      html  css  js  c++  java
  • Flutter 使用Tabbar不要Title

    Demo 1

    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          theme: ThemeData(
            primaryColor: Colors.blue,
            accentColor: Colors.pink,
          ),
          home: HomePage(),
        );
      }
    }
    
    class HomePage extends StatefulWidget {
      @override
      _HomePageState createState() => _HomePageState();
    }
    
    class _HomePageState extends State<HomePage> {
      final tabs = ["One", "Two", "Three"];
    
      @override
      Widget build(BuildContext context) {
        return DefaultTabController(
          length: tabs.length,
          child: Scaffold(
            appBar: PreferredSize(
              preferredSize: Size.fromHeight(kToolbarHeight),
              child: Container(
                color: Theme.of(context).primaryColor,
                child: SafeArea(
                  child: Column(
                    children: <Widget>[
                      Expanded(child: SizedBox()),
                      getTabBar(),
                    ],
                  ),
                ),
              ),
            ),
            body: getTabBarPages(),
          ),
        );
      }
    
      Widget getTabBar() {
        return TabBar(
          indicatorColor: Theme.of(context).accentColor,
          tabs: tabs.map((t) {
            return Tab(
              child: Text(t),
            );
          }).toList(),
        );
      }
    
      Widget getTabBarPages() {
        return TabBarView(
          children: tabs.map((t) {
            return Center(
              child: Text(t),
            );
          }).toList(),
        );
      }
    }
    

    Demo 2

    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          theme: ThemeData(
            primaryColor: Colors.blue,
            accentColor: Colors.pink,
          ),
          home: HomePage(),
        );
      }
    }
    
    class HomePage extends StatefulWidget {
      @override
      _HomePageState createState() => _HomePageState();
    }
    
    class _HomePageState extends State<HomePage> {
      final tabs = ["One", "Two", "Three"];
    
      @override
      Widget build(BuildContext context) {
        return DefaultTabController(
          length: tabs.length,
          child: Scaffold(
            appBar: AppBar(
              flexibleSpace: SafeArea(
                child: Column(
                  children: <Widget>[
                    Expanded(child: SizedBox()),
                    getTabBar(),
                  ],
                ),
              ),
            ),
            body: getTabBarPages(),
          ),
        );
      }
    
      Widget getTabBar() {
        return TabBar(
          indicatorColor: Theme.of(context).accentColor,
          tabs: tabs.map((t) {
            return Tab(
              child: Text(t),
            );
          }).toList(),
        );
      }
    
      Widget getTabBarPages() {
        return TabBarView(
          children: tabs.map((t) {
            return Center(
              child: Text(t),
            );
          }).toList(),
        );
      }
    }
    
  • 相关阅读:
    第11组(73) 需求分析报告
    第11组(73)团队展示
    结对编程作业
    第02组 Alpha冲刺 总结
    第02组 Alpha冲刺 (6/6)
    第02组 Alpha冲刺 (5/6)
    第02组 Alpha冲刺 (4/6)
    第02组 Alpha冲刺 (3/6)
    第02组 Alpha冲刺 (2/6)
    第02组 Alpha冲刺 (1/6)
  • 原文地址:https://www.cnblogs.com/ajanuw/p/11378957.html
Copyright © 2011-2022 走看看