back_button_interceptor 1.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 37

back_button_interceptor #

The BackButtonInterceptor may be used to intercept the Android back-button, as an alternative to WillPopScope.

You may set a function to be called when the back button is tapped. This function may perform some useful work, and then, if it returns false, the default button process (usually popping a Route) will not be fired.

Note: Only one function may be defined at a time, and setting a function will remove the previous one. After you've finished you MUST remove the function by setting it to null, or calling the remove() method.

Usage #

Import the package #

First, add back_button_interceptor as a dependency in your pubspec.yaml

Then, import it:

import 'package:back_button_interceptor/back_button_interceptor.dart';

Example usage #

@override
void initState() {
    super.initState();
    BackButtonInterceptor.set(() {
       print("BACK BUTTON!");
       return false;
       });
}

 @override
 void dispose() {
    BackButtonInterceptor.remove();
    super.dispose();
 }

Don't forget to check the example tab.

See also:

[1.0.0] - 02/01/2019

  • Tested thoroughly.

example/main.dart

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

void main() async => runApp(MaterialApp(home: Demo()));

class Demo extends StatefulWidget {
  @override
  DemoState createState() => new DemoState();
}

class DemoState extends State<Demo> {
  @override
  void initState() {
    super.initState();
    BackButtonInterceptor.set(() {
      print("BACK BUTTON!");
      return false;
    });
  }

  @override
  void dispose() {
    BackButtonInterceptor.remove();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    //
    return Scaffold(
      appBar: AppBar(title: const Text('Back Button Interceptor Example')),
      body: Container(color: Colors.green),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  back_button_interceptor: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:back_button_interceptor/back_button_interceptor.dart';
  
Version Uploaded Documentation Archive
2.0.2 Feb 22, 2019 Go to the documentation of back_button_interceptor 2.0.2 Download back_button_interceptor 2.0.2 archive
2.0.1 Feb 22, 2019 Go to the documentation of back_button_interceptor 2.0.1 Download back_button_interceptor 2.0.1 archive
2.0.0 Jan 3, 2019 Go to the documentation of back_button_interceptor 2.0.0 Download back_button_interceptor 2.0.0 archive
1.0.0 Jan 2, 2019 Go to the documentation of back_button_interceptor 1.0.0 Download back_button_interceptor 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
73
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
37
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <=5.0.0