欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Flutter實(shí)現(xiàn)底部導(dǎo)航欄創(chuàng)建詳解

 更新時(shí)間:2022年01月17日 16:45:29   作者:大前端之旅  
ConvexBottomBar是一個(gè)底部導(dǎo)航欄組件,用于展現(xiàn)凸起的TAB效果,支持多種內(nèi)置樣式與動(dòng)畫交互。本文將利用ConvexBottomBar創(chuàng)建漂亮的底部導(dǎo)航欄,感興趣的可以學(xué)習(xí)一下

ConvexBottomBar是一個(gè)底部導(dǎo)航欄組件,用于展現(xiàn)凸起的TAB效果,支持多種內(nèi)置樣式與動(dòng)畫交互。你可以在https://appbar.codemagic.app/上找到在線樣例。

添加依賴項(xiàng)

在你的項(xiàng)目中去 pubspec。添加依賴項(xiàng): 添加https://pub.dev/packages/convex_bottom_bar的最新版本。

運(yùn)行下列代碼,添加依賴

flutter pub add convex_bottom_bar     
environment:
  sdk: '>=2.12.0 <3.0.0'
dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  convex_bottom_bar: ^3.0.0

我們使用convax_bottom_bar 來(lái)創(chuàng)建一個(gè)非常nice的底部導(dǎo)航欄。

如何使用

通常, 「ConvexAppBar」 可以通過(guò)設(shè)置它的 bottomNavigationBar 來(lái)與腳手架一起工作。ConvexAppBar具有兩個(gè)構(gòu)造函數(shù),ConvexAppBar()將使用默認(rèn)樣式來(lái)簡(jiǎn)化選項(xiàng)卡的創(chuàng)建。

import 'package:convex_bottom_bar/convex_bottom_bar.dart';

Scaffold(
  bottomNavigationBar: ConvexAppBar(
    items: [
      TabItem(icon: Icons.home, title: 'Home'),
      TabItem(icon: Icons.map, title: 'Discovery'),
      TabItem(icon: Icons.add, title: 'Add'),
      TabItem(icon: Icons.message, title: 'Message'),
      TabItem(icon: Icons.people, title: 'Profile'),
    ],
    initialActiveIndex: 2,//optional, default as 0
    onTap: (int i) => print('click index=$i'),
  )
);

功能

  • 提供多種內(nèi)部樣式
  • 能夠更改AppBar的主題
  • 提供Builder API以自定義新樣式
  • 在AppBar上添加徽章
  • 支持優(yōu)雅的過(guò)渡動(dòng)畫
  • 提供Hook API來(lái)重載一些內(nèi)部樣式
  • RTL布局支持

關(guān)于支持的樣式,可以從這兒查看

https://pub.flutter-io.cn/packages/convex_bottom_bar

屬性

下面是 「*Convex_Bottom_Bar*」 的一些屬性:

  • 「fixed」 (副標(biāo)題圖標(biāo)停留在中心)
  • 「fixedCircle」 (相同,但在固定圖標(biāo)的所有邊上都有一個(gè)白色的圓圈)
  • 「react」 (上標(biāo)圖標(biāo)取代點(diǎn)擊另一個(gè)圖標(biāo))
  • 「reactCircle」 (與上標(biāo)圖標(biāo)中的白色圓圈相同)
  • 「textIn」 (選定的離子出現(xiàn)相應(yīng)的標(biāo)題)
  • 「titled」 (未選擇的圖標(biāo)是顯示其標(biāo)題的單個(gè)圖標(biāo))
  • 「flip」 (點(diǎn)擊圖標(biāo)顯示一個(gè) flip 動(dòng)畫)
  • 「custom」 (使用 ConvexBottomAppBar 構(gòu)建器自定義預(yù)定義的參數(shù))
  • 「height」 (grabbing the appbar)
  • 「top」 (grabbing the superscripted icon)
  • 「curveSize」 (拉伸上標(biāo)圖標(biāo)的曲線)
  • 「color」 (設(shè)置圖標(biāo)的顏色)
  • 「backgroundColor」 (設(shè)置 appbar 背景顏色)
  • 「gradient」 (使用漸變小部件設(shè)置 appbar 背景顏色)
  • 「activeColor」 (設(shè)置圓形顏色)

主題

AppBar默認(rèn)使用內(nèi)置樣式,您可能需要為其設(shè)置主題。 以下是一些支持的屬性:

AttributesDescription
backgroundColorAppBar 背景
gradient漸變屬性,可以覆蓋backgroundColor
heightAppBar 高度
coloricon/text 的顏色值
activeColoricon/text 的選中態(tài)顏色值
curveSize凸形大小
top凸形到AppBar上邊緣的距離
style支持的樣式: fixed, fixedCircle, react, reactCircle, ...
chipBuilder角標(biāo)構(gòu)造器builder, ConvexAppBar.badge會(huì)使用默認(rèn)樣式

預(yù)覽圖

代碼

Convex_Bottom_Bar 演示中,首先,我們?cè)谶@個(gè)類中創(chuàng)建一個(gè)名為 MyHomePage ()的有狀態(tài)類,我們創(chuàng)建一個(gè)值為 0 的變量 selectedpage 類型的 integer pass。定義一個(gè)名為 pageList的列表,在這個(gè)列表中我們傳遞要添加到 bootom 導(dǎo)航欄中的所有頁(yè)面。

  int selectedpage = 0;
  final _pageList= [Home(), Message(), Persion(), Detail()];

在 BuildContext ()中,我們定義 Scaffold。

appBar: AppBar(
  centerTitle: true,
  title: Text('Convex Bottom Bar'),
),

首先在正文中傳遞 _pageno,其值為 selectedPage。使用 scaffold 屬性,我們使用 bottomNavigationBar。在這里,我們創(chuàng)建 ConvexAppBar ()并傳遞 Items、 initialActiveIndex 和 onTap。在條目中,我們通過(guò)所有的屏幕,我們希望在我們的應(yīng)用程序中顯示。在 initialActiveIndexwe 中,我們傳遞已經(jīng)定義的變量 selectedpage,在 onTap 中,我們傳遞 index 并在 setState 中定義 setState () ,我們傳遞 selectedpage 相當(dāng)于 index。

bottomNavigationBar: ConvexAppBar(
  items: [
    TabItem(icon: Icons._home_, title: 'Home'),
    TabItem(icon: Icons._favorite_, title: 'Favorite'),
    TabItem(icon: Icons._shopping_cart_, title: 'Cart'),
    TabItem(icon: Icons._person_, title: 'Profile'),
  ],
  initialActiveIndex: selectedpage,
  onTap: (int index){
      setState(() {
        selectedpage = index;
      });
  },
),

main.dart

import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter/material.dart';
import 'detail.dart';
import 'home.dart';
import 'message.dart';
import 'persion.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.teal,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int selectedpage = 0;
  final _pageNo = [Home(), Message(), Persion(), Detail()];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('Convex Bottom Bar'),
      ),
      body: _pageNo[selectedpage],
      bottomNavigationBar: ConvexAppBar(
           color: Colors.white,
        activeColor: Colors.red,
        backgroundColor: Colors.orange,
        items: [
          TabItem(icon: Icons.person, title: '新'),
          TabItem(icon: Icons.favorite, title: '年'),
          TabItem(icon: Icons.brush, title: '快'),
          TabItem(icon: Icons.car_rental, title: '樂(lè)'),
        ],
        initialActiveIndex: selectedpage,
        onTap: (int index) {
          setState(() {
            selectedpage = index;
          });
        },
      ),
    );
  }
}

如果我們創(chuàng)建不同的頁(yè)面, Home(), Favorite(), CartPage(), ProfilePage(). 在 Home 類中,我們定義一個(gè)帶有背景顏色的文本。

Home 頁(yè)

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

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

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('歡迎來(lái)到這兒'),
      ),
      body: Center(
        child: Text(
          '早起的年輕人',
          style: TextStyle(fontSize: 60, fontWeight: FontWeight.bold),
        ),
      ),
    );
  }
}

Message頁(yè):

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

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

  @override
  _MessageState createState() => _MessageState();
}

class _MessageState extends State<Message> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('這是當(dāng)前頁(yè)的AppBar'),
      ),
      body: Center(
        child: Text(
          '因?yàn)橛埠?,所以?jiān)果!',
          style: TextStyle(fontSize: 60, fontWeight: FontWeight.bold),
        ),
      ),
    );
  }
}

Persion頁(yè)

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

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

  @override
  _PersionState createState() => _PersionState();
}

class _PersionState extends State<Persion> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(  appBar: AppBar(
        centerTitle: true,
        title: Text('公眾號(hào)'),
      ),
      body: Center(
        child: Text(
          '大前端之旅',
          style: TextStyle(fontSize: 60, fontWeight: FontWeight.bold),
        ),
      ),
    );
  }
}

Detail頁(yè)面

// ignore: file_names
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

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

  @override
  _DetailState createState() => _DetailState();
}

class _DetailState extends State<Detail> {
  String image =
      "https://luckly007.oss-cn-beijing.aliyuncs.com/image/image-20220114111115931.png";
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('掃碼關(guān)注'),
      ),
      body: Center(
        child: new Image(image: new NetworkImage(image)),
      ),
    );
  }
}

當(dāng)我們運(yùn)行應(yīng)用程序,我們應(yīng)該得到屏幕的輸出像下面的報(bào)錯(cuò)信息。

這是一個(gè)

Flutter web問(wèn)題:Failed to load network image

我的解決辦法

flutter build web --release --web-renderer html

flutter run --web-renderer html

flutter run -d chrome --web-renderer html

參考資料

https://pub.flutter-io.cn/packages/convex_bottom_bar

https://github.com/hacktons/convex_bottom_bar

以上就是Flutter實(shí)現(xiàn)底部導(dǎo)航欄創(chuàng)建詳解的詳細(xì)內(nèi)容,更多關(guān)于Flutter底部導(dǎo)航欄創(chuàng)建的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Android異步更新UI的四種方式

    Android異步更新UI的四種方式

    這篇文章主要為大家詳細(xì)介紹了Android異步更新UI的四種方式,感興趣的小伙伴們可以參考一下
    2016-05-05
  • 朋友圈實(shí)現(xiàn)圖片+文字轉(zhuǎn)發(fā)功能(必看篇)

    朋友圈實(shí)現(xiàn)圖片+文字轉(zhuǎn)發(fā)功能(必看篇)

    下面小編就為大家?guī)?lái)一篇朋友圈實(shí)現(xiàn)圖片+文字轉(zhuǎn)發(fā)功能(必看篇)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • Android自定義View實(shí)現(xiàn)QQ音樂(lè)中圓形旋轉(zhuǎn)碟子

    Android自定義View實(shí)現(xiàn)QQ音樂(lè)中圓形旋轉(zhuǎn)碟子

    這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)QQ音樂(lè)中圓形旋轉(zhuǎn)碟子,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • Android Studio 一鍵生成Json實(shí)體類教程

    Android Studio 一鍵生成Json實(shí)體類教程

    這篇文章主要介紹了Android Studio 一鍵生成Json實(shí)體類教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-04-04
  • 微信Android熱更新Tinker使用詳解(星空武哥)

    微信Android熱更新Tinker使用詳解(星空武哥)

    Tinker是微信官方的Android熱補(bǔ)丁解決方案,它支持動(dòng)態(tài)下發(fā)代碼、So庫(kù)以及資源,讓應(yīng)用能夠在不需要重新安裝的情況下實(shí)現(xiàn)更新。當(dāng)然,你也可以使用Tinker來(lái)更新你的插件
    2017-09-09
  • Json數(shù)據(jù)解析模擬美團(tuán)界面顯示

    Json數(shù)據(jù)解析模擬美團(tuán)界面顯示

    這篇文章主要介紹了Json數(shù)據(jù)解析模擬美團(tuán)界面顯示,涉及到j(luò)son數(shù)據(jù)解析相關(guān)知識(shí),本文寫的非常不錯(cuò),具有參考價(jià)值,特此分享供大家學(xué)習(xí)
    2016-01-01
  • 輕松實(shí)現(xiàn)Android鎖屏功能

    輕松實(shí)現(xiàn)Android鎖屏功能

    這篇文章主要幫助大家輕松實(shí)現(xiàn)Android鎖屏功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Flutter 控制屏幕旋轉(zhuǎn)的實(shí)現(xiàn)

    Flutter 控制屏幕旋轉(zhuǎn)的實(shí)現(xiàn)

    這篇文章主要介紹了Flutter 控制屏幕旋轉(zhuǎn)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • Android bindservice失敗解決方法

    Android bindservice失敗解決方法

    這篇文章主要介紹了Android bindservice失敗解決方法的相關(guān)資料,希望通過(guò)本文能幫助大家解決這樣的問(wèn)題,需要的朋友可以參考下
    2017-08-08
  • Android加載View中Background詳解

    Android加載View中Background詳解

    本文講解的是Android什么時(shí)候進(jìn)行View中Background的加載,十分的詳盡,十分全面細(xì)致,附上所有代碼,這里推薦給大家,希望大家能夠喜歡。
    2015-03-03

最新評(píng)論