Flutter底部模糊栏插件bottom_blur_bar的使用
Flutter底部模糊栏插件bottom_blur_bar的使用
预览
基本用法
首先,在你的项目文件中导入该插件:
import 'package:bottom_blur_bar/bottom_blur_bar.dart';
然后,像这样在你的应用中添加底部模糊栏:
bottomNavigationBar: BlurNavbar(
onTap: (idx) => setState(() {
_idx = idx;
debugPrint('$idx');
}),
items: [
BlurNavbarItem(icon: Icon(Icons.home, color: color, size: 24), title: "SEARCH"),
BlurNavbarItem(icon: Icon(Icons.search, color: color, size: 24), title: "SEARCH"),
BlurNavbarItem(icon: Icon(Icons.notifications, color: color, size: 24), title: "NOTIFICATIONS"),
BlurNavbarItem(icon: Icon(Icons.local_library_rounded, color: color, size: 24), title: "LIBRARY")
],
currentIndex: _idx,
selectedColor: Colors.cyanAccent,
)
必需参数
参数 | 描述 |
---|---|
onTap | 点击事件 |
items | 显示的子控件集合 |
可选参数
参数 | 默认值 | 描述 |
---|---|---|
style | auto | 模糊效果样式 |
selectedColor | – | 选中项的颜色 |
borderRadius | 24 | 边框圆角半径 |
currentIndex | 0 | 选中项的索引 |
fontSize | 10 | 字体大小 |
iconSize | 40 | 图标大小 |
许可证
bottom_blur_bar
是 MIT-licensed。
完整示例
以下是一个完整的示例代码,展示了如何在Flutter应用中使用bottom_blur_bar
插件:
import 'package:flutter/material.dart';
import 'package:bottom_blur_bar/bottom_blur_bar.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: Theme.of(context).textTheme.apply(
bodyColor: Colors.white,
displayColor: Colors.white,
),
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _idx = 0;
@override
Widget build(BuildContext context) {
final color = MediaQuery.of(context).platformBrightness == Brightness.dark
? Colors.white
: Colors.black87;
return Scaffold(
backgroundColor: Colors.white,
extendBody: true,
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.transparent,
title: const Text("Blur Bottom Bar", style: TextStyle(color: Colors.black87)),
),
body: ListView.builder(
itemCount: 200,
itemBuilder: (ctx, idx) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.deepPurple, Colors.pink.shade300])),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'当前索引:',
),
Text(
'$_idx',
style: Theme.of(context).textTheme.headlineLarge,
),
],
),
),
),
);
}),
bottomNavigationBar: BlurNavbar(
onTap: (idx) => setState(() {
_idx = idx;
debugPrint('$idx');
}),
items: [
BlurNavbarItem(icon: Icon(Icons.home, color: color, size: 24), title: "SEARCH"),
BlurNavbarItem(icon: Icon(Icons.search, color: color, size: 24), title: "SEARCH"),
BlurNavbarItem(icon: Icon(Icons.notifications, color: color, size: 24), title: "NOTIFICATIONS"),
BlurNavbarItem(icon: Icon(Icons.local_library_rounded, color: color, size: 24), title: "LIBRARY")
],
currentIndex: _idx,
selectedColor: Colors.cyanAccent,
),
);
}
}
更多关于Flutter底部模糊栏插件bottom_blur_bar的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复
更多关于Flutter底部模糊栏插件bottom_blur_bar的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
bottom_blur_bar
是一个 Flutter 插件,用于在应用的底部添加一个带有模糊效果的导航栏。它可以用来增强应用的美观性,特别是在需要展示半透明或模糊背景的场景中。
安装
首先,你需要在 pubspec.yaml
文件中添加 bottom_blur_bar
依赖:
dependencies:
flutter:
sdk: flutter
bottom_blur_bar: ^1.0.0 # 请使用最新版本
然后运行 flutter pub get
来安装依赖。
基本用法
以下是一个简单的示例,展示如何使用 bottom_blur_bar
插件:
import 'package:flutter/material.dart';
import 'package:bottom_blur_bar/bottom_blur_bar.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Text('Hello, World!'),
),
bottomNavigationBar: BottomBlurBar(
blurStrength: 5.0, // 模糊强度
color: Colors.white.withOpacity(0.5), // 背景颜色
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
icon: Icon(Icons.home),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.person),
onPressed: () {},
),
],
),
),
),
);
}
}