Flutter底部导航栏动画插件kbspinningbottombar的使用
Flutter底部导航栏动画插件kbspinningbottombar的使用
KB Spinning Bottom Bar
一个用于Flutter应用程序的简单实现旋转圆形底部导航栏的插件。
当前特性
- 初始发布旋转圆形底部导航栏
- 可自定义活动和非活动状态下的标签图标和文本
- 可自定义旋转圆的颜色
- 可自定义底部栏和旋转圆的项目数量
演示
使用方法
要使用该插件,只需将SpinCircleBottomBarHolder
添加到Scaffold的body中,如下所示:
import 'package:flutter/material.dart';
import 'package:kbspinningbottombar/kbspinningbottombar.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: '旋转圆形底部导航栏',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text("RetroPortal Studio"),
backgroundColor: Colors.deepOrangeAccent,
),
// 添加旋转圆形底部导航栏到Scaffold的body中
body: SpinCircleBottomBarHolder(
bottomNavigationBar: SCBottomBarDetails(
circleColors: [Colors.white, Colors.orange, Colors.redAccent], // 旋转圆的颜色数组
iconTheme: IconThemeData(color: Colors.black45), // 非活动状态下图标的颜色
activeIconTheme: IconThemeData(color: Colors.orange), // 活动状态下图标的颜色
backgroundColor: Colors.white, // 底部栏背景颜色
titleStyle: TextStyle(color: Colors.black45, fontSize: 12), // 非活动状态下标题的样式
activeTitleStyle: TextStyle(
color: Colors.black,
fontSize: 12,
fontWeight: FontWeight.bold), // 活动状态下标题的样式
actionButtonDetails: SCActionButtonDetails(
activeWidget: Icon(Icons.expand_less_outlined, color: Colors.white), // 激活按钮的图标
closeWidget: Icon(Icons.close, color: Colors.white), // 关闭按钮的图标
actionButtonText: "Royalty" // 按钮上的文本
),
shadow: [], // 阴影设置
elevation: 2.0, // 高度
items: [
// 建议的数量为4
SCBottomBarItem(
icon: Icons.verified_user, title: "用户", onPressed: () {}), // 第一个选项
SCBottomBarItem(
icon: Icons.supervised_user_circle,
title: "详情",
onPressed: () {}), // 第二个选项
SCBottomBarItem(
icon: Icons.notifications,
title: "通知",
onPressed: () {}), // 第三个选项
SCBottomBarItem(
icon: Icons.details, title: "新数据", onPressed: () {}), // 第四个选项
],
circleItems: [
// 建议的数量为3
SCItem(icon: Icon(Icons.add), onPressed: () {}), // 第一个旋转圆选项
SCItem(icon: Icon(Icons.print), onPressed: () {}), // 第二个旋转圆选项
SCItem(icon: Icon(Icons.map), onPressed: () {}), // 第三个旋转圆选项
],
bnbHeight: 80 // 建议的高度为80
),
child: Container(
color: Colors.orangeAccent.withAlpha(55),
child: Center(
child: Text("这不是很棒吗!"),
),
),
),
),
);
}
}
更多关于Flutter底部导航栏动画插件kbspinningbottombar的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter底部导航栏动画插件kbspinningbottombar的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
kbspinningbottombar
是一个 Flutter 插件,用于创建带有旋转动画效果的底部导航栏。它提供了一种独特的方式来增强用户体验,使底部导航栏更具交互性和视觉吸引力。以下是关于如何使用 kbspinningbottombar
插件的详细步骤。
1. 添加依赖
首先,你需要在 pubspec.yaml
文件中添加 kbspinningbottombar
插件的依赖。
dependencies:
flutter:
sdk: flutter
kbspinningbottombar: ^1.0.0 # 请根据最新版本号进行替换
然后运行 flutter pub get
来获取依赖。
2. 导入插件
在你的 Dart 文件中导入 kbspinningbottombar
插件。
import 'package:kbspinningbottombar/kbspinningbottombar.dart';
3. 使用 KbSpinningBottomBar
KbSpinningBottomBar
是插件中的主要组件,你可以通过配置它的参数来定制底部导航栏的外观和行为。
以下是一个简单的示例,展示如何使用 KbSpinningBottomBar
:
import 'package:flutter/material.dart';
import 'package:kbspinningbottombar/kbspinningbottombar.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: KbSpinningBottomBarExample(),
);
}
}
class KbSpinningBottomBarExample extends StatefulWidget {
@override
_KbSpinningBottomBarExampleState createState() =>
_KbSpinningBottomBarExampleState();
}
class _KbSpinningBottomBarExampleState extends State<KbSpinningBottomBarExample> {
int _selectedIndex = 0;
final List<Widget> _pages = [
Center(child: Text('Home Page')),
Center(child: Text('Search Page')),
Center(child: Text('Profile Page')),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: _pages[_selectedIndex],
bottomNavigationBar: KbSpinningBottomBar(
selectedIndex: _selectedIndex,
onItemSelected: (index) {
setState(() {
_selectedIndex = index;
});
},
items: [
KbSpinningBottomBarItem(icon: Icons.home, label: 'Home'),
KbSpinningBottomBarItem(icon: Icons.search, label: 'Search'),
KbSpinningBottomBarItem(icon: Icons.person, label: 'Profile'),
],
),
);
}
}
4. 参数说明
KbSpinningBottomBar
的主要参数包括:
selectedIndex
: 当前选中的索引。onItemSelected
: 当用户选择一个项目时触发的回调函数。items
: 底部导航栏的项目列表,每个项目都是一个KbSpinningBottomBarItem
对象。iconSize
: 图标的大小。activeColor
: 选中项目的颜色。inactiveColor
: 未选中项目的颜色。duration
: 旋转动画的持续时间。curve
: 旋转动画的曲线。
5. 自定义外观
你可以通过调整 KbSpinningBottomBar
的参数来自定义底部导航栏的外观。例如,更改图标大小、颜色、动画持续时间等。
KbSpinningBottomBar(
selectedIndex: _selectedIndex,
onItemSelected: (index) {
setState(() {
_selectedIndex = index;
});
},
items: [
KbSpinningBottomBarItem(icon: Icons.home, label: 'Home'),
KbSpinningBottomBarItem(icon: Icons.search, label: 'Search'),
KbSpinningBottomBarItem(icon: Icons.person, label: 'Profile'),
],
iconSize: 30.0,
activeColor: Colors.blue,
inactiveColor: Colors.grey,
duration: Duration(milliseconds: 300),
curve: Curves.easeInOut,
)