Essential_Widgets
此软件包是小部件的集合,在标准 Flutter 小部件不足或需要功能更具体的小部件时可能有用。
使用示例
浮动抽屉
import 'package:essential_widgets/widgets/floatingDrawer.dart';
import 'package:flutter/material.dart';
class FloatingDrawerPage extends StatelessWidget {
final List items = [
DrawerTile(
child: Text("Status: Online"),
leading: Icon(Icons.cloud),
trailing: Icon(
Icons.brightness_1,
color: Colors.green,
size: 10,
),
),
DrawerTile(
child: Text("Games"),
leading: Icon(Icons.gamepad),
trailing: Icon(Icons.chevron_right),
children: List.generate(2, (i) => DrawerTile(child: Text("${i + 1}"))),
),
DrawerTile(
child: Text("Friends"),
leading: Icon(Icons.people),
trailing: Icon(Icons.chevron_right),
children: List.generate(5, (i) => DrawerTile(child: Text("${i + 1}"))),
),
DrawerTile(
child: Text("Exit"),
leading: Icon(Icons.exit_to_app),
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
actions: [
PopupMenuButton<String>(
color: Colors.transparent,
elevation: 0,
itemBuilder: (context) => [
PopupMenuItem(
child: Container(
width: 300,
child: FloatingDrawer(
separator: Container(
width: double.infinity,
height: 1,
color: Colors.black12,
),
color: Colors.white,
borderRadius: BorderRadius.circular(15),
tiles: [...items],
),
),
)
],
)
],
),
);
}
}
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| Tiles (必需) | 列表 | 定义抽屉中的行 |
| color | 颜色 | 定义背景颜色 |
| 分隔符 | Widget | 定义分隔符 |
| borderRadius | BorderRadiusGeometry | 定义抽屉的边框半径 |


多功能浮动按钮
import 'package:essential_widgets/widgets/multiFab.dart';
import 'package:flutter/material.dart';
class MultiFabPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text('Hola Mundo'),
),
floatingActionButton: MultiFab(
children: [
...List.generate(
3,
(i) => MultiFabItem(
onPressed: () {},
child: Text("$i"),
))
],
));
}
}
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| unfoldedIcon | Widget | 定义浮动按钮展开时显示的图标 |
| foldedIcon | Widget | 定义浮动按钮折叠时显示的图标 |
| customIcon | Widget | 定义浮动按钮中显示的图标,覆盖折叠和展开的图标 |
| children (必需) | 列表 | 定义浮动按钮展开时显示的小部件 |
| shape | ShapeBorder | 定义浮动按钮的形状 |
| animationDuration | 持续时间 | 定义展开动画的持续时间 |
| tooltip | 字符串 | 定义工具提示字符串 |
| color | 颜色 | 定义浮动按钮的背景颜色 |
| onTap | 功能 | 定义点击浮动按钮时执行的自定义操作 |


阴影
import 'package:essential_widgets/widgets/shadowed.dart';
import 'package:flutter/material.dart';
class ShadowedPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Shadowed(
child: Text(
'Hola Mundo',
style: TextStyle(fontSize: 30),
),
blurLevel: 1.5,
distance: 3,
shadowColor: Colors.black45,
),
),
);
}
}
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| child (必需) | Widget | 定义要添加阴影的小部件 |
| blurLevel | 双精度 | 定义阴影的模糊级别 |
| distance | 双精度 | 定义子元素和阴影之间的距离 |
| shadowColor | 颜色 | 定义阴影的颜色 |
幻灯片
import 'package:essential_widgets/widgets/slideshow.dart';
import 'package:flutter/material.dart';
class SlideshowPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Slideshow(
slides: [
...List.generate(
3,
(i) => Container(
alignment: Alignment.center,
child: Text(
"$i",
style: TextStyle(fontSize: 35, color: Colors.white),
),
decoration: BoxDecoration(
color: Colors.blueGrey[400],
borderRadius: BorderRadius.circular(25)),
),
)
],
),
),
);
}
}
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| Slides (必需) | 列表 | 定义要显示的小部件 |
| dotsOnTop | 布尔值 | 定义点显示在上还是在下 |
| primaryColor | 颜色 | 定义选定幻灯片的点的颜色 |
| secondaryColor | 颜色 | 定义未选定点的颜色 |
| dotsSpace | 双精度 | 定义点之间的间距 |
| shape | 盒子形状 | 定义点的形状 |
| dotsSize | 双精度 | 定义选定幻灯片的点的大小 |
| secondaryDotsSize | 双精度 | 定义未选定点的尺寸 |
| slidesPadding | 双精度 | 定义幻灯片之间的间距 |
| scrollDirection | Axis | 定义幻灯片的滚动方向 |
| showDots | 布尔值 | 定义是否显示点 |

Deployable
import 'package:essential_widgets/widgets/deployable.dart';
import 'package:flutter/material.dart';
class DeployablePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
alignment: Alignment.centerRight,
child: Stack(
alignment: Alignment.centerRight,
children: [
SafeArea(
child: Container(
margin: EdgeInsets.all(10),
padding: EdgeInsets.all(10),
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.blueGrey[100],
),
),
),
Deployable(
child: Text(
"Hello World",
style: TextStyle(fontSize: 18),
),
),
],
),
),
);
}
}

Deployable
| 名称 | 类型 | 描述 |
|---|---|---|
| cutInLeft | 布尔值 | 定义容器的切割方向 |
| color | 颜色 | 定义背景颜色 |
| iconColor | 颜色 | 定义可展开图标的颜色 |
| child (必需) | Widget | 定义要展开的小部件 |
| alignment | Alignment | 定义展开时子容器的对齐方向 |


Blurred
import 'package:essential_widgets/widgets/blurred.dart';
import 'package:flutter/material.dart';
class BlurredPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Blurred(
width: 200,
height: 200,
opacity: .1,
blur: 8,
accentColor: Colors.blueGrey,
boxDecoration: BoxDecoration(borderRadius: BorderRadius.circular(20)),
child: FlutterLogo(size: 100),
),
),
);
}
}
Blurred
| 名称 | 类型 | 描述 |
|---|---|---|
| width | Double(双精度浮点数) | 定义容器的宽度 |
| 高度 | Double(双精度浮点数) | 定义容器的高度 |
| opacity | Double(双精度浮点数) | 定义强调色的不透明度 |
| 模糊 | Double(双精度浮点数) | 定义小部件的模糊量 |
| child (必需) | widget | 定义要模糊的小部件 |
| accentColor | 颜色 | 定义模糊效果的颜色层 |
| boxDecoration | BoxDecoration | 定义模糊容器的盒子装饰 |

响应式
- Factors 定义确定要使用的小部件的值,默认分别为 200px 和 800px。
factors[0] -> sm
factors[1] -> md
import 'package:essential_widgets/widgets/responsive.dart';
import 'package:flutter/material.dart';
class ResponsivePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Responsive(
sm: Text("Small"),
md: Text("Medium"),
lg: Text("Large"),
factors: [220, 768],
),
),
);
}
}
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| sm | Widget | 定义小屏幕上显示的小部件 |
| md | Widget | 定义中等屏幕尺寸上显示的小部件 |
| lg (必需) | Widget | 定义大(默认)屏幕上显示的小部件 |
| factors | 列表 | 定义每个断点(sm,md)的大小 |
