flutter——首页顶部的自定义导航栏

需求:首页,两个标签之间的切换以及下面内容对应的改变。以及首页的自定义导航栏。

import 'package:flutter/material.dart';

class GFIndexPage extends StatefulWidget {
  const GFIndexPage({Key? key}) : super(key: key);

  
  State<GFIndexPage> createState() => _GFIndexPageState();
}

class _GFIndexPageState extends State<GFIndexPage> {
  
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        backgroundColor: const Color(0xff1a1a1a),
        appBar: AppBar(
          backgroundColor: Colors.transparent,
          elevation: 0,
          leading: Padding(
            padding: const EdgeInsets.all(10),
            child: Transform.translate(
              offset: const Offset(50.0,0.0),
              child: Transform.scale(
                scale: 3.0,
                child: Image.asset("images/index/GetFun.png"),
              ),
            ),
          ),
          actions: [
            IconButton(
              icon: Image.asset("images/index/notification.png",width: 25,),
              onPressed: () {
              },
            ),
          ],
          // 标签的切换
          bottom: const TabBar(
            // 去掉长的下划线
            //dividerHeight: 0,
            // 指示器的大小
            indicatorSize: TabBarIndicatorSize.tab,
            isScrollable: true,
            unselectedLabelColor: Colors.white,
            dividerColor: Color(0xff737373),
            tabAlignment: TabAlignment.start,
            tabs: [
              Tab(child: Text("推荐",style: TextStyle(fontSize: 16.0),),),
              Tab(child: Text("发现",style: TextStyle(fontSize: 16.0),),),
            ],
          ),
        ),
        body: TabBarView(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Image.asset("images/index/recommendHeader.png"),
              ],
            ),
            const Center(
              child: Text("先不做,以后拿来扩展社交"),
            ),
          ],
        ),
      ),
    );
  }
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flutter中设置顶部导航栏可以使用AppBar组件。AppBar组件是Material Design中的一个标准组件,通常用于顶部导航栏或者应用栏。 以下是如何在Flutter中设置顶部导航栏的步骤: 1. 导入Material库:在Flutter中使用AppBar组件需要导入Material库,可以在文件开头添加以下代码: ``` import 'package:flutter/material.dart'; ``` 2. 创建AppBar:使用AppBar组件来创建顶部导航栏,可以在Scaffold组件中添加AppBar,如下所示: ``` Scaffold( appBar: AppBar( title: Text("My App"), ), body: Container(), ); ``` 在这个例子中,我们创建了一个标题为“My App”的AppBar。 3. 自定义AppBar:AppBar组件支持许多自定义属性,比如颜色、图标、菜单等。下面是一些常用的自定义属性: - backgroundColor:设置导航栏背景颜色 - actions:设置导航栏右侧的操作按钮 - leading:设置导航栏左侧的返回按钮 - elevation:设置导航栏的阴影大小 - title:设置导航栏标题 以下是一个自定义AppBar的例子: ``` Scaffold( appBar: AppBar( title: Text("My App"), backgroundColor: Colors.blue, actions: [ IconButton( icon: Icon(Icons.search), onPressed: (){}, ), IconButton( icon: Icon(Icons.more_vert), onPressed: (){}, ), ], leading: IconButton( icon: Icon(Icons.menu), onPressed: (){}, ), elevation: 4.0, ), body: Container(), ); ``` 在这个例子中,我们设置了导航栏的背景颜色为蓝色,右侧添加了两个操作按钮,左侧添加了一个菜单按钮,并且设置了导航栏的阴影大小为4.0。 通过以上步骤,你已经成功设置了顶部导航栏

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值