vijaycreations
Published in

vijaycreations

Slide to action button in Flutter

In this article we will discuss about how to perform slide to action in our flutter app.

→ Build up the basic UI containing the elevated button at the center.

  @override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Slide to action')),
body: Center(
child: ElevatedButton(
child: const Text('Logout'),
onPressed: () {},
),
));
}
}

→ Integrate quickalert package to show a popup menu whenever the logout button is pressed. Hence add the following code 👇 inside the onpressed event of the above elevated button widget.

  @override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Slide to action')),
body: Center(
child: ElevatedButton(
child: const Text('Logout'),
onPressed: () {
//----------------------------------------------
QuickAlert.show(
context: context,
type: QuickAlertType.loading,
title: 'Warning!',
text: 'Are you sure you want to logout?',
customAsset: 'assets/Images/warning.gif',
widget: const SlideActionBtn(),
);
//----------------------------------------------
},
),
));
}
}

→ The SlideActionBtn() widget is as follows.,

class SlideActionBtn extends StatelessWidget {
const SlideActionBtn({
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 30),
child: SlideAction(
trackBuilder: (context, state) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: Colors.white,
boxShadow: const [
BoxShadow(
color: Colors.black26,
blurRadius: 8,
),
],
),
child: Center(
child: Text(
// Show loading if async operation is being performed
state.isPerformingAction ? "Loading..." : "Slide to logout",
),
),
);
},
thumbBuilder: (context, state) {
return Container(
margin: const EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(16),
),
child: Center(
// Show loading indicator if async operation is being performed
child: state.isPerformingAction
? const CupertinoActivityIndicator(
color: Colors.white,
)
: const Icon(
Icons.chevron_right,
color: Colors.white,
),
),
);
},
action: () async {
// Async operation
await Future.delayed(
const Duration(seconds: 2),
() => debugPrint("action completed"),
);
},
),
);
}
}

Well that’s it. 🎉 Run the code to see it in action.🥳

Refer my video tutorial for complete guide:👉 https://youtube.com/shorts/XNi_djU7TvE?feature=share

Get the complete source code here:👉 https://github.com/vijayinyoutube/slide_action_app

--

--

A list of Flutter Tutorials and app templates

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vijay R

Hai👋 I’m a flutter developer experienced in designing and developing stunning mobile apps. Reach out for freelance projects: vijaycreations02@gmail.com