Flutter动画按钮插件pretty_animated_buttons的使用
Flutter动画按钮插件pretty_animated_buttons
的使用
Pretty Animated Buttons
是一个Flutter插件,提供了多种美观且高度可定制的动画按钮。当前版本中包含了12种不同风格的动画按钮,并且未来还会增加更多样式。
动画按钮列表
序号 | 按钮名称 | 示例 |
---|---|---|
1 | Pretty Shadow Button | |
2 | Pretty Neumorphic Button | |
3 | Pretty Slide Underline Button | |
4 | Pretty Wave Button | |
5 | Pretty Fuzzy Button | |
6 | Pretty Slide Icon Button | |
7 | Pretty Slide Up Button | |
8 | Pretty Color Slide Button | |
9 | Pretty Skew Button | |
10 | Pretty Border Button | |
11 | Pretty Bar Button | |
12 | Pretty Capsule Button |
使用方法
使用这些按钮非常简单,只需在代码中调用相应的按钮类名即可。以下是一些示例:
完整示例 Demo
import 'package:flutter/material.dart';
import 'package:pretty_animated_buttons/pretty_animated_buttons.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Pretty Buttons Example',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.teal,
),
home: const PrettyButtonsExample(),
);
}
}
class PrettyButtonsExample extends StatefulWidget {
const PrettyButtonsExample({super.key});
@override
State<PrettyButtonsExample> createState() => _PrettyButtonsExampleState();
}
class _PrettyButtonsExampleState extends State<PrettyButtonsExample> {
final Color? scaffoldBg = Colors.grey[300];
final Color btnColor = Colors.teal;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: scaffoldBg,
body: Padding(
padding: const EdgeInsets.all(25.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Pretty Shadow Button
PrettyShadowButton(
label: "Pretty Shadow Button",
onPressed: () {},
icon: Icons.arrow_forward,
shadowColor: btnColor,
),
// Pretty Neumorphic Button
PrettyNeumorphicButton(
label: 'Pretty Neumorphic Button',
onPressed: () {},
),
// Pretty Slide Underline Button
PrettySlideUnderlineButton(
label: 'Pretty Slide Underline Button',
onPressed: () {},
secondSlideColor: scaffoldBg,
),
// Pretty Wave Button
PrettyWaveButton(
child: const Text(
'Pretty Wave Button',
style: TextStyle(color: Colors.white),
),
onPressed: () {},
),
// Pretty Fuzzy Button
PrettyFuzzyButton(
label: 'Pretty Fuzzy Button',
onPressed: () {},
),
// Pretty Slide Icon Button
PrettySlideIconButton(
foregroundColor: btnColor,
icon: Icons.arrow_forward,
label: 'Pretty Slide Icon Button',
slidePosition: SlidePosition.right,
labelStyle: Theme.of(context).textTheme.bodyLarge!,
onPressed: () {},
),
// Pretty Slide Up Button
PrettySlideUpButton(
bgColor: btnColor,
onPressed: () {},
firstChild: const Text(
'First Slide Up Text',
style: TextStyle(color: Colors.white),
),
secondChild: const Text(
'Second Slide Up Text',
style: TextStyle(color: Colors.white),
),
),
// Pretty Color Slide Button
PrettyColorSlideButton(
label: 'Pretty Color Slide Button',
onPressed: () {},
bgColor: btnColor,
position: SlidePosition.bottom,
),
// Pretty Skew Button
PrettySkewButton(
label: 'Pretty Skew Button',
firstBgColor: btnColor,
onPressed: () {},
),
// Pretty Border Button
PrettyBorderButton(
label: 'Pretty Border Button',
onPressed: () {},
),
// Pretty Bar Button
PrettyBarButton(
onPressed: () {},
label: 'Pretty Bar Button',
),
// Pretty Capsule Button
PrettyCapsuleButton(
label: 'Pretty Capsule Button'.toUpperCase(),
labelStyle: const TextStyle(fontWeight: FontWeight.w700),
bgColor: btnColor,
onPressed: () {},
),
],
),
),
),
);
}
}
特殊参数说明
Pretty Slide Icon Button
PrettySlideIconButton
支持左右滑动位置设置:
- 左滑:
slidePosition: SlidePosition.left,
- 右滑:
slidePosition: SlidePosition.right,
Pretty Color Slide Button
PrettyColorSlideButton
支持滑动方向设置:
- 左右滑动:
position: SlidePosition.left,
- 上下滑动:
position: SlidePosition.top,
Pretty Skew Button
PrettySkewButton
也支持左右滑动位置设置:
- 左滑:
skewPosition: SkewPositions.left,
- 右滑:
skewPosition: SkewPositions.right,
更多关于Flutter动画按钮插件pretty_animated_buttons的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter动画按钮插件pretty_animated_buttons的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
当然,以下是一个关于如何在Flutter项目中使用pretty_animated_buttons
插件的示例代码。这个插件提供了一些预定义的动画按钮,你可以轻松地在你的应用中集成它们。
首先,确保你已经在pubspec.yaml
文件中添加了pretty_animated_buttons
依赖:
dependencies:
flutter:
sdk: flutter
pretty_animated_buttons: ^0.1.0 # 请注意版本号,使用最新版本
然后,运行flutter pub get
来安装依赖。
接下来,你可以在你的Flutter应用中使用这些动画按钮。以下是一个简单的示例代码,展示了如何使用PrettyAnimatedButton
:
import 'package:flutter/material.dart';
import 'package:pretty_animated_buttons/pretty_animated_buttons.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Pretty Animated Buttons Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _onButtonPressed() {
// 按钮点击后的处理逻辑
print("Button pressed!");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Pretty Animated Buttons Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
PrettyAnimatedButton(
animationType: ButtonAnimationType.jump,
width: 200,
height: 50,
color: Colors.blue,
borderColor: Colors.white,
borderWidth: 2.0,
borderRadius: 25.0,
text: 'Jump Button',
textStyle: TextStyle(color: Colors.white, fontSize: 18),
onPressed: _onButtonPressed,
),
SizedBox(height: 20),
PrettyAnimatedButton(
animationType: ButtonAnimationType.shrink,
width: 200,
height: 50,
color: Colors.green,
borderColor: Colors.white,
borderWidth: 2.0,
borderRadius: 25.0,
text: 'Shrink Button',
textStyle: TextStyle(color: Colors.white, fontSize: 18),
onPressed: _onButtonPressed,
),
SizedBox(height: 20),
PrettyAnimatedButton(
animationType: ButtonAnimationType.pulse,
width: 200,
height: 50,
color: Colors.red,
borderColor: Colors.white,
borderWidth: 2.0,
borderRadius: 25.0,
text: 'Pulse Button',
textStyle: TextStyle(color: Colors.white, fontSize: 18),
onPressed: _onButtonPressed,
),
],
),
),
);
}
}
在这个示例中,我们创建了一个简单的Flutter应用,其中包含三个不同类型的动画按钮:Jump
、Shrink
和Pulse
。每个按钮都有自己的颜色、边框、文本和点击事件处理函数。
animationType
属性指定了按钮的动画类型。width
和height
属性设置了按钮的宽度和高度。color
属性设置了按钮的背景颜色。borderColor
和borderWidth
属性设置了按钮边框的颜色和宽度。borderRadius
属性设置了按钮的圆角半径。text
和textStyle
属性设置了按钮上的文本和文本样式。onPressed
属性是按钮点击事件的回调函数。
你可以根据需要调整这些属性来创建符合你应用风格的动画按钮。