swipe_back_detector 1.0.0 copy "swipe_back_detector: ^1.0.0" to clipboard
swipe_back_detector: ^1.0.0 copied to clipboard

outdated

A detector to add "swipe to go back" functionality in custom routes or non Cupertino routes.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: FirstScreen(),
    );
  }
}

class FirstScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Swipe back detector example"),
      ),
      body: Center(
        child: RaisedButton(
          child: Text("Push route"),
          onPressed: () {
            Navigator.of(context).push(
              MyCustomRoute(
                widget: SecondScreen(),
              ),
            );
          },
        ),
      ),
    );
  }
}

class SecondScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Second screen"),
        automaticallyImplyLeading: false,
      ),
      body: Center(
          child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: List<Widget>.generate(
              5,
              (_) => Icon(Icons.chevron_left),
            ),
          ),
          Text("Swipe here to go back")
        ],
      )),
    );
  }
}

class MyCustomRoute extends PageRouteBuilder {
  final RouteSettings routeSettings;

  MyCustomRoute({
    @required Widget widget,
    this.routeSettings,
  }) : super(
          settings: routeSettings,
          pageBuilder: (context, animation1, animation2) {
            return widget;
          },
          transitionsBuilder: (context, animation1, animation2, child) {
            return SwipeBackDetector(
              child: SlideTransition(
                position: Tween<Offset>(begin: Offset(1, 1), end: Offset.zero)
                    .animate(animation1),
                child: FadeTransition(
                  opacity: animation1,
                  child: widget,
                ),
              ),
            );
          },
          transitionDuration: Duration(milliseconds: 250),
          opaque: false,
          barrierDismissible: true,
        );
}
14
likes
0
pub points
77%
popularity

Publisher

verified publishermagicleon94.dev

A detector to add "swipe to go back" functionality in custom routes or non Cupertino routes.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on swipe_back_detector