A simple slide-to-unlock widget for Flutter inspired by the Android Slide To Act.
Add slide_to_act to your pubspec:
dependencies:
slide_to_act: any # or the latest version on Pub
An example app showing all the features is available in this repo in the folder example
.
Run the app to get an idea of the component.
Or just go to this link to see it compiled for the web https://imtoori.dev/flutter-slide-to-act/#/
Contributions of any kind are more than welcome! Feel free to fork and improve the project in any way you want, make a pull request, or open an issue.
Run this command:
With Flutter:
$ flutter pub add slide_to_act
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get
):
dependencies:
slide_to_act: ^2.0.2
Alternatively, your editor might support flutter pub get
. Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:slide_to_act/slide_to_act.dart';
import 'package:flutter/material.dart';
import 'package:slide_to_act/slide_to_act.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Slide to act Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ListView(
children: <Widget>[
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: 1),
() => _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: 1),
() => _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: 1),
() => _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: 1),
() => _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: 1),
() => _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: 1),
() => _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: 1),
() => _key.currentState!.reset(),
);
},
borderRadius: 16,
animationDuration: Duration(seconds: 1),
),
);
},
),
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: 1),
() => _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: 1),
() => _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: 1),
() => _key.currentState!.reset(),
);
},
),
);
},
),
Builder(
builder: (context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: SlideAction(
sliderRotate: false,
),
);
},
),
],
),
),
);
}
}
Download details:
Author: talhasultan.dev
Source: https://github.com/imtoori/flutter-slide-to-act