├── example ├── ios │ ├── Flutter │ │ ├── Debug.xcconfig │ │ ├── Release.xcconfig │ │ └── AppFrameworkInfo.plist │ ├── Runner │ │ ├── AppDelegate.h │ │ ├── Assets.xcassets │ │ │ ├── LaunchImage.imageset │ │ │ │ ├── LaunchImage.png │ │ │ │ ├── LaunchImage@2x.png │ │ │ │ ├── LaunchImage@3x.png │ │ │ │ ├── README.md │ │ │ │ └── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ ├── Icon-App-20x20@1x.png │ │ │ │ ├── Icon-App-20x20@2x.png │ │ │ │ ├── Icon-App-20x20@3x.png │ │ │ │ ├── Icon-App-29x29@1x.png │ │ │ │ ├── Icon-App-29x29@2x.png │ │ │ │ ├── Icon-App-29x29@3x.png │ │ │ │ ├── Icon-App-40x40@1x.png │ │ │ │ ├── Icon-App-40x40@2x.png │ │ │ │ ├── Icon-App-40x40@3x.png │ │ │ │ ├── Icon-App-60x60@2x.png │ │ │ │ ├── Icon-App-60x60@3x.png │ │ │ │ ├── Icon-App-76x76@1x.png │ │ │ │ ├── Icon-App-76x76@2x.png │ │ │ │ ├── Icon-App-1024x1024@1x.png │ │ │ │ ├── Icon-App-83.5x83.5@2x.png │ │ │ │ └── Contents.json │ │ ├── main.m │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ │ ├── Main.storyboard │ │ │ └── LaunchScreen.storyboard │ │ └── Info.plist │ ├── Runner.xcworkspace │ │ └── contents.xcworkspacedata │ └── Runner.xcodeproj │ │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ │ └── project.pbxproj ├── SponsoredByMyTextAi.png ├── android │ ├── gradle.properties │ ├── app │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ └── ic_launcher.png │ │ │ │ │ ├── values │ │ │ │ │ │ └── styles.xml │ │ │ │ │ └── drawable │ │ │ │ │ │ └── launch_background.xml │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── example │ │ │ │ │ │ └── example │ │ │ │ │ │ └── MainActivity.java │ │ │ │ └── AndroidManifest.xml │ │ │ ├── debug │ │ │ │ └── AndroidManifest.xml │ │ │ └── profile │ │ │ │ └── AndroidManifest.xml │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ └── build.gradle ├── .metadata ├── pubspec.yaml ├── README.md ├── lib │ ├── main.dart │ ├── main_future.dart │ ├── main_complex_example.dart │ └── main_complex_example_routes_not_named.dart ├── .gitignore └── test │ └── main_complex_example_test.dart ├── lib ├── back_button_interceptor.dart └── src │ ├── merge_sort.dart │ └── back_button_interceptor.dart ├── .gitignore ├── .metadata ├── pubspec.yaml ├── back_button_interceptor.iml ├── LICENSE ├── CHANGELOG.md ├── README.md └── analysis_options.yaml /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Generated.xcconfig" 2 | -------------------------------------------------------------------------------- /lib/back_button_interceptor.dart: -------------------------------------------------------------------------------- 1 | export "src/back_button_interceptor.dart"; 2 | -------------------------------------------------------------------------------- /example/SponsoredByMyTextAi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/SponsoredByMyTextAi.png -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=-Xmx1536M 2 | android.enableR8=true 3 | android.useAndroidX=true 4 | android.enableJetifier=true 5 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : FlutterAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcglasberg/back_button_interceptor/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | ios/.generated/ 9 | ios/Flutter/Generated.xcconfig 10 | ios/Runner/GeneratedPluginRegistrant.* 11 | 12 | .idea/ 13 | *.iml 14 | pubspec.lock 15 | *.lock 16 | .flutter-plugins-dependencies 17 | -------------------------------------------------------------------------------- /example/ios/Runner/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char* argv[]) { 6 | @autoreleasepool { 7 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 23 08:50:38 CEST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip 7 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 5391447fae6209bb21a89e6a5a6583cac1af9b4b 8 | channel: stable 9 | 10 | project_type: package 11 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 20e59316b8b8474554b38493b8ca888794b0234a 8 | channel: stable 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/android/app/src/profile/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md: -------------------------------------------------------------------------------- 1 | # Launch Screen Assets 2 | 3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory. 4 | 5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images. -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: example 2 | description: Examples for back_button_interceptor. 3 | publish_to: "none" 4 | version: 1.0.0+1 5 | 6 | environment: 7 | sdk: '>=3.2.0 <4.0.0' 8 | 9 | dependencies: 10 | back_button_interceptor: 11 | path: ../ 12 | flutter: 13 | sdk: flutter 14 | 15 | dev_dependencies: 16 | flutter_test: 17 | sdk: flutter 18 | 19 | flutter: 20 | uses-material-design: true 21 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.example; 2 | 3 | import android.os.Bundle; 4 | import io.flutter.app.FlutterActivity; 5 | import io.flutter.plugins.GeneratedPluginRegistrant; 6 | 7 | public class MainActivity extends FlutterActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | GeneratedPluginRegistrant.registerWith(this); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #include "AppDelegate.h" 2 | #include "GeneratedPluginRegistrant.h" 3 | 4 | @implementation AppDelegate 5 | 6 | - (BOOL)application:(UIApplication *)application 7 | didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 8 | [GeneratedPluginRegistrant registerWithRegistry:self]; 9 | // Override point for customization after application launch. 10 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 11 | } 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "LaunchImage.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "LaunchImage@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "LaunchImage@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() 4 | 5 | def plugins = new Properties() 6 | def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') 7 | if (pluginsFile.exists()) { 8 | pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } 9 | } 10 | 11 | plugins.each { name, path -> 12 | def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() 13 | include ":$name" 14 | project(":$name").projectDir = pluginDirectory 15 | } 16 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: back_button_interceptor 2 | description: Back Button Interceptor. May be used to do stuff when the Android back-button is tapped, as an alternative to `WillPopScope`. 3 | version: 8.0.4 4 | # author: Marcelo Glasberg 5 | homepage: https://github.com/marcglasberg/back_button_interceptor 6 | topics: 7 | - button 8 | - android 9 | - navigation 10 | 11 | environment: 12 | sdk: '>=3.2.0 <4.0.0' 13 | 14 | dependencies: 15 | collection: ^1.17.1 16 | flutter: 17 | sdk: flutter 18 | 19 | dev_dependencies: 20 | flutter_test: 21 | sdk: flutter 22 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | jcenter() 5 | } 6 | 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:3.3.1' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | google() 15 | jcenter() 16 | } 17 | } 18 | 19 | rootProject.buildDir = '../build' 20 | subprojects { 21 | project.buildDir = "${rootProject.buildDir}/${project.name}" 22 | } 23 | subprojects { 24 | project.evaluationDependsOn(':app') 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 8.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /back_button_interceptor.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | 1. main 4 | 5 | Intercepts the back-button and prints a string to the console. 6 | 7 | 2. main_complex_example 8 | 9 | The first screen has a button which opens a second screen. 10 | The second screen has 3 red squares. 11 | By tapping the Android back-button (or the "pop" button) each square turns blue, one by one. 12 | Only when all squares are blue, tapping the back-button once more will return to the previous screen. 13 | Also, if you click the "Open Dialog" button, the interceptors are disabled while the dialog is open. 14 | 15 | 3. main_complex_example_test 16 | 17 | This package is test friendly, and this examples shows how to test the back button. 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 by Marcelo Glasberg 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted 4 | provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions 7 | and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of 10 | conditions and the following disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 14 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 15 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 16 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 19 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 20 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | // Developed by Marcelo Glasberg (2019) https://glasberg.dev and https://github.com/marcglasberg 2 | // For more info, see: https://pub.dartlang.org/packages/back_button_interceptor 3 | import 'package:back_button_interceptor/back_button_interceptor.dart'; 4 | import 'package:flutter/material.dart'; 5 | 6 | // When pressing the back-button, a message will be printed to the console, 7 | // and no back action will happen. 8 | 9 | void main() => runApp(MaterialApp(home: Demo())); 10 | 11 | class Demo extends StatefulWidget { 12 | @override 13 | DemoState createState() => DemoState(); 14 | } 15 | 16 | class DemoState extends State { 17 | // 18 | @override 19 | void initState() { 20 | super.initState(); 21 | BackButtonInterceptor.add(myInterceptor); 22 | } 23 | 24 | @override 25 | void dispose() { 26 | BackButtonInterceptor.remove(myInterceptor); 27 | super.dispose(); 28 | } 29 | 30 | bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { 31 | print("BACK BUTTON!"); // Do some stuff. 32 | return true; 33 | } 34 | 35 | @override 36 | Widget build(BuildContext context) { 37 | // 38 | return Scaffold( 39 | appBar: AppBar(title: const Text('Back Button Interceptor Example')), 40 | body: Container( 41 | color: Colors.green, 42 | child: const Center( 43 | child: Text('Click the Back Button\n' 44 | 'and see the message in the console.'), 45 | ), 46 | ), 47 | ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | example 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(FLUTTER_BUILD_NAME) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(FLUTTER_BUILD_NUMBER) 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UISupportedInterfaceOrientations 30 | 31 | UIInterfaceOrientationPortrait 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UIViewControllerBasedStatusBarAppearance 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /example/lib/main_future.dart: -------------------------------------------------------------------------------- 1 | // Developed by Marcelo Glasberg (2019) https://glasberg.dev and https://github.com/marcglasberg 2 | // For more info, see: https://pub.dartlang.org/packages/back_button_interceptor 3 | import 'package:back_button_interceptor/back_button_interceptor.dart'; 4 | import 'package:flutter/material.dart'; 5 | 6 | // When pressing the back-button, a message will be printed to the console, 7 | // and no back action will happen. In this case, the interceptor function is 8 | // a Future. 9 | 10 | void main() => runApp(MaterialApp(home: Demo())); 11 | 12 | class Demo extends StatefulWidget { 13 | @override 14 | DemoState createState() => DemoState(); 15 | } 16 | 17 | class DemoState extends State { 18 | // 19 | @override 20 | void initState() { 21 | super.initState(); 22 | BackButtonInterceptor.add(myInterceptor); 23 | } 24 | 25 | @override 26 | void dispose() { 27 | BackButtonInterceptor.remove(myInterceptor); 28 | super.dispose(); 29 | } 30 | 31 | Future myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) async { 32 | print("BACK BUTTON!"); // Do some stuff. 33 | print("Waiting..."); // Do some stuff. 34 | await Future.delayed(const Duration(seconds: 2)); 35 | print("Finished waiting."); // Do some stuff. 36 | return true; 37 | } 38 | 39 | @override 40 | Widget build(BuildContext context) { 41 | // 42 | return Scaffold( 43 | appBar: AppBar(title: const Text('Back Button Interceptor Example')), 44 | body: Container( 45 | color: Colors.green, 46 | child: const Center( 47 | child: Text('Click the Back Button\n' 48 | 'and see the message in the console.'), 49 | ), 50 | ), 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 13 | 20 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 26 | 27 | android { 28 | compileSdkVersion 28 29 | 30 | lintOptions { 31 | disable 'InvalidPackage' 32 | } 33 | 34 | defaultConfig { 35 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 36 | applicationId "com.example.example" 37 | minSdkVersion 16 38 | targetSdkVersion 28 39 | versionCode flutterVersionCode.toInteger() 40 | versionName flutterVersionName 41 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 42 | } 43 | 44 | buildTypes { 45 | release { 46 | // TODO: Add your own signing config for the release build. 47 | // Signing with the debug keys for now, so `flutter run --release` works. 48 | signingConfig signingConfigs.debug 49 | } 50 | } 51 | } 52 | 53 | flutter { 54 | source '../..' 55 | } 56 | 57 | dependencies { 58 | } 59 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/.flutter-plugins-dependencies 25 | **/flutter_export_environment.sh 26 | **/doc/api/ 27 | .dart_tool/ 28 | .flutter-plugins 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | build/ 34 | ios/.generated/ 35 | ios/Flutter/Generated.xcconfig 36 | ios/Runner/GeneratedPluginRegistrant.* 37 | pubspec.lock 38 | *.lock 39 | .flutter-plugins-dependencies 40 | 41 | # Android related 42 | **/android/**/gradle-wrapper.jar 43 | **/android/.gradle 44 | **/android/captures/ 45 | **/android/gradlew 46 | **/android/gradlew.bat 47 | **/android/local.properties 48 | **/android/**/GeneratedPluginRegistrant.java 49 | 50 | # iOS/XCode related 51 | **/ios/**/*.mode1v3 52 | **/ios/**/*.mode2v3 53 | **/ios/**/*.moved-aside 54 | **/ios/**/*.pbxuser 55 | **/ios/**/*.perspectivev3 56 | **/ios/**/*sync/ 57 | **/ios/**/.sconsign.dblite 58 | **/ios/**/.tags* 59 | **/ios/**/.vagrant/ 60 | **/ios/**/DerivedData/ 61 | **/ios/**/Icon? 62 | **/ios/**/Pods/ 63 | **/ios/**/.symlinks/ 64 | **/ios/**/profile 65 | **/ios/**/xcuserdata 66 | **/ios/.generated/ 67 | **/ios/Flutter/App.framework 68 | **/ios/Flutter/Flutter.framework 69 | **/ios/Flutter/Generated.xcconfig 70 | **/ios/Flutter/app.flx 71 | **/ios/Flutter/app.zip 72 | **/ios/Flutter/flutter_assets/ 73 | **/ios/ServiceDefinitions.json 74 | **/ios/Runner/GeneratedPluginRegistrant.* 75 | 76 | # Exceptions to above rules. 77 | !**/ios/**/default.mode1v3 78 | !**/ios/**/default.mode2v3 79 | !**/ios/**/default.pbxuser 80 | !**/ios/**/default.perspectivev3 81 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages 82 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 8.0.4 2 | 3 | * Sponsored by [MyText.ai](https://mytext.ai) 4 | 5 | [![](./example/SponsoredByMyTextAi.png)](https://mytext.ai) 6 | 7 | ## 7.1.0 8 | 9 | * Added static methods `BackButtonInterceptor.getInnermostNamedNavigatorRoute` 10 | and `BackButtonInterceptor.getInnermostNamedNavigatorRouteName`. Those methods will 11 | get the current navigator route, if that route has a name. If it doesn't have a name, 12 | it will go back until it finds a route with a name. This can be helpful if you are in 13 | a dialog or bottom sheet, and you want to know the route of the screen it's in. 14 | 15 | ## 7.0.3 16 | 17 | * Updated the README to include: "To make it work on Android 13 and up, set this to 18 | `false` in the Android manifest: `android:enableOnBackInvokedCallback="false"` 19 | 20 | ## 7.0.1 21 | 22 | * When your interceptor throws an error, you now also get its stacktrace. This is a 23 | breaking change only if you define your own `errorProcessing` function. If that's the 24 | case and your code breaks, simply change the signature of your error processing function 25 | from `static Function(Object)` to `static Function(Object, StackTrace)`. 26 | 27 | ## 6.0.1 28 | 29 | * Flutter 3.0 30 | 31 | ## 5.1.0 32 | 33 | * Don't use this version. 34 | 35 | ## 5.0.2 36 | 37 | * Docs improvement. This is the version you should use with Flutter <3.0. 38 | 39 | ## 5.0.1 40 | 41 | * Now the interceptor function can return `bool` or `Future`: 42 | `typedef InterceptorFunction = FutureOr Function(bool stopDefaultButtonEvent, RouteInfo routeInfo);` 43 | 44 | ## 5.0.0 45 | 46 | * Nullsafety. 47 | 48 | ## 4.4.1 49 | 50 | * Method ifRouteChanged() now works with named and unnamed routes. 51 | 52 | ## 4.3.0 53 | 54 | * Breaking change: The interceptor functions now get a second parameter `RouteInfo info`. 55 | To upgrade from version [4.2.4] you just need to add this parameter to your functions 56 | (you have to add it, but you don't need to use it, unless you need the new 57 | functionalities it provides). 58 | 59 | * Please read the "Notes" section of the README for more information 60 | about the new `RouteInfo` parameter. 61 | 62 | ## 3.0.0 63 | 64 | * Prevents silent errors swallowing. 65 | 66 | ## 2.0.0 67 | 68 | * Multiple interceptors. 69 | 70 | ## 1.0.0 71 | 72 | * Tested thoroughly. Single interceptor. 73 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /example/test/main_complex_example_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:back_button_interceptor/back_button_interceptor.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'package:flutter_test/flutter_test.dart'; 4 | 5 | // ignore: avoid_relative_lib_imports 6 | import '../lib/main_complex_example.dart'; 7 | 8 | void main() { 9 | testWidgets('Tests intercepting the back-button.', (WidgetTester tester) async { 10 | // 11 | // Pump Main to set up routes and show Home. 12 | await tester.pumpWidget(AnotherExample()); 13 | 14 | // Tap 'Open new screen' button to open NewScreen. 15 | Finder homeButtonFinder = find.widgetWithText(ElevatedButton, 'Open new screen'); 16 | expect(homeButtonFinder, isNotNull); 17 | 18 | await tester.tap(homeButtonFinder); 19 | await tester.pumpAndSettle(); 20 | 21 | // --- 22 | 23 | Finder newScreenButtonFinder = find.widgetWithText(ElevatedButton, 'Pop'); 24 | expect(newScreenButtonFinder, isNotNull); 25 | 26 | // Tap #1 -------------- 27 | await tester.tap(newScreenButtonFinder); 28 | await tester.pump(); 29 | 30 | InterceptorResults interceptorResults = BackButtonInterceptor.results; 31 | expect(interceptorResults.count, 1); 32 | expect(interceptorResults.ifDefaultButtonEventWasFired, false); 33 | 34 | expect(interceptorResults.getNamed('first')!.stopDefaultButtonEvent, false); 35 | expect(interceptorResults.getNamed('second')!.stopDefaultButtonEvent, false); 36 | expect(interceptorResults.getNamed('third')!.stopDefaultButtonEvent, true); 37 | 38 | // Tap #2 -------------- 39 | await tester.tap(newScreenButtonFinder); 40 | await tester.pump(); 41 | 42 | expect(interceptorResults.count, 2); 43 | expect(interceptorResults.ifDefaultButtonEventWasFired, false); 44 | 45 | expect(interceptorResults.getNamed('first')!.stopDefaultButtonEvent, false); 46 | expect(interceptorResults.getNamed('second')!.stopDefaultButtonEvent, true); 47 | expect(interceptorResults.getNamed('third')!.stopDefaultButtonEvent, false); 48 | 49 | // Tap #3 -------------- 50 | await tester.tap(newScreenButtonFinder); 51 | await tester.pump(); 52 | 53 | expect(interceptorResults.count, 3); 54 | expect(interceptorResults.ifDefaultButtonEventWasFired, false); 55 | 56 | expect(interceptorResults.getNamed('first')!.stopDefaultButtonEvent, true); 57 | expect(interceptorResults.getNamed('second')!.stopDefaultButtonEvent, false); 58 | expect(interceptorResults.getNamed('third')!.stopDefaultButtonEvent, false); 59 | 60 | // Tap #4 -------------- 61 | await tester.tap(newScreenButtonFinder); 62 | await tester.pumpAndSettle(); 63 | 64 | expect(interceptorResults.count, 4); 65 | expect(interceptorResults.ifDefaultButtonEventWasFired, true); 66 | 67 | expect(interceptorResults.getNamed('first')!.stopDefaultButtonEvent, false); 68 | expect(interceptorResults.getNamed('second')!.stopDefaultButtonEvent, false); 69 | expect(interceptorResults.getNamed('third')!.stopDefaultButtonEvent, false); 70 | }); 71 | } 72 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-App-20x20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-App-20x20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-App-29x29@1x.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-App-29x29@2x.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "29x29", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-App-29x29@3x.png", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-App-40x40@2x.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "40x40", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-App-40x40@3x.png", 43 | "scale" : "3x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-App-60x60@2x.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "60x60", 53 | "idiom" : "iphone", 54 | "filename" : "Icon-App-60x60@3x.png", 55 | "scale" : "3x" 56 | }, 57 | { 58 | "size" : "20x20", 59 | "idiom" : "ipad", 60 | "filename" : "Icon-App-20x20@1x.png", 61 | "scale" : "1x" 62 | }, 63 | { 64 | "size" : "20x20", 65 | "idiom" : "ipad", 66 | "filename" : "Icon-App-20x20@2x.png", 67 | "scale" : "2x" 68 | }, 69 | { 70 | "size" : "29x29", 71 | "idiom" : "ipad", 72 | "filename" : "Icon-App-29x29@1x.png", 73 | "scale" : "1x" 74 | }, 75 | { 76 | "size" : "29x29", 77 | "idiom" : "ipad", 78 | "filename" : "Icon-App-29x29@2x.png", 79 | "scale" : "2x" 80 | }, 81 | { 82 | "size" : "40x40", 83 | "idiom" : "ipad", 84 | "filename" : "Icon-App-40x40@1x.png", 85 | "scale" : "1x" 86 | }, 87 | { 88 | "size" : "40x40", 89 | "idiom" : "ipad", 90 | "filename" : "Icon-App-40x40@2x.png", 91 | "scale" : "2x" 92 | }, 93 | { 94 | "size" : "76x76", 95 | "idiom" : "ipad", 96 | "filename" : "Icon-App-76x76@1x.png", 97 | "scale" : "1x" 98 | }, 99 | { 100 | "size" : "76x76", 101 | "idiom" : "ipad", 102 | "filename" : "Icon-App-76x76@2x.png", 103 | "scale" : "2x" 104 | }, 105 | { 106 | "size" : "83.5x83.5", 107 | "idiom" : "ipad", 108 | "filename" : "Icon-App-83.5x83.5@2x.png", 109 | "scale" : "2x" 110 | }, 111 | { 112 | "size" : "1024x1024", 113 | "idiom" : "ios-marketing", 114 | "filename" : "Icon-App-1024x1024@1x.png", 115 | "scale" : "1x" 116 | } 117 | ], 118 | "info" : { 119 | "version" : 1, 120 | "author" : "xcode" 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /lib/src/merge_sort.dart: -------------------------------------------------------------------------------- 1 | /// Copied from algorithms.dart, Copyright (c) 2013, the Dart project authors. 2 | /// Sorts a list between [start] (inclusive) and [end] (exclusive) using the 3 | /// merge sort algorithm. 4 | /// If [compare] is omitted, this defaults to calling [Comparable.compareTo] on 5 | /// the objects. If any object is not [Comparable], this throws a [TypeError]. 6 | /// Merge-sorting works by splitting the job into two parts, sorting each 7 | /// recursively, and then merging the two sorted parts. 8 | /// This takes on the order of `n * log(n)` comparisons and moves to sort 9 | /// `n` elements, but requires extra space of about the same size as the list 10 | /// being sorted. 11 | /// This merge sort is stable: Equal elements end up in the same order 12 | /// as they started in. 13 | /// 14 | void stableSort(List list, {int start = 0, int? end, int Function(T a, T b)? compare}) { 15 | end ??= list.length; 16 | compare ??= defaultCompare(); 17 | 18 | int length = end - start; 19 | if (length < 2) return; 20 | if (length < _MERGE_SORT_LIMIT) { 21 | _insertionSort(list, compare: compare, start: start, end: end); 22 | return; 23 | } 24 | int middle = start + ((end - start) >> 1); 25 | int firstLength = middle - start; 26 | int secondLength = end - middle; 27 | var scratchSpace = List.filled(secondLength, list[start]); 28 | _mergeSort(list, compare, middle, end, scratchSpace, 0); 29 | int firstTarget = end - firstLength; 30 | _mergeSort(list, compare, start, middle, list, firstTarget); 31 | _merge(compare, list, firstTarget, end, scratchSpace, 0, secondLength, list, start); 32 | } 33 | 34 | /// Returns a [Comparator] that asserts that its first argument is comparable. 35 | Comparator defaultCompare() => (value1, value2) => (value1 as Comparable).compareTo(value2); 36 | 37 | /// Limit below which merge sort defaults to insertion sort. 38 | const int _MERGE_SORT_LIMIT = 32; 39 | 40 | void _insertionSort(List list, {int Function(T a, T b)? compare, int start = 0, int? end}) { 41 | compare ??= defaultCompare(); 42 | end ??= list.length; 43 | 44 | for (int pos = start + 1; pos < end; pos++) { 45 | int min = start; 46 | int max = pos; 47 | var element = list[pos]; 48 | while (min < max) { 49 | int mid = min + ((max - min) >> 1); 50 | int comparison = compare(element, list[mid]); 51 | if (comparison < 0) { 52 | max = mid; 53 | } else { 54 | min = mid + 1; 55 | } 56 | } 57 | list.setRange(min + 1, pos + 1, list, min); 58 | list[min] = element; 59 | } 60 | } 61 | 62 | void _movingInsertionSort(List list, int Function(T a, T b) compare, int start, int end, 63 | List target, int targetOffset) { 64 | int length = end - start; 65 | if (length == 0) return; 66 | target[targetOffset] = list[start]; 67 | for (int i = 1; i < length; i++) { 68 | var element = list[start + i]; 69 | int min = targetOffset; 70 | int max = targetOffset + i; 71 | while (min < max) { 72 | int mid = min + ((max - min) >> 1); 73 | if (compare(element, target[mid]) < 0) { 74 | max = mid; 75 | } else { 76 | min = mid + 1; 77 | } 78 | } 79 | target.setRange(min + 1, targetOffset + i + 1, target, min); 80 | target[min] = element; 81 | } 82 | } 83 | 84 | void _mergeSort(List list, int Function(T a, T b) compare, int start, int end, List target, 85 | int targetOffset) { 86 | int length = end - start; 87 | if (length < _MERGE_SORT_LIMIT) { 88 | _movingInsertionSort(list, compare, start, end, target, targetOffset); 89 | return; 90 | } 91 | int middle = start + (length >> 1); 92 | int firstLength = middle - start; 93 | int secondLength = end - middle; 94 | int targetMiddle = targetOffset + firstLength; 95 | _mergeSort(list, compare, middle, end, target, targetMiddle); 96 | _mergeSort(list, compare, start, middle, list, middle); 97 | _merge(compare, list, middle, middle + firstLength, target, targetMiddle, 98 | targetMiddle + secondLength, target, targetOffset); 99 | } 100 | 101 | void _merge(int Function(T a, T b) compare, List firstList, int firstStart, int firstEnd, 102 | List secondList, int secondStart, int secondEnd, List target, int targetOffset) { 103 | assert(firstStart < firstEnd); 104 | assert(secondStart < secondEnd); 105 | int cursor1 = firstStart; 106 | int cursor2 = secondStart; 107 | var firstElement = firstList[cursor1++]; 108 | var secondElement = secondList[cursor2++]; 109 | while (true) { 110 | if (compare(firstElement, secondElement) <= 0) { 111 | target[targetOffset++] = firstElement; 112 | if (cursor1 == firstEnd) break; // Flushing second list after loop. 113 | firstElement = firstList[cursor1++]; 114 | } else { 115 | target[targetOffset++] = secondElement; 116 | if (cursor2 != secondEnd) { 117 | secondElement = secondList[cursor2++]; 118 | continue; 119 | } 120 | target[targetOffset++] = firstElement; 121 | target.setRange(targetOffset, targetOffset + (firstEnd - cursor1), firstList, cursor1); 122 | return; 123 | } 124 | } 125 | target[targetOffset++] = secondElement; 126 | target.setRange(targetOffset, targetOffset + (secondEnd - cursor2), secondList, cursor2); 127 | } 128 | -------------------------------------------------------------------------------- /example/lib/main_complex_example.dart: -------------------------------------------------------------------------------- 1 | // Developed by Marcelo Glasberg (2019) https://glasberg.dev and https://github.com/marcglasberg 2 | // For more info, see: https://pub.dartlang.org/packages/back_button_interceptor 3 | import 'package:back_button_interceptor/back_button_interceptor.dart'; 4 | import 'package:flutter/material.dart'; 5 | 6 | /// The first screen has a button which opens a second screen. 7 | /// The second screen has 3 red squares. By tapping the Android back-button (or the "pop" button) 8 | /// each square turns blue, one by one. Only when all squares are blue, tapping the back-button 9 | /// once more will return to the previous screen. 10 | /// 11 | /// Please see tests at: back_button_interceptor/test/complex_example/main_test.dart 12 | /// 13 | void main() => runApp(AnotherExample()); 14 | 15 | class AnotherExample extends StatelessWidget { 16 | @override 17 | Widget build(BuildContext context) { 18 | return MaterialApp( 19 | routes: _createRoutes(), 20 | ); 21 | } 22 | 23 | Map _createRoutes() { 24 | return { 25 | RoutePaths.main: (_) => Home(), 26 | RoutePaths.newScreen: (_) => NewScreen(), 27 | }; 28 | } 29 | } 30 | 31 | class RoutePaths { 32 | RoutePaths._(); 33 | 34 | static const main = '/'; 35 | static const newScreen = '/new-screen'; 36 | } 37 | 38 | class Home extends StatelessWidget { 39 | @override 40 | Widget build(BuildContext context) { 41 | return Scaffold( 42 | backgroundColor: Colors.blue, 43 | body: Center( 44 | child: Column( 45 | mainAxisAlignment: MainAxisAlignment.center, 46 | children: [ 47 | const Padding( 48 | padding: EdgeInsets.all(50.0), 49 | child: Text( 50 | "The first screen has a button which opens a second screen.\n\n" 51 | "The second screen has 3 red squares. By tapping the Android back-button (or the 'pop' button) " 52 | "each square turns blue, one by one.\n\n" 53 | "Only when all squares are blue, tapping the back-button " 54 | "once more will return to the previous screen.", 55 | textAlign: TextAlign.center, 56 | ), 57 | ), 58 | ElevatedButton( 59 | onPressed: () => openNewScreen(context), 60 | child: const Text('Open new screen'), 61 | ), 62 | ], 63 | ), 64 | ), 65 | ); 66 | } 67 | 68 | void openNewScreen(BuildContext context) => Navigator.pushNamed(context, RoutePaths.newScreen); 69 | } 70 | 71 | class NewScreen extends StatelessWidget { 72 | // 73 | @override 74 | Widget build(BuildContext context) { 75 | return Scaffold( 76 | backgroundColor: Colors.green, 77 | body: Center( 78 | child: Column( 79 | mainAxisAlignment: MainAxisAlignment.center, 80 | children: [ 81 | const Row( 82 | mainAxisAlignment: MainAxisAlignment.center, 83 | children: [ 84 | ContainerWithInterceptor("first"), 85 | SizedBox(width: 20), 86 | ContainerWithInterceptor("second"), 87 | SizedBox(width: 20), 88 | ContainerWithInterceptor("third"), 89 | ], 90 | ), 91 | const SizedBox(height: 40), 92 | const ElevatedButton( 93 | onPressed: BackButtonInterceptor.popRoute, 94 | child: Text('Pop'), 95 | ), 96 | ElevatedButton( 97 | onPressed: () => _openDialog(context), 98 | child: const Text('Open Dialog'), 99 | ), 100 | ], 101 | ), 102 | ), 103 | ); 104 | } 105 | 106 | void _openDialog(BuildContext context) { 107 | showDialog( 108 | context: context, 109 | builder: (context) => const AlertDialog( 110 | title: Text("My Dialog"), 111 | content: Text("Click outside to close it, or use the back-button."), 112 | ), 113 | ); 114 | } 115 | } 116 | 117 | class ContainerWithInterceptor extends StatefulWidget { 118 | // 119 | final String name; 120 | 121 | const ContainerWithInterceptor(this.name); 122 | 123 | @override 124 | State createState() => _ContainerWithInterceptorState(); 125 | } 126 | 127 | class _ContainerWithInterceptorState extends State { 128 | bool ifPop = false; 129 | 130 | void pop() => setState(() => ifPop = true); 131 | 132 | @override 133 | void initState() { 134 | super.initState(); 135 | ifPop = false; 136 | BackButtonInterceptor.add(myInterceptor, name: widget.name, context: context); 137 | } 138 | 139 | @override 140 | void dispose() { 141 | BackButtonInterceptor.remove(myInterceptor); 142 | super.dispose(); 143 | } 144 | 145 | @override 146 | Widget build(BuildContext context) { 147 | return Container( 148 | decoration: BoxDecoration(color: ifPop ? Colors.blue : Colors.red), 149 | height: 50, 150 | width: 70, 151 | ); 152 | } 153 | 154 | bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { 155 | if (stopDefaultButtonEvent) return false; 156 | 157 | // If a dialog (or any other route) is open, don't run the interceptor. 158 | if (info.ifRouteChanged(context)) return false; 159 | 160 | if (ifPop) 161 | return false; 162 | else { 163 | pop(); 164 | return true; 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /example/lib/main_complex_example_routes_not_named.dart: -------------------------------------------------------------------------------- 1 | // Developed by Marcelo Glasberg (2019) https://glasberg.dev and https://github.com/marcglasberg 2 | // For more info, see: https://pub.dartlang.org/packages/back_button_interceptor 3 | import 'package:back_button_interceptor/back_button_interceptor.dart'; 4 | import 'package:flutter/material.dart'; 5 | 6 | /// The first screen has a button which opens a second screen. 7 | /// The second screen has 3 red squares. By tapping the Android back-button (or the "pop" button) 8 | /// each square turns blue, one by one. Only when all squares are blue, tapping the back-button 9 | /// once more will return to the previous screen. 10 | /// 11 | /// Please see tests at: back_button_interceptor/test/complex_example/main_test.dart 12 | /// 13 | void main() => runApp(AnotherExample()); 14 | 15 | class AnotherExample extends StatelessWidget { 16 | @override 17 | Widget build(BuildContext context) { 18 | return MaterialApp( 19 | // This is removed: 20 | // routes: _createRoutes(), 21 | initialRoute: '/', 22 | onGenerateRoute: (RouteSettings settings) => PageRouteBuilder( 23 | barrierDismissible: true, 24 | opaque: false, 25 | pageBuilder: (context, _, __) => Home(), 26 | ), 27 | ); 28 | } 29 | 30 | // This is removed: 31 | // Map _createRoutes() { 32 | // return { 33 | // RoutePaths.main: (_) => Home(), 34 | // RoutePaths.newScreen: (_) => NewScreen(), 35 | // }; 36 | // } 37 | } 38 | 39 | class RoutePaths { 40 | RoutePaths._(); 41 | 42 | // This is removed: 43 | // static const main = '/'; 44 | // static const newScreen = '/new-screen'; 45 | } 46 | 47 | class Home extends StatelessWidget { 48 | @override 49 | Widget build(BuildContext context) { 50 | return Scaffold( 51 | backgroundColor: Colors.blue, 52 | body: Center( 53 | child: Column( 54 | mainAxisAlignment: MainAxisAlignment.center, 55 | children: [ 56 | const Text( 57 | "Same example,\nbut routes are not named.", 58 | textAlign: TextAlign.center, 59 | ), 60 | const SizedBox(height: 40.0), 61 | ElevatedButton( 62 | onPressed: () => openNewScreen(context), 63 | child: const Text('Open new screen'), 64 | ), 65 | ], 66 | ), 67 | ), 68 | ); 69 | } 70 | 71 | // void openNewScreen(BuildContext context) => Navigator.pushNamed(context, RoutePaths.newScreen); 72 | void openNewScreen(BuildContext context) => Navigator.push( 73 | context, 74 | PageRouteBuilder( 75 | barrierDismissible: true, 76 | opaque: false, 77 | pageBuilder: (context, _, __) => NewScreen(), 78 | ), 79 | ); 80 | } 81 | 82 | class NewScreen extends StatelessWidget { 83 | // 84 | @override 85 | Widget build(BuildContext context) { 86 | return Scaffold( 87 | backgroundColor: Colors.green, 88 | body: Center( 89 | child: Column( 90 | mainAxisAlignment: MainAxisAlignment.center, 91 | children: [ 92 | const Row( 93 | mainAxisAlignment: MainAxisAlignment.center, 94 | children: [ 95 | ContainerWithInterceptor("first"), 96 | SizedBox(width: 20), 97 | ContainerWithInterceptor("second"), 98 | SizedBox(width: 20), 99 | ContainerWithInterceptor("third"), 100 | ], 101 | ), 102 | const SizedBox(height: 40), 103 | const ElevatedButton( 104 | onPressed: BackButtonInterceptor.popRoute, 105 | child: Text('Pop'), 106 | ), 107 | ElevatedButton( 108 | onPressed: () => _openDialog(context), 109 | child: const Text('Open Dialog'), 110 | ), 111 | ], 112 | ), 113 | ), 114 | ); 115 | } 116 | 117 | void _openDialog(BuildContext context) { 118 | showDialog( 119 | context: context, 120 | builder: (context) => const AlertDialog( 121 | title: Text("My Dialog"), 122 | content: Text("Click outside to close it, or use the back-button."), 123 | ), 124 | ); 125 | } 126 | } 127 | 128 | class ContainerWithInterceptor extends StatefulWidget { 129 | // 130 | final String name; 131 | 132 | const ContainerWithInterceptor(this.name); 133 | 134 | @override 135 | State createState() => _ContainerWithInterceptorState(); 136 | } 137 | 138 | class _ContainerWithInterceptorState extends State { 139 | bool ifPop = false; 140 | 141 | void pop() => setState(() => ifPop = true); 142 | 143 | @override 144 | void initState() { 145 | super.initState(); 146 | ifPop = false; 147 | BackButtonInterceptor.add(myInterceptor, name: widget.name, context: context); 148 | } 149 | 150 | @override 151 | void dispose() { 152 | BackButtonInterceptor.remove(myInterceptor); 153 | super.dispose(); 154 | } 155 | 156 | @override 157 | Widget build(BuildContext context) { 158 | return Container( 159 | decoration: BoxDecoration(color: ifPop ? Colors.blue : Colors.red), 160 | height: 50, 161 | width: 70, 162 | ); 163 | } 164 | 165 | bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { 166 | if (stopDefaultButtonEvent) return false; 167 | 168 | // If a dialog (or any other route) is open, don't run the interceptor. 169 | if (info.ifRouteChanged(context)) return false; 170 | 171 | if (ifPop) 172 | return false; 173 | else { 174 | pop(); 175 | return true; 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](./example/SponsoredByMyTextAi.png)](https://mytext.ai) 2 | 3 | [![Pub popularity](https://badgen.net/pub/popularity/back_button_interceptor)](https://pub.dev/packages/back_button_interceptor) 4 | [![Pub Version](https://img.shields.io/pub/v/back_button_interceptor?style=flat-square&logo=dart)](https://pub.dev/packages/back_button_interceptor) 5 | [![GitHub stars](https://img.shields.io/github/stars/marcglasberg/back_button_interceptor?style=social)](https://github.com/marcglasberg/back_button_interceptor) 6 | ![Code Climate issues](https://img.shields.io/github/issues/marcglasberg/back_button_interceptor?style=flat-square) 7 | ![GitHub closed issues](https://img.shields.io/github/issues-closed/marcglasberg/back_button_interceptor?style=flat-square) 8 | ![GitHub contributors](https://img.shields.io/github/contributors/marcglasberg/back_button_interceptor?style=flat-square) 9 | ![GitHub repo size](https://img.shields.io/github/repo-size/marcglasberg/back_button_interceptor?style=flat-square) 10 | ![GitHub forks](https://img.shields.io/github/forks/marcglasberg/back_button_interceptor?style=flat-square) 11 | ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square) 12 | [![Developed by Marcelo Glasberg](https://img.shields.io/badge/Developed%20by%20Marcelo%20Glasberg-blue.svg)](https://glasberg.dev/) 13 | [![Glasberg.dev on pub.dev](https://img.shields.io/pub/publisher/async_redux.svg)](https://pub.dev/publishers/glasberg.dev/packages) 14 | [![Platforms](https://badgen.net/pub/flutter-platform/back_button_interceptor)](https://pub.dev/packages/back_button_interceptor) 15 | 16 | # back_button_interceptor 17 | 18 | In simple cases, when you need to intercept the Android back-button, you usually add `WillPopScope` 19 | to your widget tree. However, when developing stateful widgets that interact with the back button, 20 | it's more convenient to use the `BackButtonInterceptor`. 21 | 22 | You may add **interceptor functions** to be called when the back button is tapped. These functions 23 | may perform some useful work, and then, if any of them return `true`, the default button process 24 | (usually popping a Route) will not be fired. 25 | 26 | ## Android 13 27 | 28 | To make it work on Android 13 and up, set this to `false` in the Android manifest: 29 | 30 | ``` 31 | android:enableOnBackInvokedCallback="false" 32 | ``` 33 | 34 | ## In more detail 35 | 36 | All added functions are called, in order. If any function returns `true`, the 37 | combined result is `true`, and the default button process will NOT be fired. Only if all functions 38 | return `false` (or `null`), the combined result is `false`, and the default button process will be 39 | fired. 40 | 41 | Optionally, you may provide a **z-index**. Functions with a valid z-index will be called before 42 | functions with a null z-index, and functions with larger z-index will be called first. When they 43 | have the same z-index, functions added last are called first. 44 | 45 | Each function gets the boolean `stopDefaultButtonEvent` that indicates the current combined result 46 | from all the previous functions. So, if some function doesn't want to fire if some other previous 47 | function already fired, it can do: 48 | 49 | if (stopDefaultButtonEvent) return false; 50 | 51 | The same result may be obtained if the optional `ifNotYetIntercepted` parameter is true. Then the 52 | function will only be called if all previous functions returned false 53 | (that is, if `stopDefaultButtonEvent` is false). 54 | 55 | ### Notes 56 | 57 | * After you've finished you MUST remove each function by calling the `remove()` method. 58 | Alternatively, you may also provide a `name` when adding a function, and then later remove it by 59 | calling the `removeByName(name)` method. 60 | 61 | * If any of your interceptors throw an error, the error message will be printed to the console, but 62 | the error thrown will be a general error with not much information. You can change the treatment 63 | of errors by changing the static `errorProcessing` field. 64 | 65 | * Your functions can also process information about routes by using the function's `RouteInfo info` 66 | parameter. To get the current route in the navigator, call `info.currentRoute(context)`. 67 | Also, `info.routeWhenAdded` contains the route that was the current one when the interceptor was 68 | added through the `BackButtonInterceptor.add()` method. 69 | 70 | * You can set up some function so that it only runs when the current route is the same route of when 71 | the interceptor was created. To that end, you can use 72 | `info.ifRouteChanged()` method: 73 | 74 | ``` 75 | bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { 76 | if (info.ifRouteChanged(context)) return false; 77 | ... 78 | } 79 | ``` 80 | 81 | This means the interceptor function is temporarily disabled while, for example, a dialog is open. 82 | 83 | * You can set up some function so that it only runs in certain routes: 84 | 85 | ``` 86 | bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { 87 | if (["myRoute1", "myRoute2", "myRoute3"] 88 | .contains(info.currentRoute(context))) return false; 89 | ... 90 | } 91 | ``` 92 | 93 | * Both `info.routeWhenAdded` and `info.ifRouteChanged()` only work if you passed the `context` 94 | parameter to the `BackButtonInterceptor.add()` method. Otherwise, `info.routeWhenAdded` will 95 | be `null` and `info.ifRouteChanged()` 96 | will thrown an error. 97 | 98 | * The current route can also be obtained by using the static 99 | method `BackButtonInterceptor.getCurrentNavigatorRouteName(context)`. 100 | 101 | * The interceptor function can return `bool` or `Future`. 102 | 103 | --- 104 | 105 | ## Examples 106 | 107 | ### Intercepting 108 | 109 | @override 110 | void initState() { 111 | super.initState(); 112 | BackButtonInterceptor.add(myInterceptor); 113 | } 114 | 115 | @override 116 | void dispose() { 117 | BackButtonInterceptor.remove(myInterceptor); 118 | super.dispose(); 119 | } 120 | 121 | bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { 122 | print("BACK BUTTON!"); // Do some stuff. 123 | return true; 124 | } 125 | 126 | ### Named function and z-index 127 | 128 | @override 129 | void initState() { 130 | super.initState(); 131 | BackButtonInterceptor.add(myInterceptor, zIndex:2, name:"SomeName"); 132 | } 133 | 134 | @override 135 | void dispose() { 136 | BackButtonInterceptor.removeByName("SomeName"); 137 | super.dispose(); 138 | } 139 | 140 | bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { 141 | print("BACK BUTTON!"); // Do some stuff. 142 | return true; 143 | } 144 | 145 | ### Runnable Examples 146 | 147 | 1. 148 | main 149 | 150 | Intercepts the back-button and prints a string to the console. 151 | 152 | 2. 153 | main 154 | 155 | Intercepts the back-button and prints a string to the console, by using an async interceptor 156 | function. 157 | 158 | 3. 159 | main_complex_example 160 | 161 | The first screen has a button which opens a second screen. The second screen has 3 red squares. 162 | By tapping the Android back-button (or the "pop" button) each square turns blue, one by one. Only 163 | when all squares are blue, tapping the back-button once more will return to the previous screen. 164 | Also, if you click the "Open Dialog" button, the interceptors are disabled while the dialog is 165 | open. 166 | 167 | 4. 168 | main_complex_example_test 169 | 170 | This package is test friendly, and this examples shows how to test the back button. 171 | 172 | ## Testing 173 | 174 | For testing purposes, the `BackButtonInterceptor.popRoute()` method may be called directly, to 175 | simulate pressing the back button. The list of all fired functions and their results is 176 | recorded in the `BackButtonInterceptor.results` static variable. 177 | 178 | _Note:_ You may want to add `BackButtonInterceptor.removeAll();` 179 | to your test's `setUp` function, so that you remove old interceptors between tests. 180 | 181 | ## Debugging 182 | 183 | In complex cases, to make it easier for you to debug your interceptors, you may print them to the 184 | console, with their names and z-indexes, by doing: 185 | 186 | ``` 187 | print(BackButtonInterceptor.describe()); 188 | ``` 189 | 190 | ## Incompatibilities 191 | 192 | This package is currently incompatible with deep links of the GoRouter package. 193 | 194 | ## See also: 195 | 196 | * https://docs.flutter.io/flutter/widgets/WillPopScope-class.html 197 | * https://stackoverflow.com/questions/45916658/de-activate-system-back-button-in-flutter-app-toddler-navigation 198 | 199 | *** 200 | 201 | ## By Marcelo Glasberg 202 | 203 | _glasberg.dev_ 204 |
205 | _github.com/marcglasberg_ 206 |
207 | _linkedin.com/in/marcglasberg/_ 208 |
209 | _twitter.com/glasbergmarcelo_ 210 |
211 | 212 | _stackoverflow.com/users/3411681/marcg_ 213 |
214 | _medium.com/@marcglasberg_ 215 |
216 | 217 | *My article in the official Flutter documentation*: 218 | 219 | * Understanding 220 | constraints 221 | 222 | *The Flutter packages I've authored:* 223 | 224 | * async_redux 225 | * provider_for_redux 226 | * i18n_extension 227 | * align_positioned 228 | * network_to_file_image 229 | * image_pixels 230 | * matrix4_transform 231 | * back_button_interceptor 232 | * indexed_list_view 233 | * animated_size_and_fade 234 | * assorted_layout_widgets 235 | * weak_map 236 | * themed 237 | * bdd_framework 238 | * 239 | tiktoken_tokenizer_gpt4o_o1 240 | 241 | *My Medium Articles:* 242 | 243 | * 244 | Async Redux: Flutter’s non-boilerplate version of Redux 245 | (versions: 246 | Português) 247 | * 248 | i18n_extension 249 | (versions: 250 | Português) 251 | * 252 | Flutter: The Advanced Layout Rule Even Beginners Must Know 253 | (versions: русский) 254 | * 255 | The New Way to create Themes in your Flutter App 256 | -------------------------------------------------------------------------------- /lib/src/back_button_interceptor.dart: -------------------------------------------------------------------------------- 1 | // Developed by Marcelo Glasberg (2019) https://glasberg.dev and https://github.com/marcglasberg 2 | // For more info, see: https://pub.dartlang.org/packages/back_button_interceptor 3 | library back_button_interceptor; 4 | 5 | import 'dart:async'; 6 | 7 | import 'package:collection/collection.dart' show IterableExtension; 8 | import 'package:flutter/material.dart'; 9 | import 'package:flutter/services.dart'; 10 | 11 | import 'merge_sort.dart'; 12 | 13 | /// When you need to intercept the Android back-button, you usually add `WillPopScope` to your 14 | /// widget tree. However, under some use cases, specially when developing stateful widgets that 15 | /// interact with the back button, it's more convenient to use the `BackButtonInterceptor`. 16 | /// 17 | /// For more info, see: https://pub.dartlang.org/packages/back_button_interceptor 18 | abstract class BackButtonInterceptor implements WidgetsBinding { 19 | static final List<_FunctionWithZIndex> _interceptors = []; 20 | static final InterceptorResults results = InterceptorResults(); 21 | 22 | static Function(Object, StackTrace) errorProcessing = _errorProcessing; 23 | 24 | static void _errorProcessing(Object error, StackTrace stackTrace) { 25 | print("The BackButtonInterceptor threw an ERROR: $error."); 26 | Future.delayed(const Duration(), () => Error.throwWithStackTrace(error, stackTrace)); 27 | } 28 | 29 | static Future Function() handlePopRouteFunction = WidgetsBinding.instance.handlePopRoute; 30 | 31 | static Future Function(String?) handlePushRouteFunction = 32 | WidgetsBinding.instance.handlePushRoute as Future Function(String?); 33 | 34 | /// Sets a function of type [InterceptorFunction] to be called when the back button is tapped. 35 | /// This function may perform some useful work, and then, if it returns `true`, 36 | /// the default button process (usually popping a Route) will NOT be fired. 37 | /// 38 | /// Functions added last are called first. 39 | /// 40 | /// If the optional [ifNotYetIntercepted] parameter is true, then the function will only be 41 | /// called if all previous functions returned `false` (that is, `stopDefaultButtonEvent` is 42 | /// `false`). 43 | /// 44 | /// Optionally, you may provide a [zIndex]. Functions with a valid z-index will be called before 45 | /// functions with a null z-index, and functions with larger z-index will be called first. 46 | /// When they have the same z-index, functions added last are called first. 47 | /// 48 | /// Optionally, you may provide a [name]. This is useful if you later want to removes the 49 | /// function by name by using the [removeByName] method. 50 | /// 51 | /// You can also provide the current [context]. That's optional, and you only need to do this if 52 | /// later you want to use [RouteInfo.ifRouteChanged]. 53 | /// 54 | static void add( 55 | InterceptorFunction interceptorFunction, { 56 | bool ifNotYetIntercepted = false, 57 | int? zIndex, 58 | String? name, 59 | BuildContext? context, 60 | }) { 61 | _interceptors.insert( 62 | 0, 63 | _FunctionWithZIndex( 64 | interceptorFunction, 65 | ifNotYetIntercepted, 66 | zIndex, 67 | name, 68 | (context == null) ? null : getCurrentNavigatorRoute(context), 69 | )); 70 | stableSort(_interceptors); 71 | SystemChannels.navigation.setMethodCallHandler(_handleNavigationInvocation); 72 | } 73 | 74 | /// Removes the function, by reference. 75 | /// Example: 76 | /// 77 | /// ``` 78 | /// void initState() { 79 | /// super.initState(); 80 | /// BackButtonInterceptor.add(_onBackButton); 81 | /// } 82 | /// 83 | /// void dispose() { 84 | /// BackButtonInterceptor.remove(_onBackButton); 85 | /// super.dispose(); 86 | /// } 87 | /// 88 | /// bool _onBackButton(bool stopDefaultButtonEvent, RouteInfo info) { ... } 89 | /// ``` 90 | /// 91 | static void remove(InterceptorFunction interceptorFunction) { 92 | _interceptors 93 | .removeWhere((interceptor) => interceptor.interceptionFunction == interceptorFunction); 94 | } 95 | 96 | /// Removes the function, by name. 97 | /// Example: 98 | /// 99 | /// ``` 100 | /// void initState() { 101 | /// super.initState(); 102 | /// BackButtonInterceptor.add(_onBackButton, name: 'myInterceptor'); 103 | /// } 104 | /// 105 | /// void dispose() { 106 | /// BackButtonInterceptor.removeByName('myInterceptor'); 107 | /// super.dispose(); 108 | /// } 109 | /// 110 | /// bool _onBackButton(bool stopDefaultButtonEvent, RouteInfo info) { ... } 111 | /// ``` 112 | /// 113 | static void removeByName(String name) { 114 | _interceptors.removeWhere((interceptor) => interceptor.name == name); 115 | } 116 | 117 | /// Removes all functions. 118 | /// Example: 119 | /// 120 | /// ``` 121 | /// void initState() { 122 | /// super.initState(); 123 | /// BackButtonInterceptor.add(_onBackButton); 124 | /// } 125 | /// 126 | /// void dispose() { 127 | /// // Not recommended, because it will remove all functions, 128 | /// // not only the one created above. 129 | /// BackButtonInterceptor.removeAll(); 130 | /// super.dispose(); 131 | /// } 132 | /// 133 | /// bool _onBackButton(bool stopDefaultButtonEvent, RouteInfo info) { ... } 134 | /// ``` 135 | /// 136 | static void removeAll() { 137 | _interceptors.clear(); 138 | } 139 | 140 | /// Gets the current navigator route. 141 | /// 142 | /// Trick explained here: https://github.com/flutter/flutter/issues/20451 143 | /// Note `ModalRoute.of(context).settings.name` doesn't always work. 144 | static Route? getCurrentNavigatorRoute(BuildContext context) { 145 | Route? currentRoute; 146 | Navigator.popUntil(context, (route) { 147 | currentRoute = route; 148 | return true; 149 | }); 150 | return currentRoute; 151 | } 152 | 153 | /// Gets the name of the current navigator route. 154 | /// 155 | /// Trick explained here: https://github.com/flutter/flutter/issues/20451 156 | /// Note `ModalRoute.of(context).settings.name` doesn't always work. 157 | static String? getCurrentNavigatorRouteName(BuildContext context) => 158 | getCurrentNavigatorRoute(context)!.settings.name; 159 | 160 | /// Gets the current navigator route, if that route has a name. 161 | /// If it doesn't have a name, it will go back until it finds a route with a name. 162 | /// This can be helpful if you are in a dialog or bottom sheet, and you want to know 163 | /// the route of the screen it's in. 164 | static Route? getInnermostNamedNavigatorRoute(BuildContext context) { 165 | Route? currentRoute; 166 | Navigator.popUntil(context, (Route route) { 167 | currentRoute = route; 168 | 169 | return (route.settings.name != null) && (route.settings.name!.isNotEmpty); 170 | }); 171 | return currentRoute; 172 | } 173 | 174 | /// Gets the name of the current navigator route, if that route has a name. 175 | /// If it doesn't have a name, it will go back until it finds a route with a name. 176 | /// This can be helpful if you are in a dialog or bottom sheet, and you want to know 177 | /// the name of the route of the screen it's in. 178 | static String? getInnermostNamedNavigatorRouteName(BuildContext context) => 179 | getInnermostNamedNavigatorRoute(context)!.settings.name; 180 | 181 | static Future _handleNavigationInvocation(MethodCall methodCall) async { 182 | // POP. 183 | if (methodCall.method == 'popRoute') 184 | return popRoute(); 185 | 186 | // PUSH. 187 | else if (methodCall.method == 'pushRoute') 188 | return _pushRoute(methodCall.arguments); 189 | 190 | // OTHER. 191 | else 192 | return Future.value(); 193 | } 194 | 195 | /// All functions are called, in order. 196 | /// If any function returns true, the combined result is true, 197 | /// and the default button process will NOT be fired. 198 | /// 199 | /// Only if all functions return false (or null), the combined result is false, 200 | /// and the default button process will be fired. 201 | /// 202 | /// Each function gets a boolean that indicates the current combined result 203 | /// from the previous functions. 204 | /// 205 | /// Note: If the interceptor throws an error, a message will be printed to the 206 | /// console, and a placeholder error will not be thrown. You can change the 207 | /// treatment of errors by changing the static errorProcessing field. 208 | static Future popRoute() async { 209 | bool stopDefaultButtonEvent = false; 210 | 211 | results.clear(); 212 | 213 | List<_FunctionWithZIndex> interceptors = List.of(_interceptors); 214 | 215 | for (var i = 0; i < interceptors.length; i++) { 216 | bool? result; 217 | 218 | try { 219 | var interceptor = interceptors[i]; 220 | 221 | if (!interceptor.ifNotYetIntercepted || !stopDefaultButtonEvent) { 222 | FutureOr _result = interceptor.interceptionFunction( 223 | stopDefaultButtonEvent, 224 | RouteInfo(routeWhenAdded: interceptor.routeWhenAdded), 225 | ); 226 | 227 | if (_result is bool) 228 | result = _result; 229 | // ignore: unnecessary_type_check 230 | else if (_result is Future) 231 | result = await _result; 232 | else 233 | throw AssertionError(_result.runtimeType); 234 | 235 | results.results.add(InterceptorResult(interceptor.name, result)); 236 | } 237 | } catch (error, stackTrace) { 238 | errorProcessing(error, stackTrace); 239 | } 240 | 241 | if (result == true) stopDefaultButtonEvent = true; 242 | } 243 | 244 | if (stopDefaultButtonEvent) 245 | return Future.value(); 246 | else { 247 | results.ifDefaultButtonEventWasFired = true; 248 | return handlePopRouteFunction(); 249 | } 250 | } 251 | 252 | static Future _pushRoute(dynamic arguments) => 253 | handlePushRouteFunction(arguments as String?); 254 | 255 | /// Describes all interceptors, with their names and z-indexes. 256 | /// This may help you debug your interceptors, by printing them 257 | /// to the console, like this: 258 | /// `print(BackButtonInterceptor.describe());` 259 | static String describe() => _interceptors.join("\n"); 260 | } 261 | 262 | typedef InterceptorFunction = FutureOr Function( 263 | bool stopDefaultButtonEvent, 264 | RouteInfo routeInfo, 265 | ); 266 | 267 | /// Your functions can also process information about routes by using the function's RouteInfo info 268 | /// parameter. To get the current route in the navigator, call `info.currentRoute(context)`. 269 | /// Also, `info.routeWhenAdded` contains the route that was the current one when the interceptor 270 | /// was added through the `BackButtonInterceptor.add()` method. 271 | class RouteInfo { 272 | // 273 | 274 | /// The current route when the interceptor was added 275 | /// through the BackButtonInterceptor.add() method. 276 | final Route? routeWhenAdded; 277 | 278 | RouteInfo({this.routeWhenAdded}); 279 | 280 | Route? currentRoute(BuildContext context) => 281 | BackButtonInterceptor.getCurrentNavigatorRoute(context); 282 | 283 | /// Return true if the current route is NOT the same route of when the interceptor was created. 284 | /// 285 | /// This is useful if you want to create an interceptor that only runs when the current route is 286 | /// the same route of when the interceptor was created: 287 | /// ``` 288 | /// bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) { 289 | /// if (info.ifRouteChanged(context)) return false; 290 | /// ... 291 | /// } 292 | /// ``` 293 | /// 294 | /// This method can only be called if the [context] parameter was 295 | /// passed to the [BackButtonInterceptor.add] method. 296 | /// 297 | bool ifRouteChanged(BuildContext context) { 298 | if (routeWhenAdded == null) 299 | throw AssertionError("The ifRouteChanged() method " 300 | "can only be called if the context parameter was " 301 | "passed to the BackButtonInterceptor.add() method."); 302 | 303 | return !identical(currentRoute(context), routeWhenAdded); 304 | } 305 | } 306 | 307 | class InterceptorResult { 308 | String? name; 309 | bool? stopDefaultButtonEvent; 310 | 311 | InterceptorResult(this.name, this.stopDefaultButtonEvent); 312 | } 313 | 314 | class InterceptorResults { 315 | int count = 0; 316 | List results = []; 317 | bool ifDefaultButtonEventWasFired = false; 318 | 319 | void clear() { 320 | results = []; 321 | ifDefaultButtonEventWasFired = false; 322 | count++; 323 | } 324 | 325 | InterceptorResult? getNamed(String name) => 326 | results.firstWhereOrNull((result) => result.name == name); 327 | } 328 | 329 | class _FunctionWithZIndex implements Comparable<_FunctionWithZIndex> { 330 | final InterceptorFunction interceptionFunction; 331 | final bool ifNotYetIntercepted; 332 | final int? zIndex; 333 | final String? name; 334 | final Route? routeWhenAdded; 335 | 336 | _FunctionWithZIndex( 337 | this.interceptionFunction, 338 | this.ifNotYetIntercepted, 339 | this.zIndex, 340 | this.name, 341 | this.routeWhenAdded, 342 | ); 343 | 344 | @override 345 | int compareTo(_FunctionWithZIndex other) { 346 | if (zIndex == null && other.zIndex == null) 347 | return 0; 348 | else if (zIndex == null && other.zIndex != null) 349 | return 1; 350 | else if (zIndex != null && other.zIndex == null) 351 | return -1; 352 | else 353 | return other.zIndex!.compareTo(zIndex!); 354 | } 355 | 356 | @override 357 | String toString() => 358 | 'BackButtonInterceptor: $name, z-index: $zIndex (ifNotYetIntercepted: $ifNotYetIntercepted).'; 359 | } 360 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 11 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; 12 | 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; 13 | 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 14 | 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; 15 | 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 16 | 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; 17 | 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 18 | 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; 19 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 20 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 21 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXCopyFilesBuildPhase section */ 25 | 9705A1C41CF9048500538489 /* Embed Frameworks */ = { 26 | isa = PBXCopyFilesBuildPhase; 27 | buildActionMask = 2147483647; 28 | dstPath = ""; 29 | dstSubfolderSpec = 10; 30 | files = ( 31 | 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, 32 | 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, 33 | ); 34 | name = "Embed Frameworks"; 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXCopyFilesBuildPhase section */ 38 | 39 | /* Begin PBXFileReference section */ 40 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 41 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 42 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 43 | 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 44 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 45 | 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 46 | 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 47 | 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 48 | 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 49 | 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 50 | 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 51 | 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 52 | 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 53 | 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 54 | 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 55 | 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 56 | /* End PBXFileReference section */ 57 | 58 | /* Begin PBXFrameworksBuildPhase section */ 59 | 97C146EB1CF9000F007C117D /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, 64 | 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | /* End PBXFrameworksBuildPhase section */ 69 | 70 | /* Begin PBXGroup section */ 71 | 9740EEB11CF90186004384FC /* Flutter */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 3B80C3931E831B6300D905FE /* App.framework */, 75 | 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, 76 | 9740EEBA1CF902C7004384FC /* Flutter.framework */, 77 | 9740EEB21CF90195004384FC /* Debug.xcconfig */, 78 | 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 79 | 9740EEB31CF90195004384FC /* Generated.xcconfig */, 80 | ); 81 | name = Flutter; 82 | sourceTree = ""; 83 | }; 84 | 97C146E51CF9000F007C117D = { 85 | isa = PBXGroup; 86 | children = ( 87 | 9740EEB11CF90186004384FC /* Flutter */, 88 | 97C146F01CF9000F007C117D /* Runner */, 89 | 97C146EF1CF9000F007C117D /* Products */, 90 | CF3B75C9A7D2FA2A4C99F110 /* Frameworks */, 91 | ); 92 | sourceTree = ""; 93 | }; 94 | 97C146EF1CF9000F007C117D /* Products */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 97C146EE1CF9000F007C117D /* Runner.app */, 98 | ); 99 | name = Products; 100 | sourceTree = ""; 101 | }; 102 | 97C146F01CF9000F007C117D /* Runner */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, 106 | 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, 107 | 97C146FA1CF9000F007C117D /* Main.storyboard */, 108 | 97C146FD1CF9000F007C117D /* Assets.xcassets */, 109 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, 110 | 97C147021CF9000F007C117D /* Info.plist */, 111 | 97C146F11CF9000F007C117D /* Supporting Files */, 112 | 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, 113 | 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, 114 | ); 115 | path = Runner; 116 | sourceTree = ""; 117 | }; 118 | 97C146F11CF9000F007C117D /* Supporting Files */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 97C146F21CF9000F007C117D /* main.m */, 122 | ); 123 | name = "Supporting Files"; 124 | sourceTree = ""; 125 | }; 126 | /* End PBXGroup section */ 127 | 128 | /* Begin PBXNativeTarget section */ 129 | 97C146ED1CF9000F007C117D /* Runner */ = { 130 | isa = PBXNativeTarget; 131 | buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; 132 | buildPhases = ( 133 | 9740EEB61CF901F6004384FC /* Run Script */, 134 | 97C146EA1CF9000F007C117D /* Sources */, 135 | 97C146EB1CF9000F007C117D /* Frameworks */, 136 | 97C146EC1CF9000F007C117D /* Resources */, 137 | 9705A1C41CF9048500538489 /* Embed Frameworks */, 138 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */, 139 | ); 140 | buildRules = ( 141 | ); 142 | dependencies = ( 143 | ); 144 | name = Runner; 145 | productName = Runner; 146 | productReference = 97C146EE1CF9000F007C117D /* Runner.app */; 147 | productType = "com.apple.product-type.application"; 148 | }; 149 | /* End PBXNativeTarget section */ 150 | 151 | /* Begin PBXProject section */ 152 | 97C146E61CF9000F007C117D /* Project object */ = { 153 | isa = PBXProject; 154 | attributes = { 155 | LastUpgradeCheck = 1020; 156 | ORGANIZATIONNAME = "The Chromium Authors"; 157 | TargetAttributes = { 158 | 97C146ED1CF9000F007C117D = { 159 | CreatedOnToolsVersion = 7.3.1; 160 | }; 161 | }; 162 | }; 163 | buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; 164 | compatibilityVersion = "Xcode 3.2"; 165 | developmentRegion = en; 166 | hasScannedForEncodings = 0; 167 | knownRegions = ( 168 | en, 169 | Base, 170 | ); 171 | mainGroup = 97C146E51CF9000F007C117D; 172 | productRefGroup = 97C146EF1CF9000F007C117D /* Products */; 173 | projectDirPath = ""; 174 | projectRoot = ""; 175 | targets = ( 176 | 97C146ED1CF9000F007C117D /* Runner */, 177 | ); 178 | }; 179 | /* End PBXProject section */ 180 | 181 | /* Begin PBXResourcesBuildPhase section */ 182 | 97C146EC1CF9000F007C117D /* Resources */ = { 183 | isa = PBXResourcesBuildPhase; 184 | buildActionMask = 2147483647; 185 | files = ( 186 | 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 187 | 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, 188 | 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 189 | 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 190 | 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, 191 | ); 192 | runOnlyForDeploymentPostprocessing = 0; 193 | }; 194 | /* End PBXResourcesBuildPhase section */ 195 | 196 | /* Begin PBXShellScriptBuildPhase section */ 197 | 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { 198 | isa = PBXShellScriptBuildPhase; 199 | buildActionMask = 2147483647; 200 | files = ( 201 | ); 202 | inputPaths = ( 203 | ); 204 | name = "Thin Binary"; 205 | outputPaths = ( 206 | ); 207 | runOnlyForDeploymentPostprocessing = 0; 208 | shellPath = /bin/sh; 209 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; 210 | }; 211 | 9740EEB61CF901F6004384FC /* Run Script */ = { 212 | isa = PBXShellScriptBuildPhase; 213 | buildActionMask = 2147483647; 214 | files = ( 215 | ); 216 | inputPaths = ( 217 | ); 218 | name = "Run Script"; 219 | outputPaths = ( 220 | ); 221 | runOnlyForDeploymentPostprocessing = 0; 222 | shellPath = /bin/sh; 223 | shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; 224 | }; 225 | /* End PBXShellScriptBuildPhase section */ 226 | 227 | /* Begin PBXSourcesBuildPhase section */ 228 | 97C146EA1CF9000F007C117D /* Sources */ = { 229 | isa = PBXSourcesBuildPhase; 230 | buildActionMask = 2147483647; 231 | files = ( 232 | 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, 233 | 97C146F31CF9000F007C117D /* main.m in Sources */, 234 | 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, 235 | ); 236 | runOnlyForDeploymentPostprocessing = 0; 237 | }; 238 | /* End PBXSourcesBuildPhase section */ 239 | 240 | /* Begin PBXVariantGroup section */ 241 | 97C146FA1CF9000F007C117D /* Main.storyboard */ = { 242 | isa = PBXVariantGroup; 243 | children = ( 244 | 97C146FB1CF9000F007C117D /* Base */, 245 | ); 246 | name = Main.storyboard; 247 | sourceTree = ""; 248 | }; 249 | 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { 250 | isa = PBXVariantGroup; 251 | children = ( 252 | 97C147001CF9000F007C117D /* Base */, 253 | ); 254 | name = LaunchScreen.storyboard; 255 | sourceTree = ""; 256 | }; 257 | /* End PBXVariantGroup section */ 258 | 259 | /* Begin XCBuildConfiguration section */ 260 | 249021D3217E4FDB00AE95B9 /* Profile */ = { 261 | isa = XCBuildConfiguration; 262 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 263 | buildSettings = { 264 | ALWAYS_SEARCH_USER_PATHS = NO; 265 | CLANG_ANALYZER_NONNULL = YES; 266 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 267 | CLANG_CXX_LIBRARY = "libc++"; 268 | CLANG_ENABLE_MODULES = YES; 269 | CLANG_ENABLE_OBJC_ARC = YES; 270 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 271 | CLANG_WARN_BOOL_CONVERSION = YES; 272 | CLANG_WARN_COMMA = YES; 273 | CLANG_WARN_CONSTANT_CONVERSION = YES; 274 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 275 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 276 | CLANG_WARN_EMPTY_BODY = YES; 277 | CLANG_WARN_ENUM_CONVERSION = YES; 278 | CLANG_WARN_INFINITE_RECURSION = YES; 279 | CLANG_WARN_INT_CONVERSION = YES; 280 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 281 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 282 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 283 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 284 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 285 | CLANG_WARN_STRICT_PROTOTYPES = YES; 286 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 287 | CLANG_WARN_UNREACHABLE_CODE = YES; 288 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 289 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 290 | COPY_PHASE_STRIP = NO; 291 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 292 | ENABLE_NS_ASSERTIONS = NO; 293 | ENABLE_STRICT_OBJC_MSGSEND = YES; 294 | GCC_C_LANGUAGE_STANDARD = gnu99; 295 | GCC_NO_COMMON_BLOCKS = YES; 296 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 297 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 298 | GCC_WARN_UNDECLARED_SELECTOR = YES; 299 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 300 | GCC_WARN_UNUSED_FUNCTION = YES; 301 | GCC_WARN_UNUSED_VARIABLE = YES; 302 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 303 | MTL_ENABLE_DEBUG_INFO = NO; 304 | SDKROOT = iphoneos; 305 | TARGETED_DEVICE_FAMILY = "1,2"; 306 | VALIDATE_PRODUCT = YES; 307 | }; 308 | name = Profile; 309 | }; 310 | 249021D4217E4FDB00AE95B9 /* Profile */ = { 311 | isa = XCBuildConfiguration; 312 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 313 | buildSettings = { 314 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 315 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 316 | DEVELOPMENT_TEAM = S8QB4VV633; 317 | ENABLE_BITCODE = NO; 318 | FRAMEWORK_SEARCH_PATHS = ( 319 | "$(inherited)", 320 | "$(PROJECT_DIR)/Flutter", 321 | ); 322 | INFOPLIST_FILE = Runner/Info.plist; 323 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 324 | LIBRARY_SEARCH_PATHS = ( 325 | "$(inherited)", 326 | "$(PROJECT_DIR)/Flutter", 327 | ); 328 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example; 329 | PRODUCT_NAME = "$(TARGET_NAME)"; 330 | VERSIONING_SYSTEM = "apple-generic"; 331 | }; 332 | name = Profile; 333 | }; 334 | 97C147031CF9000F007C117D /* Debug */ = { 335 | isa = XCBuildConfiguration; 336 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 337 | buildSettings = { 338 | ALWAYS_SEARCH_USER_PATHS = NO; 339 | CLANG_ANALYZER_NONNULL = YES; 340 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 341 | CLANG_CXX_LIBRARY = "libc++"; 342 | CLANG_ENABLE_MODULES = YES; 343 | CLANG_ENABLE_OBJC_ARC = YES; 344 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 345 | CLANG_WARN_BOOL_CONVERSION = YES; 346 | CLANG_WARN_COMMA = YES; 347 | CLANG_WARN_CONSTANT_CONVERSION = YES; 348 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 349 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 350 | CLANG_WARN_EMPTY_BODY = YES; 351 | CLANG_WARN_ENUM_CONVERSION = YES; 352 | CLANG_WARN_INFINITE_RECURSION = YES; 353 | CLANG_WARN_INT_CONVERSION = YES; 354 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 355 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 356 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 357 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 358 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 359 | CLANG_WARN_STRICT_PROTOTYPES = YES; 360 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 361 | CLANG_WARN_UNREACHABLE_CODE = YES; 362 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 363 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 364 | COPY_PHASE_STRIP = NO; 365 | DEBUG_INFORMATION_FORMAT = dwarf; 366 | ENABLE_STRICT_OBJC_MSGSEND = YES; 367 | ENABLE_TESTABILITY = YES; 368 | GCC_C_LANGUAGE_STANDARD = gnu99; 369 | GCC_DYNAMIC_NO_PIC = NO; 370 | GCC_NO_COMMON_BLOCKS = YES; 371 | GCC_OPTIMIZATION_LEVEL = 0; 372 | GCC_PREPROCESSOR_DEFINITIONS = ( 373 | "DEBUG=1", 374 | "$(inherited)", 375 | ); 376 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 377 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 378 | GCC_WARN_UNDECLARED_SELECTOR = YES; 379 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 380 | GCC_WARN_UNUSED_FUNCTION = YES; 381 | GCC_WARN_UNUSED_VARIABLE = YES; 382 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 383 | MTL_ENABLE_DEBUG_INFO = YES; 384 | ONLY_ACTIVE_ARCH = YES; 385 | SDKROOT = iphoneos; 386 | TARGETED_DEVICE_FAMILY = "1,2"; 387 | }; 388 | name = Debug; 389 | }; 390 | 97C147041CF9000F007C117D /* Release */ = { 391 | isa = XCBuildConfiguration; 392 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 393 | buildSettings = { 394 | ALWAYS_SEARCH_USER_PATHS = NO; 395 | CLANG_ANALYZER_NONNULL = YES; 396 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 397 | CLANG_CXX_LIBRARY = "libc++"; 398 | CLANG_ENABLE_MODULES = YES; 399 | CLANG_ENABLE_OBJC_ARC = YES; 400 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 401 | CLANG_WARN_BOOL_CONVERSION = YES; 402 | CLANG_WARN_COMMA = YES; 403 | CLANG_WARN_CONSTANT_CONVERSION = YES; 404 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 405 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 406 | CLANG_WARN_EMPTY_BODY = YES; 407 | CLANG_WARN_ENUM_CONVERSION = YES; 408 | CLANG_WARN_INFINITE_RECURSION = YES; 409 | CLANG_WARN_INT_CONVERSION = YES; 410 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 411 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 412 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 413 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 414 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 415 | CLANG_WARN_STRICT_PROTOTYPES = YES; 416 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 417 | CLANG_WARN_UNREACHABLE_CODE = YES; 418 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 419 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 420 | COPY_PHASE_STRIP = NO; 421 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 422 | ENABLE_NS_ASSERTIONS = NO; 423 | ENABLE_STRICT_OBJC_MSGSEND = YES; 424 | GCC_C_LANGUAGE_STANDARD = gnu99; 425 | GCC_NO_COMMON_BLOCKS = YES; 426 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 427 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 428 | GCC_WARN_UNDECLARED_SELECTOR = YES; 429 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 430 | GCC_WARN_UNUSED_FUNCTION = YES; 431 | GCC_WARN_UNUSED_VARIABLE = YES; 432 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 433 | MTL_ENABLE_DEBUG_INFO = NO; 434 | SDKROOT = iphoneos; 435 | TARGETED_DEVICE_FAMILY = "1,2"; 436 | VALIDATE_PRODUCT = YES; 437 | }; 438 | name = Release; 439 | }; 440 | 97C147061CF9000F007C117D /* Debug */ = { 441 | isa = XCBuildConfiguration; 442 | baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; 443 | buildSettings = { 444 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 445 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 446 | ENABLE_BITCODE = NO; 447 | FRAMEWORK_SEARCH_PATHS = ( 448 | "$(inherited)", 449 | "$(PROJECT_DIR)/Flutter", 450 | ); 451 | INFOPLIST_FILE = Runner/Info.plist; 452 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 453 | LIBRARY_SEARCH_PATHS = ( 454 | "$(inherited)", 455 | "$(PROJECT_DIR)/Flutter", 456 | ); 457 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example; 458 | PRODUCT_NAME = "$(TARGET_NAME)"; 459 | VERSIONING_SYSTEM = "apple-generic"; 460 | }; 461 | name = Debug; 462 | }; 463 | 97C147071CF9000F007C117D /* Release */ = { 464 | isa = XCBuildConfiguration; 465 | baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; 466 | buildSettings = { 467 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 468 | CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; 469 | ENABLE_BITCODE = NO; 470 | FRAMEWORK_SEARCH_PATHS = ( 471 | "$(inherited)", 472 | "$(PROJECT_DIR)/Flutter", 473 | ); 474 | INFOPLIST_FILE = Runner/Info.plist; 475 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 476 | LIBRARY_SEARCH_PATHS = ( 477 | "$(inherited)", 478 | "$(PROJECT_DIR)/Flutter", 479 | ); 480 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example; 481 | PRODUCT_NAME = "$(TARGET_NAME)"; 482 | VERSIONING_SYSTEM = "apple-generic"; 483 | }; 484 | name = Release; 485 | }; 486 | /* End XCBuildConfiguration section */ 487 | 488 | /* Begin XCConfigurationList section */ 489 | 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { 490 | isa = XCConfigurationList; 491 | buildConfigurations = ( 492 | 97C147031CF9000F007C117D /* Debug */, 493 | 97C147041CF9000F007C117D /* Release */, 494 | 249021D3217E4FDB00AE95B9 /* Profile */, 495 | ); 496 | defaultConfigurationIsVisible = 0; 497 | defaultConfigurationName = Release; 498 | }; 499 | 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { 500 | isa = XCConfigurationList; 501 | buildConfigurations = ( 502 | 97C147061CF9000F007C117D /* Debug */, 503 | 97C147071CF9000F007C117D /* Release */, 504 | 249021D4217E4FDB00AE95B9 /* Profile */, 505 | ); 506 | defaultConfigurationIsVisible = 0; 507 | defaultConfigurationName = Release; 508 | }; 509 | /* End XCConfigurationList section */ 510 | }; 511 | rootObject = 97C146E61CF9000F007C117D /* Project object */; 512 | } 513 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | analyzer: 2 | strong-mode: 3 | # Will become the default once non-nullable types land 4 | # https://github.com/dart-lang/sdk/issues/31410#issuecomment-510683629 5 | implicit-casts: false 6 | implicit-dynamic: false 7 | errors: 8 | # treat missing required parameters as a warning (not a hint) 9 | missing_required_param: warning 10 | # treat missing returns as a warning (not a hint) 11 | missing_return: warning 12 | # allow having TODOs in the code 13 | todo: ignore 14 | 15 | # Rules are in the same order (alphabetically) as documented at http://dart-lang.github.io/linter/lints 16 | # and https://github.com/dart-lang/linter/blob/master/example/all.yaml 17 | linter: 18 | rules: 19 | # Prevents accidental return type changes which results in a breaking API change. 20 | # Enforcing return type makes API changes visible in a diff 21 | # pedantic: enabled 22 | # http://dart-lang.github.io/linter/lints/always_declare_return_types.html 23 | - always_declare_return_types 24 | 25 | # Single line `if`s are fine as recommended in Effective Dart "DO format your code using dartfmt" 26 | # pedantic: disabled 27 | # http://dart-lang.github.io/linter/lints/always_put_control_body_on_new_line.html 28 | # - always_put_control_body_on_new_line 29 | 30 | # Flutter widgets always put a Key as first optional parameter which breaks this rule. 31 | # Also violates other orderings like matching the class fields or alphabetically. 32 | # pedantic: disabled 33 | # http://dart-lang.github.io/linter/lints/always_declare_return_types.html 34 | # - always_put_required_named_parameters_first 35 | 36 | # Since dart 2.0 dart is a sound language, specifying types is not required anymore. 37 | # `var foo = 10;` is enough information for the compiler to make foo a int. 38 | # Violates Effective Dart "AVOID type annotating initialized local variables". 39 | # Makes code unnecessarily complex https://github.com/dart-lang/linter/issues/1620 40 | # pedantic: disabled 41 | # http://dart-lang.github.io/linter/lints/always_specify_types.html 42 | # - always_specify_types 43 | 44 | # Protect against unintentionally overriding superclass members 45 | # pedantic: enabled 46 | # http://dart-lang.github.io/linter/lints/annotate_overrides.html 47 | - annotate_overrides 48 | 49 | # All methods should define a return type. dynamic is no exception. 50 | # Violates Effective Dart "PREFER annotating with dynamic instead of letting inference fail" 51 | # pedantic: disabled 52 | # http://dart-lang.github.io/linter/lints/avoid_annotating_with_dynamic.html 53 | # - avoid_annotating_with_dynamic 54 | 55 | # A leftover from dart1, should be deprecated 56 | # pedantic: disabled 57 | # - https://github.com/dart-lang/linter/issues/1401 58 | # http://dart-lang.github.io/linter/lints/avoid_as.html 59 | # - avoid_as 60 | 61 | # Highlights boolean expressions which can be simplified 62 | # http://dart-lang.github.io/linter/lints/avoid_bool_literals_in_conditional_expressions.html 63 | - avoid_bool_literals_in_conditional_expressions 64 | 65 | # There are no strong arguments to enable this rule because it is very strict. Catching anything is useful 66 | # and common even if not always the most correct thing to do. 67 | # pedantic: disabled 68 | # http://dart-lang.github.io/linter/lints/avoid_catches_without_on_clauses.html 69 | # - avoid_catches_without_on_clauses 70 | 71 | # Errors aren't for catching but to prevent prior to runtime 72 | # pedantic: disabled 73 | # http://dart-lang.github.io/linter/lints/avoid_catching_errors.html 74 | - avoid_catching_errors 75 | 76 | # Can usually be replaced with an extension 77 | # pedantic: disabled 78 | # http://dart-lang.github.io/linter/lints/avoid_classes_with_only_static_members.html 79 | # - avoid_classes_with_only_static_members 80 | 81 | # Only useful when targeting JS 82 | # pedantic: disabled 83 | # http://dart-lang.github.io/linter/lints/avoid_double_and_int_checks.html 84 | # - avoid_double_and_int_checks 85 | 86 | # Prevents accidental empty else cases. See samples in documentation 87 | # pedantic: enabled 88 | # http://dart-lang.github.io/linter/lints/avoid_empty_else.html 89 | - avoid_empty_else 90 | 91 | # It is expected that mutable objects which override hash & equals shouldn't be used as keys for hashmaps. 92 | # This one use case doesn't make all hash & equals implementations for mutable classes bad. 93 | # pedantic: disabled 94 | # https://dart-lang.github.io/linter/lints/avoid_equals_and_hash_code_on_mutable_classes.html 95 | # - avoid_equals_and_hash_code_on_mutable_classes 96 | 97 | # Use different quotes instead of escaping 98 | # Dart SDK: >= 2.8.0-dev.11.0 • (Linter v0.1.111) 99 | # https://dart-lang.github.io/linter/lints/avoid_escaping_inner_quotes.html 100 | - avoid_escaping_inner_quotes 101 | 102 | # Prevents unnecessary allocation of a field 103 | # pedantic: disabled 104 | # http://dart-lang.github.io/linter/lints/avoid_field_initializers_in_const_classes.html 105 | - avoid_field_initializers_in_const_classes 106 | 107 | # Prevents allocating a lambda and allows return/break/continue control flow statements inside the loop 108 | # http://dart-lang.github.io/linter/lints/avoid_function_literals_in_foreach_calls.html 109 | - avoid_function_literals_in_foreach_calls 110 | 111 | # Don't break value types by implementing them 112 | # http://dart-lang.github.io/linter/lints/avoid_implementing_value_types.html 113 | - avoid_implementing_value_types 114 | 115 | # Removes redundant `= null;` 116 | # https://dart-lang.github.io/linter/lints/avoid_init_to_null.html 117 | - avoid_init_to_null 118 | 119 | # Only useful when targeting JS 120 | # Warns about too large integers when compiling to JS 121 | # pedantic: disabled 122 | # https://dart-lang.github.io/linter/lints/avoid_js_rounded_ints.html 123 | # - avoid_js_rounded_ints 124 | 125 | # Null checks aren't required in ==() operators 126 | # pedantic: enabled 127 | # https://dart-lang.github.io/linter/lints/avoid_null_checks_in_equality_operators.html 128 | - avoid_null_checks_in_equality_operators 129 | 130 | # Good APIs don't use ambiguous boolean parameters. Instead use named parameters 131 | # https://dart-lang.github.io/linter/lints/avoid_positional_boolean_parameters.html 132 | # - avoid_positional_boolean_parameters 133 | 134 | # Don't call print in production code 135 | # pedantic: disabled 136 | # https://dart-lang.github.io/linter/lints/avoid_print.html 137 | # - avoid_print 138 | 139 | # Always prefer function references over typedefs. 140 | # Jumping twice in code to see the signature of a lambda sucks. This is different from the flutter analysis_options 141 | # https://dart-lang.github.io/linter/lints/avoid_private_typedef_functions.html 142 | - avoid_private_typedef_functions 143 | 144 | # Don't explicitly set defaults 145 | # Dart SDK: >= 2.8.0-dev.1.0 • (Linter v0.1.107) 146 | # https://dart-lang.github.io/linter/lints/avoid_redundant_argument_values.html 147 | # - avoid_redundant_argument_values 148 | 149 | # package or relative? Let's end the discussion and use package everywhere. 150 | # pedantic: enabled 151 | # https://dart-lang.github.io/linter/lints/avoid_relative_lib_imports.html 152 | - avoid_relative_lib_imports 153 | 154 | # Not recommended to break dartdoc but besides that there is no reason to continue with bad naming 155 | # https://dart-lang.github.io/linter/lints/avoid_renaming_method_parameters.html 156 | # - avoid_renaming_method_parameters 157 | 158 | # Setters always return void, therefore defining void is redundant 159 | # pedantic: enabled 160 | # https://dart-lang.github.io/linter/lints/avoid_return_types_on_setters.html 161 | - avoid_return_types_on_setters 162 | 163 | # Especially with Non-Nullable types on the horizon, `int?` is fine. 164 | # There are plenty of valid reasons to return null. 165 | # pedantic: disabled 166 | # https://dart-lang.github.io/linter/lints/avoid_returning_null.html 167 | # - avoid_returning_null 168 | 169 | # Use empty returns, don't show off with you knowledge about dart internals. 170 | # https://dart-lang.github.io/linter/lints/avoid_returning_null_for_void.html 171 | - avoid_returning_null_for_void 172 | 173 | # Hinting you forgot about the cascade operator. But too often you did this on purpose. 174 | # There are plenty of valid reasons to return this. 175 | # pedantic: disabled 176 | # https://dart-lang.github.io/linter/lints/avoid_returning_this.html 177 | # - avoid_returning_this 178 | 179 | # Prevents logical inconsistencies. It's good practice to define getters for all existing setters. 180 | # https://dart-lang.github.io/linter/lints/avoid_setters_without_getters.html 181 | - avoid_setters_without_getters 182 | 183 | # Don't reuse a type parameter when on with the same name already exists in the same scope 184 | # pedantic: enabled 185 | # https://dart-lang.github.io/linter/lints/avoid_shadowing_type_parameters.html 186 | - avoid_shadowing_type_parameters 187 | 188 | # A single cascade operator can be replaced with a normal method call 189 | # https://dart-lang.github.io/linter/lints/avoid_single_cascade_in_expression_statements.html 190 | - avoid_single_cascade_in_expression_statements 191 | 192 | # Might cause frame drops because of synchronous file access on mobile, especially on older phones with slow storage. 193 | # There are no known measurements sync access does *not* drop frames. 194 | # pedantic: disabled 195 | # https://dart-lang.github.io/linter/lints/avoid_slow_async_io.html 196 | # - avoid_slow_async_io 197 | 198 | # Don't use a parameter names which can be confused with a types (i.e. int, bool, num, ...) 199 | # pedantic: enabled 200 | # https://dart-lang.github.io/linter/lints/avoid_types_as_parameter_names.html 201 | - avoid_types_as_parameter_names 202 | 203 | # Adding the type is not required, but sometimes improves readability. Therefore removing it doesn't always help 204 | # https://dart-lang.github.io/linter/lints/avoid_types_on_closure_parameters.html 205 | # - avoid_types_on_closure_parameters 206 | 207 | # Containers without parameters have no effect and can be removed 208 | # https://dart-lang.github.io/linter/lints/avoid_unnecessary_containers.html 209 | - avoid_unnecessary_containers 210 | 211 | # Unused parameters should be removed 212 | # https://dart-lang.github.io/linter/lints/avoid_unused_constructor_parameters.html 213 | - avoid_unused_constructor_parameters 214 | 215 | # TODO double check 216 | # For async functions use `Future` as return value, not `void` 217 | # This allows usage of the await keyword and prevents operations from running in parallel. 218 | # pedantic: disabled 219 | # https://dart-lang.github.io/linter/lints/avoid_void_async.html 220 | - avoid_void_async 221 | 222 | # Flutter mobile only: Web packages aren't available in mobile flutter apps 223 | # https://dart-lang.github.io/linter/lints/avoid_web_libraries_in_flutter.html 224 | - avoid_web_libraries_in_flutter 225 | 226 | # Use the await keyword only for futures. There is nothing to await in synchronous code 227 | # https://dart-lang.github.io/linter/lints/await_only_futures.html 228 | - await_only_futures 229 | 230 | # Follow the style guide and use UpperCamelCase for extensions 231 | # pedantic: enabled 232 | # https://dart-lang.github.io/linter/lints/camel_case_extensions.html 233 | - camel_case_extensions 234 | 235 | # Follow the style guide and use UpperCamelCase for class names and typedefs 236 | # https://dart-lang.github.io/linter/lints/camel_case_types.html 237 | - camel_case_types 238 | 239 | # Prevents leaks and code executing after their lifecycle. 240 | # Discussion https://github.com/passsy/dart-lint/issues/4 241 | # 242 | # pedantic: disabled 243 | # https://dart-lang.github.io/linter/lints/cancel_subscriptions.html 244 | - cancel_subscriptions 245 | 246 | # The cascade syntax is weird and you shouldn't be forced to use it. 247 | # False positives: 248 | # https://github.com/dart-lang/linter/issues/1589 249 | # 250 | # https://dart-lang.github.io/linter/lints/cascade_invocations.html 251 | # - cascade_invocations 252 | 253 | # False positives, not reliable enough 254 | # - https://github.com/dart-lang/linter/issues/1381 255 | # 256 | # pedantic: disabled 257 | # https://dart-lang.github.io/linter/lints/close_sinks.html 258 | # - close_sinks 259 | 260 | # False positives: 261 | # - https://github.com/dart-lang/linter/issues/1142 262 | # 263 | # https://dart-lang.github.io/linter/lints/comment_references.html 264 | # - comment_references 265 | 266 | # Follow standard dart naming style. 267 | # pedantic: disabled 268 | # https://dart-lang.github.io/linter/lints/constant_identifier_names.html 269 | # - constant_identifier_names 270 | 271 | # Prevents hard to debug code 272 | # pedantic: disabled 273 | # https://dart-lang.github.io/linter/lints/control_flow_in_finally.html 274 | - control_flow_in_finally 275 | 276 | # Single line `if`s are fine, but when a new line splits the bool expression and body curly braces 277 | # are recommended. It prevents the danging else problem and easily allows the addition of more lines inside 278 | # the if body 279 | # pedantic: enabled 280 | # https://dart-lang.github.io/linter/lints/curly_braces_in_flow_control_structures.html 281 | # - curly_braces_in_flow_control_structures 282 | 283 | # Still experimental and pretty much work when enforced 284 | # https://dart-lang.github.io/linter/lints/diagnostic_describe_all_properties.html 285 | # - diagnostic_describe_all_properties 286 | 287 | # Follows dart style. Fully supported by IDEs and no manual effort for a consistent style 288 | # pedantic: disabled 289 | # https://dart-lang.github.io/linter/lints/directives_ordering.html 290 | - directives_ordering 291 | 292 | # String.fromEnvironment looks up env variables at compile time. The variable is baked in by the compiler 293 | # and can't be changed by environment variables. 294 | # 295 | # For dart apps: 296 | # Better look up a environment variable at runtime with Platform.environment 297 | # or use code generation to define variables at compile time. 298 | # 299 | # For Flutter apps: 300 | # String.fromEnvironment is the recommended way to include variables defined with `flutter build --dart-define` 301 | # 302 | # pedantic: disabled 303 | # Dart SDK: >= 2.10.0-0.0.dev • (Linter v0.1.117) 304 | # https://dart-lang.github.io/linter/lints/do_not_use_environment.html 305 | # - do_not_use_environment 306 | 307 | # Add a comment why no further error handling is required 308 | # pedantic: enabled 309 | # https://dart-lang.github.io/linter/lints/empty_catches.html 310 | - empty_catches 311 | 312 | # Removed empty constructor bodies 313 | # pedantic: enabled 314 | # https://dart-lang.github.io/linter/lints/empty_constructor_bodies.html 315 | - empty_constructor_bodies 316 | 317 | # Don't allow empty if bodies. Works together with curly_braces_in_flow_control_structures 318 | # pedantic: disabled 319 | # https://dart-lang.github.io/linter/lints/empty_statements.html 320 | - empty_statements 321 | 322 | # Enums aren't powerful enough, now enum like classes get the same linting support 323 | # pedantic: disabled 324 | # Dart SDK: >= 2.9.0-12.0.dev • (Linter v0.1.116) 325 | # https://dart-lang.github.io/linter/lints/exhaustive_cases.html 326 | - exhaustive_cases 327 | 328 | # Follow dart file naming schema 329 | # https://dart-lang.github.io/linter/lints/file_names.html 330 | - file_names 331 | 332 | # Very flutter specific, not applicable for all projects 333 | # pedantic: disabled 334 | # https://dart-lang.github.io/linter/lints/flutter_style_todos.html 335 | # - flutter_style_todos # not all todos require a ticket 336 | 337 | # hashCode and equals need to be consistent. One can't live without another. 338 | # https://dart-lang.github.io/linter/lints/hash_and_equals.html 339 | - hash_and_equals 340 | 341 | # DON'T import implementation files from another package. 342 | # If you need access to some internal code, create an issue 343 | # https://dart-lang.github.io/linter/lints/implementation_imports.html 344 | - implementation_imports 345 | 346 | # Although there are some false positives, this lint generally catches unnecessary checks 347 | # - https://github.com/dart-lang/linter/issues/811 348 | # 349 | # pedantic: disabled 350 | # https://dart-lang.github.io/linter/lints/invariant_booleans.html 351 | - invariant_booleans 352 | 353 | # Type check for Iterable.contains(other) where other is! T 354 | # otherwise contains will always report false. Those errors are usually very hard to catch. 355 | # https://dart-lang.github.io/linter/lints/iterable_contains_unrelated_type.html 356 | - collection_methods_unrelated_type 357 | 358 | # Hint to join return and assignment. 359 | # pedantic: disabled 360 | # https://dart-lang.github.io/linter/lints/join_return_with_assignment.html 361 | # - join_return_with_assignment 362 | 363 | # Add leading \n which which makes multiline strings easier to read 364 | # Dart SDK: >= 2.8.0-dev.16.0 • (Linter v0.1.113) 365 | # https://dart-lang.github.io/linter/lints/leading_newlines_in_multiline_strings.html 366 | - leading_newlines_in_multiline_strings 367 | 368 | # Makes sure a library name is a valid dart identifier. 369 | # This comes in handy for test files combining multiple tests where the file name can be used as identifier 370 | # 371 | # ``` 372 | # import src/some_test.dart as some_test; 373 | # 374 | # main() { 375 | # some_test.main(); 376 | # } 377 | # ``` 378 | # pedantic: enabled 379 | # https://dart-lang.github.io/linter/lints/library_names.html 380 | - library_names 381 | 382 | # Follow dart style 383 | # pedantic: enabled 384 | # https://dart-lang.github.io/linter/lints/library_prefixes.html 385 | - library_prefixes 386 | 387 | # Nobody wants to manually wrap lines when changing a few words. This rule is too hard to be a "general" rule 388 | # https://dart-lang.github.io/linter/lints/lines_longer_than_80_chars.html 389 | # - lines_longer_than_80_chars 390 | 391 | # Good for libraries to prevent unnecessary code paths. 392 | # False positives may occur for applications when boolean properties are generated by external programs 393 | # producing auto-generated source code 394 | # 395 | # Known issue: while(true) loops https://github.com/dart-lang/linter/issues/453 396 | # 397 | # pedantic: disabled 398 | # https://dart-lang.github.io/linter/lints/literal_only_boolean_expressions.html 399 | # - literal_only_boolean_expressions 400 | 401 | # Don't forget the whitespaces at the end 402 | # Dart SDK: >= 2.8.0-dev.10.0 • (Linter v0.1.110) 403 | # https://dart-lang.github.io/linter/lints/missing_whitespace_between_adjacent_strings.html 404 | - missing_whitespace_between_adjacent_strings 405 | 406 | # Concat Strings obviously with `+` inside a list. 407 | # pedantic: disabled 408 | # https://dart-lang.github.io/linter/lints/no_adjacent_strings_in_list.html 409 | - no_adjacent_strings_in_list 410 | 411 | # Second case is basically dead code which will never be reached. 412 | # pedantic: enabled 413 | # https://dart-lang.github.io/linter/lints/no_duplicate_case_values.html 414 | - no_duplicate_case_values 415 | 416 | # Flutter only: `createState` shouldn't pass information into the state 417 | # https://dart-lang.github.io/linter/lints/no_logic_in_create_state.html 418 | - no_logic_in_create_state 419 | 420 | # calling `runtimeType` may be a performance problem 421 | # Dart SDK: >= 2.8.0-dev.10.0 • (Linter v0.1.110) 422 | # https://dart-lang.github.io/linter/lints/no_runtimeType_toString.html 423 | - no_runtimeType_toString 424 | 425 | # Follow dart style naming conventions 426 | # https://dart-lang.github.io/linter/lints/non_constant_identifier_names.html 427 | - non_constant_identifier_names 428 | 429 | # Might become irrelevant when non-nullable types land in dart. Until then use this lint check which checks for 430 | # non null arguments for specific dart sdk methods. 431 | # pedantic: enabled 432 | # https://dart-lang.github.io/linter/lints/null_closures.html 433 | - null_closures 434 | 435 | # Types for local variables may improve readability. 436 | # pedantic: enabled 437 | # https://dart-lang.github.io/linter/lints/omit_local_variable_types.html 438 | # - omit_local_variable_types 439 | 440 | # Defining interfaces (abstract classes), with only one method, makes sense architecture wise 441 | # Discussion: https://github.com/passsy/dart-lint/issues/2 442 | # 443 | # pedantic: disabled 444 | # https://dart-lang.github.io/linter/lints/one_member_abstracts.html 445 | # - one_member_abstracts 446 | 447 | # Since Errors aren't intended to be caught (see avoid_catching_errors), throwing anything 448 | # doesn't cause trouble. 449 | # https://dart-lang.github.io/linter/lints/only_throw_errors.html 450 | # - only_throw_errors 451 | 452 | # Highlights unintentionally overridden fields. 453 | # https://dart-lang.github.io/linter/lints/overridden_fields.html 454 | - overridden_fields 455 | 456 | # Only relevant for packages, not applications or general dart code 457 | # https://dart-lang.github.io/linter/lints/package_api_docs.html 458 | # - package_api_docs 459 | 460 | # Follow dart style package naming convention 461 | # https://dart-lang.github.io/linter/lints/package_names.html 462 | - package_names 463 | 464 | # Seems very rare, especially for applications. 465 | # https://dart-lang.github.io/linter/lints/package_prefixed_library_names.html 466 | - package_prefixed_library_names 467 | 468 | # Most likely a mistake, if not: bad practice 469 | # pedantic: disabled 470 | # https://dart-lang.github.io/linter/lints/parameter_assignments.html 471 | # - parameter_assignments 472 | 473 | # Is contradictory to `no_adjacent_strings_in_list` 474 | # pedantic: enabled 475 | # https://dart-lang.github.io/linter/lints/prefer_adjacent_string_concatenation.html 476 | # - prefer_adjacent_string_concatenation 477 | 478 | # Makes it easier to migrate to const constructors and to have final fields 479 | # pedantic: disabled 480 | # https://dart-lang.github.io/linter/lints/prefer_asserts_in_initializer_lists.html 481 | - prefer_asserts_in_initializer_lists 482 | 483 | # Assertions blocks don't require a message because they throw simple to understand errors 484 | # pedantic: disabled 485 | # https://dart-lang.github.io/linter/lints/prefer_asserts_with_message.html 486 | # - prefer_asserts_with_message 487 | 488 | # Collection literals are shorter. They exists, use them. 489 | # pedantic: enabled 490 | # https://dart-lang.github.io/linter/lints/prefer_collection_literals.html 491 | - prefer_collection_literals 492 | 493 | # Use the ??= operator when possible 494 | # pedantic: enabled 495 | # https://dart-lang.github.io/linter/lints/prefer_conditional_assignment.html 496 | - prefer_conditional_assignment 497 | 498 | # Always use const when possible, make runtime faster 499 | # pedantic: disabled 500 | # https://dart-lang.github.io/linter/lints/prefer_const_constructors.html 501 | - prefer_const_constructors 502 | 503 | # Add a const constructor when possible 504 | # pedantic: disabled 505 | # https://dart-lang.github.io/linter/lints/prefer_const_constructors_in_immutables.html 506 | - prefer_const_constructors_in_immutables 507 | 508 | # final is good, const is better 509 | # https://dart-lang.github.io/linter/lints/prefer_const_declarations.html 510 | - prefer_const_declarations 511 | 512 | # Always use const when possible, make runtime faster 513 | # pedantic: disabled 514 | # https://dart-lang.github.io/linter/lints/prefer_const_literals_to_create_immutables.html 515 | - prefer_const_literals_to_create_immutables 516 | 517 | # Dart has named constructors. Static methods in other languages (java) are a workaround which don't have 518 | # named constructors. 519 | # pedantic: disabled 520 | # https://dart-lang.github.io/linter/lints/prefer_constructors_over_static_methods.html 521 | - prefer_constructors_over_static_methods 522 | 523 | # Contains may be faster and is easier to read 524 | # pedantic: enabled 525 | # https://dart-lang.github.io/linter/lints/prefer_contains.html 526 | - prefer_contains 527 | 528 | # Use whatever makes you happy. lint doesn't define a style 529 | # pedantic: disabled 530 | # https://dart-lang.github.io/linter/lints/prefer_double_quotes.html 531 | # - prefer_double_quotes 532 | 533 | # Prevent confusion with call-side when using named parameters 534 | # pedantic: enabled 535 | # https://dart-lang.github.io/linter/lints/prefer_equal_for_default_values.html 536 | - prefer_equal_for_default_values 537 | 538 | # Single line methods + implementation makes it hard to write comments for that line. 539 | # Dense code isn't necessarily better code. 540 | # pedantic: disabled 541 | # https://dart-lang.github.io/linter/lints/prefer_expression_function_bodies.html 542 | # - prefer_expression_function_bodies 543 | 544 | # Avoid accidental reassignments and allows the compiler to do optimizations. 545 | # pedantic: enabled 546 | # https://dart-lang.github.io/linter/lints/prefer_final_fields.html 547 | - prefer_final_fields 548 | 549 | # Helps avoid accidental reassignments and allows the compiler to do optimizations. 550 | # pedantic: disabled 551 | # https://dart-lang.github.io/linter/lints/prefer_final_in_for_each.html 552 | # - prefer_final_in_for_each 553 | 554 | # Helps avoid accidental reassignments and allows the compiler to do optimizations. 555 | # pedantic: disabled 556 | # https://dart-lang.github.io/linter/lints/prefer_final_locals.html 557 | # - prefer_final_locals 558 | 559 | # Saves lot of code 560 | # pedantic: enabled 561 | # https://dart-lang.github.io/linter/lints/prefer_for_elements_to_map_fromIterable.html 562 | - prefer_for_elements_to_map_fromIterable 563 | 564 | # Dense code isn't necessarily better code 565 | # pedantic: disabled 566 | # https://dart-lang.github.io/linter/lints/prefer_foreach.html 567 | # - prefer_foreach 568 | 569 | # As Dart allows local function declarations, it is a good practice to use them in the place of function literals. 570 | # https://dart-lang.github.io/linter/lints/prefer_function_declarations_over_variables.html 571 | - prefer_function_declarations_over_variables 572 | 573 | # For consistency 574 | # pedantic: enabled 575 | # https://dart-lang.github.io/linter/lints/prefer_generic_function_type_aliases.html 576 | - prefer_generic_function_type_aliases 577 | 578 | # Allows potential usage of const 579 | # https://dart-lang.github.io/linter/lints/prefer_if_elements_to_conditional_expressions.html 580 | - prefer_if_elements_to_conditional_expressions 581 | 582 | # Dart has a special operator for this, use it 583 | # pedantic: enabled 584 | # https://dart-lang.github.io/linter/lints/prefer_if_null_operators.html 585 | - prefer_if_null_operators 586 | 587 | # Terser code 588 | # https://dart-lang.github.io/linter/lints/prefer_initializing_formals.html 589 | - prefer_initializing_formals 590 | 591 | # Easier move towards const, and way easier to read 592 | # https://dart-lang.github.io/linter/lints/prefer_inlined_adds.html 593 | - prefer_inlined_adds 594 | 595 | # There is no argument which makes int literals better than double literals for doubles. 596 | # pedantic: disabled 597 | # https://dart-lang.github.io/linter/lints/prefer_int_literals.html 598 | # - prefer_int_literals 599 | 600 | # Interpolate, use less "", '' and + 601 | # https://dart-lang.github.io/linter/lints/prefer_interpolation_to_compose_strings.html 602 | - prefer_interpolation_to_compose_strings 603 | 604 | # Iterables do not necessary know their length 605 | # pedantic: enabled 606 | # https://dart-lang.github.io/linter/lints/prefer_is_empty.html 607 | - prefer_is_empty 608 | 609 | # Easier to read 610 | # pedantic: enabled 611 | # https://dart-lang.github.io/linter/lints/prefer_is_not_empty.html 612 | - prefer_is_not_empty 613 | 614 | # Use the `foo is! Foo` instead of `!(foo is Foo)` 615 | # https://dart-lang.github.io/linter/lints/prefer_is_not_operator.html 616 | - prefer_is_not_operator 617 | 618 | # Easier to read 619 | # pedantic: enabled 620 | # https://dart-lang.github.io/linter/lints/prefer_iterable_whereType.html 621 | - prefer_iterable_whereType 622 | 623 | # Users of a 3rd party mixins can't change 3rd party code to use the mixin syntax. 624 | # This makes the rule useless 625 | # https://dart-lang.github.io/linter/lints/prefer_mixin.html 626 | # - prefer_mixin 627 | 628 | # Makes expressions with null checks easier to read. 629 | # https://github.com/flutter/flutter/pull/32711#issuecomment-492930932 630 | - prefer_null_aware_operators 631 | 632 | # Conflicting with `avoid_relative_lib_imports` which is enforced 633 | # https://dart-lang.github.io/linter/lints/prefer_relative_imports.html 634 | # - prefer_relative_imports 635 | 636 | # Use whatever makes you happy. noexcuse doesn't define a style 637 | # pedantic: enabled 638 | # https://dart-lang.github.io/linter/lints/prefer_single_quotes.html 639 | # - prefer_single_quotes 640 | 641 | # Allows potential usage of const 642 | # pedantic: enabled 643 | # https://dart-lang.github.io/linter/lints/prefer_spread_collections.html 644 | - prefer_spread_collections 645 | 646 | # Define types 647 | # pedantic: disabled 648 | # https://dart-lang.github.io/linter/lints/prefer_typing_uninitialized_variables.html 649 | - prefer_typing_uninitialized_variables 650 | 651 | # Null is not a type, use void 652 | # https://dart-lang.github.io/linter/lints/prefer_void_to_null.html 653 | - prefer_void_to_null 654 | 655 | # Document the replacement API 656 | # https://dart-lang.github.io/linter/lints/provide_deprecation_message.html 657 | - provide_deprecation_message 658 | 659 | # Definitely not a rule for standard dart code. Maybe relevant for packages 660 | # https://dart-lang.github.io/linter/lints/public_member_api_docs.html 661 | # - public_member_api_docs 662 | 663 | # Hints accidental recursions 664 | # pedantic: enabled 665 | # https://dart-lang.github.io/linter/lints/recursive_getters.html 666 | - recursive_getters 667 | 668 | # Flutter only, prefer SizedBox over Container which offers a const constructors 669 | # Dart SDK: >= 2.9.0-4.0.dev • (Linter v0.1.115) 670 | # https://dart-lang.github.io/linter/lints/sized_box_for_whitespace.html 671 | - sized_box_for_whitespace 672 | 673 | # Follow dart style use triple slashes 674 | # pedantic: enabled 675 | # https://dart-lang.github.io/linter/lints/slash_for_doc_comments.html 676 | - slash_for_doc_comments 677 | 678 | # Flutter only, always put child last 679 | # https://dart-lang.github.io/linter/lints/sort_child_properties_last.html 680 | - sort_child_properties_last 681 | 682 | # Working, results in consistent code. But too opinionated 683 | # Discussion: https://github.com/passsy/dart-lint/issues/1 684 | # 685 | # pedantic: disabled 686 | # https://dart-lang.github.io/linter/lints/sort_constructors_first.html 687 | # - sort_constructors_first 688 | 689 | # Any sorting is better than no sorting 690 | # https://dart-lang.github.io/linter/lints/sort_pub_dependencies.html 691 | - sort_pub_dependencies 692 | 693 | # Default constructor comes first. 694 | # pedantic: disabled 695 | # https://dart-lang.github.io/linter/lints/sort_unnamed_constructors_first.html 696 | - sort_unnamed_constructors_first 697 | 698 | # First test, then cast 699 | # pedantic: disabled 700 | # https://dart-lang.github.io/linter/lints/test_types_in_equals.html 701 | - test_types_in_equals 702 | 703 | # Hard to debug and bad style 704 | # pedantic: disabled 705 | # https://dart-lang.github.io/linter/lints/throw_in_finally.html 706 | - throw_in_finally 707 | 708 | # Type annotations make the compiler intelligent, use them 709 | # https://dart-lang.github.io/linter/lints/type_annotate_public_apis.html 710 | - type_annotate_public_apis 711 | 712 | # Don't add types for already typed constructor parameters. 713 | # pedantic: enabled 714 | # https://dart-lang.github.io/linter/lints/type_init_formals.html 715 | - type_init_formals 716 | 717 | # Too many false positives. 718 | # Using the pedantic package for the unawaited function doesn't make code better readable 719 | # 720 | # pedantic: enabled 721 | # https://dart-lang.github.io/linter/lints/unawaited_futures.html 722 | # - unawaited_futures 723 | 724 | # Remove async/await clutter when not required 725 | # https://dart-lang.github.io/linter/lints/unnecessary_await_in_return.html 726 | - unnecessary_await_in_return 727 | 728 | # Remove unnecessary braces 729 | # https://dart-lang.github.io/linter/lints/unnecessary_brace_in_string_interps.html 730 | - unnecessary_brace_in_string_interps 731 | 732 | # Yes, const everywhere. But not in an already const scope 733 | # pedantic: enabled 734 | # https://dart-lang.github.io/linter/lints/unnecessary_const.html 735 | - unnecessary_const 736 | 737 | # Disabled because `final` prevents accidental reassignment 738 | # https://dart-lang.github.io/linter/lints/unnecessary_final.html 739 | # - unnecessary_final 740 | 741 | # Getter/setters can be added later on in a non API breaking manner 742 | # https://dart-lang.github.io/linter/lints/unnecessary_getters_setters.html 743 | - unnecessary_getters_setters 744 | 745 | # Flutter setState is a good example where a lambda should always be used. 746 | # https://github.com/dart-lang/linter/issues/498 747 | # 748 | # Some generic code sometimes requires lambdas, otherwise the generic type isn't forwarded correctly. 749 | # 750 | # https://dart-lang.github.io/linter/lints/unnecessary_lambdas.html 751 | # - unnecessary_lambdas 752 | 753 | # Remove the optional `new` keyword 754 | # pedantic: enabled 755 | # https://dart-lang.github.io/linter/lints/unnecessary_new.html 756 | - unnecessary_new 757 | 758 | # Don't assign `null` when value is already `null`. 759 | # pedantic: disabled 760 | # https://dart-lang.github.io/linter/lints/unnecessary_null_aware_assignments.html 761 | - unnecessary_null_aware_assignments 762 | 763 | # Don't assign `null` when value is already `null`. 764 | # pedantic: enabled 765 | # https://dart-lang.github.io/linter/lints/unnecessary_null_in_if_null_operators.html 766 | - unnecessary_null_in_if_null_operators 767 | 768 | # If a variable doesn't change and is initialized, no need to define it as nullable (NNDB) 769 | # Dart SDK: >= 2.10.0-10.0.dev • (Linter v0.1.118) 770 | # https://dart-lang.github.io/linter/lints/unnecessary_nullable_for_final_variable_declarations.html 771 | - unnecessary_nullable_for_final_variable_declarations 772 | 773 | # Remove overrides which simply call super 774 | # https://dart-lang.github.io/linter/lints/unnecessary_overrides.html 775 | - unnecessary_overrides 776 | 777 | # Remove clutter where possible 778 | # https://dart-lang.github.io/linter/lints/unnecessary_parenthesis.html 779 | # - unnecessary_parenthesis 780 | 781 | # Use raw string only when needed 782 | # Dart SDK: >= 2.8.0-dev.11.0 • (Linter v0.1.111) 783 | # https://dart-lang.github.io/linter/lints/unnecessary_raw_strings.html 784 | - unnecessary_raw_strings 785 | 786 | # Avoid magic overloads of + operators 787 | # https://dart-lang.github.io/linter/lints/unnecessary_statements.html 788 | - unnecessary_statements 789 | 790 | # Remove unnecessary escape characters 791 | # Dart SDK: >= 2.8.0-dev.11.0 • (Linter v0.1.111) 792 | # https://dart-lang.github.io/linter/lints/unnecessary_string_escapes.html 793 | - unnecessary_string_escapes 794 | 795 | # Especially with NNBD a no-brainer 796 | # Dart SDK: >= 2.8.0-dev.10.0 • (Linter v0.1.110) 797 | # https://dart-lang.github.io/linter/lints/unnecessary_string_interpolations.html 798 | - unnecessary_string_interpolations 799 | 800 | # The variable is clear, remove clutter 801 | # pedantic: enabled 802 | # https://dart-lang.github.io/linter/lints/unnecessary_this.html 803 | - unnecessary_this 804 | 805 | # Highlights potential bugs where unrelated types are compared with another. (always *not* equal). 806 | # pedantic: enabled 807 | # https://dart-lang.github.io/linter/lints/unrelated_type_equality_checks.html 808 | - unrelated_type_equality_checks 809 | 810 | # Always use hex syntax Color(0x00000001), never Color(1) 811 | # https://dart-lang.github.io/linter/lints/use_full_hex_values_for_flutter_colors.html 812 | - use_full_hex_values_for_flutter_colors 813 | 814 | # Always use generic function type syntax, don't mix styles 815 | # pedantic: enabled 816 | # https://dart-lang.github.io/linter/lints/use_function_type_syntax_for_parameters.html 817 | - use_function_type_syntax_for_parameters 818 | 819 | # Adding a key without using it isn't helpful in applications, only for the Flutter SDK 820 | # Dart SDK: >= 2.8.0-dev.1.0 • (Linter v0.1.108) 821 | # https://dart-lang.github.io/linter/lints/use_key_in_widget_constructors.html 822 | # - use_key_in_widget_constructors 823 | 824 | # Still unsure if `late` is always better than `!` (NNBD) 825 | # Dart SDK: >= 2.10.0-10.0.dev • (Linter v0.1.118) 826 | # https://dart-lang.github.io/linter/lints/use_late_for_private_fields_and_variables.html 827 | - use_late_for_private_fields_and_variables 828 | 829 | # Use rethrow to preserve the original stacktrace. 830 | # https://dart.dev/guides/language/effective-dart/usage#do-use-rethrow-to-rethrow-a-caught-exception 831 | # pedantic: enabled 832 | # https://dart-lang.github.io/linter/lints/use_rethrow_when_possible.html 833 | - use_rethrow_when_possible 834 | 835 | # Use the setter syntax 836 | # pedantic: disabled 837 | # https://dart-lang.github.io/linter/lints/use_setters_to_change_properties.html 838 | - use_setters_to_change_properties 839 | 840 | # In most cases, using a string buffer is preferred for composing strings due to its improved performance. 841 | # https://dart-lang.github.io/linter/lints/use_string_buffers.html 842 | - use_string_buffers 843 | 844 | # Naming is hard, strict rules don't help 845 | # pedantic: disabled 846 | # https://dart-lang.github.io/linter/lints/use_to_and_as_if_applicable.html 847 | # - use_to_and_as_if_applicable 848 | 849 | # Catches invalid regular expressions. 850 | # pedantic: enabled 851 | # https://dart-lang.github.io/linter/lints/valid_regexps.html 852 | - valid_regexps 853 | 854 | # Don't assign anything to void 855 | # https://dart-lang.github.io/linter/lints/void_checks.html 856 | - void_checks 857 | --------------------------------------------------------------------------------