flutter - 如何在 flutter 中获得渐变底部导航选项卡?

标签 flutter flutter-layout flutter-bottomnavigation

pub上有一个包 https://pub.dev/packages/gradient_bottom_navigation_bar

但是很久没有更新了。 那么,有没有办法创建自己的带有渐变效果的自定义导航栏?

像这样... enter image description here

最佳答案

Flutter 一切皆有可能,一种选择是在您的 BottomNavigationBar 中使用透明背景并将其放入带有 BoxDecoration 的容器中,尝试下一个:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Text("Hello"),
        ),
        bottomNavigationBar: _createBottomNavigationBar(),
      ),
    );
  }

  Widget _createBottomNavigationBar() {
    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          colors: [Color(0xFF00D0E1), Color(0xFF00B3FA)],
          begin: Alignment.topLeft,
          end: Alignment.topRight,
          stops: [0.0, 0.8],
          tileMode: TileMode.clamp,
        ),
      ),
      child: BottomNavigationBar(
        currentIndex: 0,
        onTap: (index) {},
        showUnselectedLabels: false,
        backgroundColor: Colors.transparent,
        type: BottomNavigationBarType.fixed,
        elevation: 0,
        unselectedItemColor: Colors.white,
        selectedIconTheme: IconThemeData(color: Colors.white),
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            title: Text(
              "Home",
              style: TextStyle(color: Colors.white),
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.business),
            title: Text(
              "Business",
              style: TextStyle(color: Colors.white),
            ),
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.school),
            title: Text(
              "School",
              style: TextStyle(color: Colors.white),
            ),
          ),
        ],
      ),
    );
  }
}

关于flutter - 如何在 flutter 中获得渐变底部导航选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61717440/

相关文章:

firebase - flutter 地实现搜索栏

Flutter - 如何在一行中显示文本和图标?

flutter - 如何使用 'CupertinoFullscreenDialogTransition' ?

flutter - 如何从父小部件检测子部件的焦点

flutter - 当我通过单击脚手架内的平面按钮导航到其他页面时,底部导航栏消失

flutter - Flushbar编译器问题

flutter - 如何禁用行为底部导航栏随键盘弹起而上升

在 FutureBuilder 中使用 Uint8List 的 Flutter 出现错误

android - 我可以在 Flutter 中为 Android 应用程序安装应用程序后更改应用程序图标和名称吗?

flutter - 没有脚手架的 DefaultTabController?