Flutter水波纹动画效果插件ripple_container的使用
Flutter水波纹动画效果插件ripple_container的使用
特性
RippleContainer 提供了一个多功能的 Box 小部件,可以在 Flutter 应用程序中应用水波纹效果。
主要特性包括:
- 应用水波纹效果
- 简单直观的使用方式
- 各种自定义选项(背景颜色、水波纹颜色、速度、大小等)
- 兼容所有 Flutter 项目
如何使用
以下是一个简单的示例代码,展示如何在 Flutter 应用中使用 RippleContainer:
RippleContainer(
width: 200,
height: 100,
backgroundColor: Colors.blueAccent,
margin: const EdgeInsets.all(10),
borderRadius: BorderRadius.circular(30),
splashColor: Colors.amber,
border: const Border.fromBorderSide(BorderSide(color: Colors.grey)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
offset: const Offset(0, 2),
blurRadius: 10,
)
],
onTap: () => tapTest('Button OnTap'),
onLongPress: () => tapTest('Button OnLongPress'),
child: const Text('Hi'),
)
示例
以下是一些示例代码,帮助你更好地理解如何使用 RippleContainer:
示例代码
import 'package:flutter/material.dart';
import 'package:ripple_container/ripple_container.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(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
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> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RippleContainer(
width: 200,
height: 100,
decoration: ContainerDecoration(
backgroundColor: Colors.blueAccent,
margin: const EdgeInsets.all(10),
borderRadius: BorderRadius.circular(30),
splashColor: Colors.amber,
border: const Border.fromBorderSide(BorderSide(color: Colors.grey)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
offset: const Offset(0, 2),
blurRadius: 10,
)
],
),
onTap: () => tapTest('Button OnTap'),
onLongPress: () => tapTest('Button OnLongPress'),
child: const Text('Hi'),
),
Container(
width: 200,
height: 100,
decoration: const BoxDecoration(
border: Border.fromBorderSide(BorderSide(color: Colors.red))),
child: const Text('Hi'),
)
],
),
),
);
}
void tapTest(String testMessage) =>
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
testMessage,
style: TextStyle(color: Colors.white),
),
duration: Duration(seconds: 1),
showCloseIcon: true,
),
);
}
展示效果
RippleContainer 示例
RippleContainer(
width: 200,
height: 100,
backgroundColor: Colors.blueAccent,
margin: const EdgeInsets.all(10),
borderRadius: BorderRadius.circular(30),
splashColor: Colors.amber,
border: const Border.fromBorderSide(BorderSide(color: Colors.grey)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
offset: const Offset(0, 2),
blurRadius: 10,
)
],
onTap: () => tapTest('Button OnTap'),
onLongPress: () => tapTest('Button OnLongPress'),
child: const Text('Hi'),
)
原始 Container 示例
Container(
width: 200,
height: 100,
decoration: const BoxDecoration(
border: Border.fromBorderSide(BorderSide(color: Colors.red)),
),
child: const Text('Hi'),
)
更多关于Flutter水波纹动画效果插件ripple_container的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复