簡體   English   中英

如何在 flutter 中獲取漸變底部導航選項卡?

[英]How to get gradient bottom navigation tab in flutter?

pub https://pub.dev/packages/gradient_bottom_navigation_bar 上有一個 package

但是這個已經很久沒有更新了。 那么,有沒有辦法創建自己的具有漸變效果的自定義導航欄?

像這樣的…… 在此處輸入圖像描述

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),
            ),
          ),
        ],
      ),
    );
  }
}

我有一個更基本的解決方案。 你可以檢查這個 DartPad

最終結果:

顫振中的漸變底部導航欄

訣竅是這樣的:

  • BottomNavigationBar的背景顏色設置為透明。
  • Stack包裹它。
  • 添加一個Container作為第一個孩子到Stack
  • Container的裝飾設置為漸變。
  • 將其高度設置為 60。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM