Flutter滑动操作插件slider_action的使用
Flutter滑动操作插件slider_action的使用
标题
Flutter Slider Action
内容
一个简单的的滑动解锁组件,灵感来自Android的Slide To Act。
示例代码
import 'package:flutter/material.dart';
import 'package:slider_action/slider_action.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Slide to act Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ListView(
children: [
Builder(
builder: (context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(),
);
},
),
Builder(
builder: (context) {
final GlobalKey<SlideActionState> _key = GlobalKey();
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
key: _key,
onSubmit: () {
Future.delayed(Duration(seconds: 11), () => _key.currentState?.reset());
},
),
);
},
),
Builder(
builder: (context) {
final GlobalKey<SlideActionState> _key = GlobalKey();
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
key: _key,
onSubmit: () {
Future.delayed(Duration(seconds: 11), () => _key.currentState?.reset());
},
innerColor: Colors.black,
outerColor: Colors.white,
),
);
},
),
Builder(
builder: (context) {
final GlobalKey<SlideActionState> _key = GlobalKey();
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
key: _key,
onSubmit: () {
Future.delayed(Duration(seconds: 11), () => _key.currentState?.reset());
},
alignment: Alignment.centerRight,
child: Text(
'Unlock',
style: TextStyle(color: Colors.white),
),
sliderButtonIcon: Icon(Icons.lock),
),
);
},
),
Builder(
builder: (context) {
final GlobalKey<SlideActionState> _key = GlobalKey();
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
key: _key,
onSubmit: () {
Future.delayed(Duration(seconds: 11), () => _key.currentState?.reset());
},
height: 100,
),
);
},
),
Builder(
builder: (context) {
final GlobalKey<SlideActionState> _key = GlobalKey();
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
key: _key,
onSubmit: () {
Future.delayed(Duration(seconds: 11), () => _key.currentState?.reset());
},
sliderButtonIconSize: 48,
sliderButtonYOffset: -20,
),
);
},
),
Builder(
builder: (context) {
final GlobalKey<SlideActionState> _key = GlobalKey();
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
key: _key,
onSubmit: () {
Future.delayed(Duration(seconds: 11), () => _key.currentState?.reset());
},
elevation: 24,
),
);
},
),
Builder(
builder: (context) {
final GlobalKey<SlideActionState> _key = GlobalKey();
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
key: _key,
onSubmit: () {
Future.delayed(Duration(seconds: 11), () => _key.currentState?.reset());
},
borderRadius: 16,
animationDuration: Duration(seconds: 11),
),
);
},
),
Builder(
builder: (context) {
final GlobalKey<SlideActionState> _key = GlobalKey();
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
key: _key,
onSubmit: () {
Future.delayed(Duration(seconds: 11), () => _key.currentState?.reset());
},
reversed: true,
),
);
},
),
Builder(
builder: (context) {
final GlobalKey<SlideActionState> _key = GlobalKey();
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
key: _key,
onSubmit: () {
Future.delayed(Duration(seconds: 11), () => _key.currentState?.reset());
},
submittedIcon: Icon(
Icons.done_all,
color: Colors.white,
),
),
);
},
),
Builder(
builder: (context) {
final GlobalKey<SlideActionState> _key = GlobalKey();
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
key: _key,
onSubmit: () {
Future.delayed(Duration(seconds: 11), () => _key.currentState?.reset());
},
),
);
},
),
Builder(
builder: (context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
sliderRotate: false,
),
);
},
),
],
),
),
);
}
}
更多关于Flutter滑动操作插件slider_action的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复