如何在Flutter中创建此下拉设计的选项卡栏?

huangapple go评论78阅读模式
英文:

How to make this drop design tab bar in flutter?

问题

如何在Flutter中创建这种类型的选项卡栏?

英文:

如何在Flutter中创建此下拉设计的选项卡栏?

How can i make this kind of tab bar in flutter

答案1

得分: 2

你可以使用这个包:curved_navigation_bar

CurvedNavigationBar(
backgroundColor: Colors.blueAccent,
items: [
Icon(Icons.add, size: 30),
Icon(Icons.list, size: 30),
Icon(Icons.compare_arrows, size: 30),
],
onTap: (index) {
// 处理按钮点击事件
},
)

英文:

You can use this package: curved_navigation_bar

CurvedNavigationBar(
    backgroundColor: Colors.blueAccent,
    items: <Widget>[
      Icon(Icons.add, size: 30),
      Icon(Icons.list, size: 30),
      Icon(Icons.compare_arrows, size: 30),
    ],
    onTap: (index) {
      //Handle button tap
    },
  )

答案2

得分: 2

> 您可以尝试这些依赖项:stylish_bottom_bar: ^1.0.3

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:stylish_bottom_bar/model/bar_items.dart';
import 'package:stylish_bottom_bar/stylish_bottom_bar.dart';

class TabbarScreen extends StatefulWidget {
  const TabbarScreen({super.key});

  @override
  State<TabbarScreen> createState() => _TabbarScreenState();
}

class _TabbarScreenState extends State<TabbarScreen> {
  dynamic selected;
  var heart = false;
  PageController controller = PageController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar: StylishBottomBar(
        option: AnimatedBarOptions(
          barAnimation: BarAnimation.fade,
          iconStyle: IconStyle.animated,
        ),
        items: [
          BottomBarItem(
            icon: const Icon(
              Icons.chat_bubble_outline,
            ),
            selectedIcon: const Icon(Icons.chat),
            selectedColor: Colors.teal,
            backgroundColor: Colors.teal,
            title: const Text('Chat'),
          ),
          BottomBarItem(
            icon: const Icon(Icons.list),
            selectedIcon: const Icon(Icons.list),
            selectedColor: Colors.red,
            title: const Text('List'),
          ),
          BottomBarItem(
            icon: const Icon(
              Icons.person_outline,
            ),
            selectedIcon: const Icon(
              Icons.person,
            ),
            backgroundColor: Colors.purpleAccent,
            selectedColor: Colors.deepPurple,
            title: const Text('Profile'),
          ),
        ],
        hasNotch: true,
        fabLocation: StylishBarFabLocation.end,
        currentIndex: selected ?? 0,
        onTap: (index) {
          controller.jumpToPage(index);
          setState(() {
            selected = index;
          });
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            heart = !heart;
          });
        },
        backgroundColor: Colors.white,
        child: Icon(
          heart ? CupertinoIcons.add_circled_solid : CupertinoIcons.add,
          color: Colors.red,
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
      body: SafeArea(
        child: PageView(
          controller: controller,
          children: const [
            Center(child: Text('Chat')),
            Center(child: Text('List')),
            Center(child: Text('Profile')),
          ],
        ),
      ),
    );
  }
}
英文:

> U can try this Dependencies: stylish_bottom_bar: ^1.0.3

import &#39;package:flutter/cupertino.dart&#39;;
import &#39;package:flutter/material.dart&#39;;
import &#39;package:stylish_bottom_bar/model/bar_items.dart&#39;;
import &#39;package:stylish_bottom_bar/stylish_bottom_bar.dart&#39;;
class TabbarScreen extends StatefulWidget {
const TabbarScreen({super.key});
@override
State&lt;TabbarScreen&gt; createState() =&gt; _TabbarScreenState();
}
class _TabbarScreenState extends State&lt;TabbarScreen&gt; {
dynamic selected;
var heart = false;
PageController controller = PageController();
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: StylishBottomBar(
option: AnimatedBarOptions(
barAnimation: BarAnimation.fade,
iconStyle: IconStyle.animated,
),
items: [
BottomBarItem(
icon: const Icon(
Icons.chat_bubble_outline,
),
selectedIcon: const Icon(Icons.chat),
selectedColor: Colors.teal,
backgroundColor: Colors.teal,
title: const Text(&#39;Chat&#39;),
),
BottomBarItem(
icon: const Icon(Icons.list),
selectedIcon: const Icon(Icons.list),
selectedColor: Colors.red,
title: const Text(&#39;List&#39;),
),
BottomBarItem(
icon: const Icon(
Icons.person_outline,
),
selectedIcon: const Icon(
Icons.person,
),
backgroundColor: Colors.purpleAccent,
selectedColor: Colors.deepPurple,
title: const Text(&#39;Profile&#39;)),
],
hasNotch: true,
fabLocation: StylishBarFabLocation.end,
currentIndex: selected ?? 0,
onTap: (index) {
controller.jumpToPage(index);
setState(() {
selected = index;
});
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
heart = !heart;
});
},
backgroundColor: Colors.white,
child: Icon(
heart ? CupertinoIcons.add_circled_solid : CupertinoIcons.add,
color: Colors.red,
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
body: SafeArea(
child: PageView(
controller: controller,
children: const [
Center(child: Text(&#39;Chat&#39;)),
Center(child: Text(&#39;List&#39;)),
Center(child: Text(&#39;Profile&#39;)),
],
),
),
);
}
}

huangapple
  • 本文由 发表于 2023年7月20日 18:56:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76729157.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定