swipe_callback 1.0.0+1 copy "swipe_callback: ^1.0.0+1" to clipboard
swipe_callback: ^1.0.0+1 copied to clipboard

A simple flutter package to add swipe to reply functionality similar to that of Whatsapp.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:swipe_callback/swipe_callback.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Swipe action demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final List<String> sampleText = [
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris in mattis arcu. Donec lobortis consequat libero a gravida.",
    "Donec ac enim eget velit varius accumsan. Aliquam eu ante quis ligula blandit faucibus vitae volutpat lectus.",
  ];

  void showSnackBar(String message) {
    ScaffoldMessenger.of(
      context,
    ).showSnackBar(SnackBar(content: Text(message)));
  }

  Widget createSwipeWidgets(SwipeDirection swipeDirection) {
    return Column(
      spacing: 16,
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: [
        Center(
          child: Text(
            swipeDirection.name,
            style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
          ),
        ),
        SwipeCallback(
          swipeDirection: swipeDirection,
          onSwipeSuccess: () {
            showSnackBar("Swipe success triggered");
          },
          threshold: 150,
          child: SizedBox(
            width: double.infinity,
            child: FractionallySizedBox(
              widthFactor: 0.8,
              alignment: Alignment.centerLeft,
              child: DecoratedBox(
                decoration: BoxDecoration(
                  color: Colors.blue,
                  borderRadius: BorderRadius.circular(12),
                ),
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text(sampleText.first),
                ),
              ),
            ),
          ),
        ),
        SwipeCallback(
          swipeDirection: swipeDirection,
          onSwipeSuccess: () {
            showSnackBar("Swipe success triggered");
          },
          threshold: 150,
          child: SizedBox(
            width: double.infinity,
            child: FractionallySizedBox(
              widthFactor: 0.8,
              alignment: Alignment.topRight,
              child: DecoratedBox(
                decoration: BoxDecoration(
                  color: Colors.green,
                  borderRadius: BorderRadius.circular(12),
                ),
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text(sampleText.last),
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Swipe Action Example")),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            spacing: 32,
            children: [
              createSwipeWidgets(SwipeDirection.right),
              Divider(),
              createSwipeWidgets(SwipeDirection.left),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
160
points
4
downloads

Publisher

verified publisherdoki.co.in

Weekly Downloads

A simple flutter package to add swipe to reply functionality similar to that of Whatsapp.

Repository (GitHub)
View/report issues

Topics

#swipe-action #chat-reply

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on swipe_callback