Flutter交互控制插件holdnload的使用
Flutter交互控制插件holdnload的使用
Flutter版本 3.1.0
本插件适用于Flutter版本3.1.0。
描述
这个插件的目的是创建类似于Snapchat和Instagram在录制视频或故事时显示的持有动画按钮。
入门指南
首先,将HoldAndLoad
组件包裹在Scaffold
中:
HoldAndLoad(
child: Text('hold'),
controller: ShootingController(ShootingValue(false, false)),
isShootingButtonAnimate: false,
style: Style.withGradientColor(
outerSize: const Size.square(115),
innerSize: const Size.square(82),
outerColor: Colors.white,
progressColor: Colors.redAccent,
gradient: const LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0xFF00AACE),
Color(0xFF006BCE),
],
),
progressWidth: 3,
outerWidth: 4
),
callBackShootingEnd: callBackEnd,
callBackShootingStart: callBackStart,
listener: listener,
);
HoldAndLoad
样式
样式可以设置为渐变或背景色。
带有渐变颜色的样式
Style.withGradientColor(
outerSize: const Size.square(115),
innerSize: const Size.square(82),
outerColor: Colors.white,
progressColor: Colors.redAccent,
gradient: const LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0xFF00AACE),
Color(0xFF006BCE),
],
),
progressWidth: 3,
outerWidth: 4
)
带有背景颜色的样式
Style.withBackgroundColor(
outerSize: const Size.square(115),
innerSize: const Size.square(82),
outerColor: Colors.white,
progressColor: Colors.redAccent,
backgroundColor: const Color(0xFF00AACE),
progressWidth: 3,
outerWidth: 4
)
回调
- callBackShootingStart: 当检测到长按手势时触发此回调。它只会被触发一次。
- callBackShootingEnd: 当长按手势释放时触发此回调。它只会被触发一次。
- listener: 从
callBackShootingStart
开始触发,直到callBackShootingEnd
被触发。
示例Demo
以下是完整的示例代码:
import 'package:flutter/material.dart';
import 'package:holdnload/holdnload.dart';
void main() {
runApp(const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
[@override](/user/override)
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blueGrey,
body: Center(
child: HoldAndLoad(
controller: ShootingController(ShootingValue(false, false)),
isShootingButtonAnimate: false,
style: Style.withGradientColor(
outerSize: const Size.square(115),
innerSize: const Size.square(82),
outerColor: Colors.white,
progressColor: Colors.redAccent,
gradient: const LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0xFF00AACE),
Color(0xFF006BCE),
],
),
progressWidth: 3,
outerWidth: 4
),
callBackShootingEnd: () {},
callBackShootingStart: () {},
listener: () {
// 可以在这里处理监听逻辑
},
child: Image.asset(
'assets/images/video.png',
width: 30,
height: 30,
),
),
),
);
}
}
更多关于Flutter交互控制插件holdnload的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复