flutter tabbar 仅做记录

本文介绍了一个使用Flutter框架创建的TabBar导航栏示例应用。该应用包含一个底部导航栏,具备三个标签页:主页、个人资料和专业版。每个标签页展示了不同的组件,如旋转按钮和中心定位的文本。此示例演示了如何在Flutter中实现常见的底部导航功能。

main.dart 

import 'package:flutter/material.dart';
import 'tabbar.dart';

void main() => runApp(MyApp());


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return  MaterialApp(
      title: 'Navigation',
      initialRoute: '/',
      routes: <String, WidgetBuilder>{
        '/': (BuildContext context) =>  Home(),
//        '/search': (BuildContext context) =>  SearchBarDemo(),
//        '/scrollMap': (BuildContext context) =>  scrollMap(),
      },
    );
  }
}

tabbar.dart

 

import 'package:flutter/material.dart';

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


class _HomeState extends State<Home> {
  int _currentIndex = 0;
  final List<Widget> _children = [
    new HomePage(),
    new Profile(),
    new Profile(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _children[_currentIndex],
      bottomNavigationBar: new BottomNavigationBar(
        onTap: onTabTapped,
        currentIndex: _currentIndex,
        items: [
          new BottomNavigationBarItem(
            icon: new Icon(Icons.home),
            title: new Text('Home'),
          ),
          new BottomNavigationBarItem(
            icon: new Icon(Icons.person),
            title: new Text('Profile'),
          ),
          new BottomNavigationBarItem(
            icon: new Icon(Icons.backup),
            title: new Text('pro'),
          ),
        ],
      ),
    );
  }

  void onTabTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Home'),
      ),
      body: new Center(
        child: new Container( // gray box
          child: new Center(
            child:  new Transform(
              child:  new RaisedButton( // red box
                child: new Text(
                  "super man",
                  style: new TextStyle(
                    color: Colors.red,
                    fontSize: 24.0,
                    fontWeight: FontWeight.w900,
                  ),
                  textAlign: TextAlign.center,
                ),
                padding: new EdgeInsets.all(16.0),
                color: Colors.blue,
                onPressed: () {
//                  Navigator.of(context).pushNamed('/scrollMap');
                },
              ),
              alignment: Alignment.center,
              transform: new Matrix4.identity()
                ..rotateZ(15 * 3.1415927 / 180),
            ),
          ),
          width: 320.0,
          height: 240.0,
          color: Colors.grey[300],
        ),
      ),
    );
  }
}

class Profile extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return  Scaffold(
      appBar:  AppBar(
        title:  Text('Profiles'),
      ),
      body:  Center(
        child:  RaisedButton(
          child:  Text('search'),
          onPressed: () {
//            Navigator.of(context).pushNamed('/search');
          },
        ),
      ),
    );
  }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值